From 795738900d189b958586025773516c7ab4b822f7 Mon Sep 17 00:00:00 2001 From: xdatomic-the-codeur Date: Thu, 26 Sep 2024 15:27:35 +0200 Subject: [PATCH] SQ3-S3 --- Contacts/Contact.cs | 9 ++- Contacts/FrmContacts.Designer.cs | 94 ++++++++++++++++++++++++++++++-- Contacts/FrmContacts.cs | 90 +++++++++++++++++++++++++++++- 3 files changed, 185 insertions(+), 8 deletions(-) diff --git a/Contacts/Contact.cs b/Contacts/Contact.cs index 6531751..dc5f333 100644 --- a/Contacts/Contact.cs +++ b/Contacts/Contact.cs @@ -74,7 +74,14 @@ namespace Contacts /// prenom public string getPrenom() { - return this.prenom; + if(this.prenom != null) + { + return this.prenom; + } + else + { + return null; + } } /// diff --git a/Contacts/FrmContacts.Designer.cs b/Contacts/FrmContacts.Designer.cs index 717a427..8199b79 100644 --- a/Contacts/FrmContacts.Designer.cs +++ b/Contacts/FrmContacts.Designer.cs @@ -46,9 +46,17 @@ this.btnSuppr = new System.Windows.Forms.Button(); this.btnModif = new System.Windows.Forms.Button(); this.imgPhoto = new System.Windows.Forms.PictureBox(); + this.grpRecherche = new System.Windows.Forms.GroupBox(); + this.searchTel = new System.Windows.Forms.TextBox(); + this.searchPrenom = new System.Windows.Forms.TextBox(); + this.searchNom = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.grbAjout.SuspendLayout(); this.grbContacts.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.imgPhoto)).BeginInit(); + this.grpRecherche.SuspendLayout(); this.SuspendLayout(); // // lblChoixPhoto @@ -71,7 +79,7 @@ this.lstContact.HorizontalScrollbar = true; this.lstContact.Location = new System.Drawing.Point(6, 19); this.lstContact.Name = "lstContact"; - this.lstContact.Size = new System.Drawing.Size(318, 329); + this.lstContact.Size = new System.Drawing.Size(318, 459); this.lstContact.TabIndex = 9; this.lstContact.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lstContact_DrawItem); this.lstContact.SelectedIndexChanged += new System.EventHandler(this.LstContact_SelectedIndexChanged); @@ -206,7 +214,7 @@ this.grbContacts.Controls.Add(this.btnModif); this.grbContacts.Location = new System.Drawing.Point(188, 12); this.grbContacts.Name = "grbContacts"; - this.grbContacts.Size = new System.Drawing.Size(333, 430); + this.grbContacts.Size = new System.Drawing.Size(333, 545); this.grbContacts.TabIndex = 15; this.grbContacts.TabStop = false; this.grbContacts.Text = "les contacts"; @@ -214,7 +222,7 @@ // btnSuppr // this.btnSuppr.Image = global::Contacts.Properties.Resources.supprimer; - this.btnSuppr.Location = new System.Drawing.Point(279, 354); + this.btnSuppr.Location = new System.Drawing.Point(279, 484); this.btnSuppr.Name = "btnSuppr"; this.btnSuppr.Size = new System.Drawing.Size(45, 45); this.btnSuppr.TabIndex = 10; @@ -224,7 +232,7 @@ // btnModif // this.btnModif.Image = global::Contacts.Properties.Resources.modifier; - this.btnModif.Location = new System.Drawing.Point(228, 354); + this.btnModif.Location = new System.Drawing.Point(228, 484); this.btnModif.Name = "btnModif"; this.btnModif.Size = new System.Drawing.Size(45, 45); this.btnModif.TabIndex = 11; @@ -243,11 +251,78 @@ this.imgPhoto.TabStop = false; this.imgPhoto.Click += new System.EventHandler(this.ImgPhoto_Click); // + // grpRecherche + // + this.grpRecherche.Controls.Add(this.searchTel); + this.grpRecherche.Controls.Add(this.searchPrenom); + this.grpRecherche.Controls.Add(this.searchNom); + this.grpRecherche.Controls.Add(this.label5); + this.grpRecherche.Controls.Add(this.label4); + this.grpRecherche.Controls.Add(this.label2); + this.grpRecherche.Location = new System.Drawing.Point(12, 449); + this.grpRecherche.Name = "grpRecherche"; + this.grpRecherche.Size = new System.Drawing.Size(170, 108); + this.grpRecherche.TabIndex = 16; + this.grpRecherche.TabStop = false; + this.grpRecherche.Text = "Recherche"; + // + // searchTel + // + this.searchTel.Location = new System.Drawing.Point(60, 72); + this.searchTel.Name = "searchTel"; + this.searchTel.Size = new System.Drawing.Size(100, 20); + this.searchTel.TabIndex = 17; + this.searchTel.TextChanged += new System.EventHandler(this.searchTel_TextChanged); + // + // searchPrenom + // + this.searchPrenom.Location = new System.Drawing.Point(60, 43); + this.searchPrenom.Name = "searchPrenom"; + this.searchPrenom.Size = new System.Drawing.Size(100, 20); + this.searchPrenom.TabIndex = 6; + this.searchPrenom.TextChanged += new System.EventHandler(this.searchPrenom_TextChanged); + // + // searchNom + // + this.searchNom.Location = new System.Drawing.Point(60, 17); + this.searchNom.Name = "searchNom"; + this.searchNom.Size = new System.Drawing.Size(100, 20); + this.searchNom.TabIndex = 5; + this.searchNom.TextChanged += new System.EventHandler(this.searchNom_TextChanged); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(7, 75); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(22, 13); + this.label5.TabIndex = 4; + this.label5.Text = "Tel"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(7, 46); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(43, 13); + this.label4.TabIndex = 2; + this.label4.Text = "Prénom"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 20); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 13); + this.label2.TabIndex = 0; + this.label2.Text = "Nom"; + // // frmContacts // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(531, 454); + this.ClientSize = new System.Drawing.Size(531, 569); + this.Controls.Add(this.grpRecherche); this.Controls.Add(this.grbContacts); this.Controls.Add(this.btnNouveauContact); this.Controls.Add(this.lblChoixPhoto); @@ -260,6 +335,8 @@ this.grbAjout.PerformLayout(); this.grbContacts.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.imgPhoto)).EndInit(); + this.grpRecherche.ResumeLayout(false); + this.grpRecherche.PerformLayout(); this.ResumeLayout(false); } @@ -284,6 +361,13 @@ private System.Windows.Forms.GroupBox grbContacts; private System.Windows.Forms.RadioButton radioEntreprise; private System.Windows.Forms.RadioButton radioPerso; + private System.Windows.Forms.GroupBox grpRecherche; + private System.Windows.Forms.TextBox searchTel; + private System.Windows.Forms.TextBox searchPrenom; + private System.Windows.Forms.TextBox searchNom; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label2; } } diff --git a/Contacts/FrmContacts.cs b/Contacts/FrmContacts.cs index ce305c3..3bc2591 100644 --- a/Contacts/FrmContacts.cs +++ b/Contacts/FrmContacts.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using System.Diagnostics; namespace Contacts { @@ -33,6 +34,7 @@ namespace Contacts // Gérer les accès aux objets graphiques grbAjout.Enabled = true; grbContacts.Enabled = false; + grpRecherche.Enabled = false; imgPhoto.Enabled = true; btnNouveauContact.Enabled = false; lblChoixPhoto.Visible = true; @@ -41,7 +43,7 @@ namespace Contacts // affiche la photo standard AffichePhotoStandard(); // se positionner sur le nom - txtNom.Focus(); + txtNom.Focus(); } /// @@ -52,6 +54,7 @@ namespace Contacts // Gérer les accès aux objets graphiques grbAjout.Enabled = false; grbContacts.Enabled = true; + grpRecherche.Enabled = true; imgPhoto.Enabled = false; btnNouveauContact.Enabled = true; lblChoixPhoto.Visible = false; @@ -370,7 +373,8 @@ namespace Contacts if (leContacts.IsPersonne()) { couleur = radioPerso.ForeColor; - }else + } + else { couleur = radioEntreprise.ForeColor; } @@ -379,5 +383,87 @@ namespace Contacts e.Graphics.DrawString(lstContact.Items[e.Index].ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault); } + + private void searchNom_TextChanged(object sender, EventArgs e) + { + string query = searchNom.Text.ToLower(); + + searchPrenom.Text = ""; + searchTel.Text = ""; + + if (searchNom.Text != "") + { + for (int i = 0; i < lstContact.Items.Count; i++) + { + Contact contact = (Contact)lstContact.Items[i]; + string toTest = contact.getNom().ToLower(); + //Debug.WriteLine(toTest); + if (toTest.Contains(query)) + { + lstContact.SelectedIndex = i; + } + } + } + } + + private void searchPrenom_TextChanged(object sender, EventArgs e) + { + string query = searchPrenom.Text.ToLower(); + + searchNom.Text = ""; + searchTel.Text = ""; + + if (searchPrenom.Text != "") + { + for (int i = 0; i < lstContact.Items.Count; i++) + { + Contact contact = (Contact)lstContact.Items[i]; + string toTest; + if (contact.getPrenom() != null) + { + toTest = contact.getPrenom().ToLower(); + } + else + { + toTest = ""; + } + //Debug.WriteLine(toTest); + if (toTest.Contains(query)) + { + lstContact.SelectedIndex = i; + } + } + } + } + + private void searchTel_TextChanged(object sender, EventArgs e) + { + string query = searchTel.Text; + + searchNom.Text = ""; + searchPrenom.Text = ""; + + if (searchTel.Text != "") + { + for (int i = 0; i < lstContact.Items.Count; i++) + { + Contact contact = (Contact)lstContact.Items[i]; + string toTest; + if (contact.getTel() != null) + { + toTest = contact.getTel().ToLower(); + } + else + { + toTest = ""; + } + //Debug.WriteLine(toTest); + if (toTest.Contains(query)) + { + lstContact.SelectedIndex = i; + } + } + } + } } }