diff --git a/Contacts.sln b/Contacts.sln new file mode 100644 index 0000000..79ac1dc --- /dev/null +++ b/Contacts.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30104.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contacts", "Contacts\Contacts.csproj", "{7A989FF0-CB51-4312-B11C-5F8476E5A113}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A989FF0-CB51-4312-B11C-5F8476E5A113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A989FF0-CB51-4312-B11C-5F8476E5A113}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A989FF0-CB51-4312-B11C-5F8476E5A113}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A989FF0-CB51-4312-B11C-5F8476E5A113}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6BDD0F5B-A066-402D-BABE-A977D94B24AD} + EndGlobalSection +EndGlobal diff --git a/Contacts/App.config b/Contacts/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Contacts/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Contacts/Contact.cs b/Contacts/Contact.cs new file mode 100644 index 0000000..6531751 --- /dev/null +++ b/Contacts/Contact.cs @@ -0,0 +1,117 @@ +using System; +using System.Drawing; + +namespace Contacts +{ + /// + /// Classe Contact + /// mémorise les informations du contact + /// + [SerializableAttribute] + public class Contact : IComparable +// public class Contact + { + private string nom; + private string prenom; + private string tel; + private Image photo; + + /// + /// Constructeur + /// + /// nom + /// prénom + /// téléphone + /// photo + public Contact(string nom, string prenom, string tel, Image photo) + { + this.nom = nom; + this.prenom = prenom; + this.tel = tel; + this.photo = photo; + } + /// + /// Constructeur pour une entreprise + /// + /// Nom de l'entreprise + /// Numéro de téléphone de l'entreprise + /// Photo de contact de l'entreprise + public Contact(string nom, string tel, Image photo) + { + this.nom = nom; + this.tel = tel; + this.photo = photo; + } + + /// + /// Indique si une valeur est une entreprise ou non + /// + /// true si c'est une personne, false dans le cas contraire. + public bool IsPersonne() + { + if(this.getPrenom() == null) + { + return false; + } + else + { + return true; + } + } + + /// + /// getter sur nom + /// + /// nom + public string getNom() + { + return this.nom; + } + + /// + /// getter sur prenom + /// + /// prenom + public string getPrenom() + { + return this.prenom; + } + + /// + /// getter sur tel + /// + /// tel + public string getTel() + { + return this.tel; + } + + /// + /// getter sur photo + /// + /// photo + public Image getPhoto() + { + return this.photo; + } + + /// + /// informations sur le contact + /// + /// nom + prenom + (tel) + public override string ToString() + { + return this.nom + " " + this.prenom + " (" + this.tel + ")"; + } + + /// + /// Comparaison des noms pour le tri + /// + /// contact à comparer + /// comparaison sur le nom + public int CompareTo(object obj) + { + return nom.CompareTo(((Contact)obj).getNom()); + } + } +} diff --git a/Contacts/Contacts.csproj b/Contacts/Contacts.csproj new file mode 100644 index 0000000..db5fa70 --- /dev/null +++ b/Contacts/Contacts.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {7A989FF0-CB51-4312-B11C-5F8476E5A113} + WinExe + Contacts + Contacts + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\Contacts.xml + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + FrmContacts.cs + + + + + True + True + Resources.resx + + + + FrmContacts.cs + + + ResXFileCodeGenerator + Designer + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Contacts/FrmContacts.Designer.cs b/Contacts/FrmContacts.Designer.cs new file mode 100644 index 0000000..717a427 --- /dev/null +++ b/Contacts/FrmContacts.Designer.cs @@ -0,0 +1,289 @@ +namespace Contacts +{ + partial class frmContacts + { + /// + /// Variable nécessaire au concepteur. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Nettoyage des ressources utilisées. + /// + /// true si les ressources managées doivent être supprimées ; sinon, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Code généré par le Concepteur Windows Form + + /// + /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas + /// le contenu de cette méthode avec l'éditeur de code. + /// + private void InitializeComponent() + { + this.lblChoixPhoto = new System.Windows.Forms.Label(); + this.lstContact = new System.Windows.Forms.ListBox(); + this.grbAjout = new System.Windows.Forms.GroupBox(); + this.radioEntreprise = new System.Windows.Forms.RadioButton(); + this.radioPerso = new System.Windows.Forms.RadioButton(); + this.btnAnnuler = new System.Windows.Forms.Button(); + this.btnAjouter = new System.Windows.Forms.Button(); + this.txtTel = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtPrenom = new System.Windows.Forms.TextBox(); + this.lblPrenom = new System.Windows.Forms.Label(); + this.txtNom = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnNouveauContact = new System.Windows.Forms.Button(); + this.grbContacts = new System.Windows.Forms.GroupBox(); + this.btnSuppr = new System.Windows.Forms.Button(); + this.btnModif = new System.Windows.Forms.Button(); + this.imgPhoto = new System.Windows.Forms.PictureBox(); + this.grbAjout.SuspendLayout(); + this.grbContacts.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.imgPhoto)).BeginInit(); + this.SuspendLayout(); + // + // lblChoixPhoto + // + this.lblChoixPhoto.BackColor = System.Drawing.Color.Transparent; + this.lblChoixPhoto.Enabled = false; + this.lblChoixPhoto.Location = new System.Drawing.Point(31, 186); + this.lblChoixPhoto.Name = "lblChoixPhoto"; + this.lblChoixPhoto.Size = new System.Drawing.Size(125, 32); + this.lblChoixPhoto.TabIndex = 14; + this.lblChoixPhoto.Text = "Cliquer pour sélectionner une photo"; + this.lblChoixPhoto.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.lblChoixPhoto.Visible = false; + this.lblChoixPhoto.Click += new System.EventHandler(this.LblChoixPhoto_Click); + // + // lstContact + // + this.lstContact.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; + this.lstContact.FormattingEnabled = true; + 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.TabIndex = 9; + this.lstContact.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lstContact_DrawItem); + this.lstContact.SelectedIndexChanged += new System.EventHandler(this.LstContact_SelectedIndexChanged); + // + // grbAjout + // + this.grbAjout.Controls.Add(this.radioEntreprise); + this.grbAjout.Controls.Add(this.radioPerso); + this.grbAjout.Controls.Add(this.btnAnnuler); + this.grbAjout.Controls.Add(this.btnAjouter); + this.grbAjout.Controls.Add(this.txtTel); + this.grbAjout.Controls.Add(this.label3); + this.grbAjout.Controls.Add(this.txtPrenom); + this.grbAjout.Controls.Add(this.lblPrenom); + this.grbAjout.Controls.Add(this.txtNom); + this.grbAjout.Controls.Add(this.label1); + this.grbAjout.Location = new System.Drawing.Point(12, 265); + this.grbAjout.Name = "grbAjout"; + this.grbAjout.Size = new System.Drawing.Size(170, 177); + this.grbAjout.TabIndex = 8; + this.grbAjout.TabStop = false; + this.grbAjout.Text = "ajout contact"; + // + // radioEntreprise + // + this.radioEntreprise.AutoSize = true; + this.radioEntreprise.ForeColor = System.Drawing.Color.Green; + this.radioEntreprise.Location = new System.Drawing.Point(98, 101); + this.radioEntreprise.Name = "radioEntreprise"; + this.radioEntreprise.Size = new System.Drawing.Size(72, 17); + this.radioEntreprise.TabIndex = 11; + this.radioEntreprise.TabStop = true; + this.radioEntreprise.Text = "Entreprise"; + this.radioEntreprise.UseVisualStyleBackColor = true; + this.radioEntreprise.CheckedChanged += new System.EventHandler(this.radioEntreprise_CheckedChanged); + // + // radioPerso + // + this.radioPerso.AutoSize = true; + this.radioPerso.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.radioPerso.Location = new System.Drawing.Point(22, 101); + this.radioPerso.Name = "radioPerso"; + this.radioPerso.Size = new System.Drawing.Size(52, 17); + this.radioPerso.TabIndex = 10; + this.radioPerso.TabStop = true; + this.radioPerso.Text = "Perso"; + this.radioPerso.UseVisualStyleBackColor = true; + this.radioPerso.CheckedChanged += new System.EventHandler(this.radioPerso_CheckedChanged); + // + // btnAnnuler + // + this.btnAnnuler.Image = global::Contacts.Properties.Resources.annuler; + this.btnAnnuler.Location = new System.Drawing.Point(115, 126); + this.btnAnnuler.Name = "btnAnnuler"; + this.btnAnnuler.Size = new System.Drawing.Size(45, 45); + this.btnAnnuler.TabIndex = 9; + this.btnAnnuler.UseVisualStyleBackColor = true; + this.btnAnnuler.Click += new System.EventHandler(this.BtnAnnuler_Click); + // + // btnAjouter + // + this.btnAjouter.Image = global::Contacts.Properties.Resources.ajouter; + this.btnAjouter.Location = new System.Drawing.Point(54, 126); + this.btnAjouter.Name = "btnAjouter"; + this.btnAjouter.Size = new System.Drawing.Size(45, 45); + this.btnAjouter.TabIndex = 8; + this.btnAjouter.UseVisualStyleBackColor = true; + this.btnAjouter.Click += new System.EventHandler(this.BtnAjouter_Click); + // + // txtTel + // + this.txtTel.Location = new System.Drawing.Point(54, 75); + this.txtTel.Name = "txtTel"; + this.txtTel.Size = new System.Drawing.Size(106, 20); + this.txtTel.TabIndex = 7; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(7, 78); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(18, 13); + this.label3.TabIndex = 6; + this.label3.Text = "tel"; + // + // txtPrenom + // + this.txtPrenom.Location = new System.Drawing.Point(54, 49); + this.txtPrenom.Name = "txtPrenom"; + this.txtPrenom.Size = new System.Drawing.Size(106, 20); + this.txtPrenom.TabIndex = 5; + // + // lblPrenom + // + this.lblPrenom.AutoSize = true; + this.lblPrenom.Location = new System.Drawing.Point(7, 52); + this.lblPrenom.Name = "lblPrenom"; + this.lblPrenom.Size = new System.Drawing.Size(42, 13); + this.lblPrenom.TabIndex = 4; + this.lblPrenom.Text = "prénom"; + // + // txtNom + // + this.txtNom.Location = new System.Drawing.Point(54, 23); + this.txtNom.Name = "txtNom"; + this.txtNom.Size = new System.Drawing.Size(106, 20); + this.txtNom.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 26); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(27, 13); + this.label1.TabIndex = 0; + this.label1.Text = "nom"; + // + // btnNouveauContact + // + this.btnNouveauContact.Location = new System.Drawing.Point(12, 237); + this.btnNouveauContact.Name = "btnNouveauContact"; + this.btnNouveauContact.Size = new System.Drawing.Size(169, 20); + this.btnNouveauContact.TabIndex = 10; + this.btnNouveauContact.Text = "nouveau contact"; + this.btnNouveauContact.UseVisualStyleBackColor = true; + this.btnNouveauContact.Click += new System.EventHandler(this.btnNouveauContact_Click); + // + // grbContacts + // + this.grbContacts.Controls.Add(this.lstContact); + this.grbContacts.Controls.Add(this.btnSuppr); + 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.TabIndex = 15; + this.grbContacts.TabStop = false; + this.grbContacts.Text = "les contacts"; + // + // btnSuppr + // + this.btnSuppr.Image = global::Contacts.Properties.Resources.supprimer; + this.btnSuppr.Location = new System.Drawing.Point(279, 354); + this.btnSuppr.Name = "btnSuppr"; + this.btnSuppr.Size = new System.Drawing.Size(45, 45); + this.btnSuppr.TabIndex = 10; + this.btnSuppr.UseVisualStyleBackColor = true; + this.btnSuppr.Click += new System.EventHandler(this.BtnSuppr_Click); + // + // btnModif + // + this.btnModif.Image = global::Contacts.Properties.Resources.modifier; + this.btnModif.Location = new System.Drawing.Point(228, 354); + this.btnModif.Name = "btnModif"; + this.btnModif.Size = new System.Drawing.Size(45, 45); + this.btnModif.TabIndex = 11; + this.btnModif.UseVisualStyleBackColor = true; + this.btnModif.Click += new System.EventHandler(this.BtnModif_Click); + // + // imgPhoto + // + this.imgPhoto.Enabled = false; + this.imgPhoto.Image = global::Contacts.Properties.Resources.vide; + this.imgPhoto.Location = new System.Drawing.Point(12, 31); + this.imgPhoto.Name = "imgPhoto"; + this.imgPhoto.Size = new System.Drawing.Size(170, 200); + this.imgPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.imgPhoto.TabIndex = 13; + this.imgPhoto.TabStop = false; + this.imgPhoto.Click += new System.EventHandler(this.ImgPhoto_Click); + // + // 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.Controls.Add(this.grbContacts); + this.Controls.Add(this.btnNouveauContact); + this.Controls.Add(this.lblChoixPhoto); + this.Controls.Add(this.imgPhoto); + this.Controls.Add(this.grbAjout); + this.Name = "frmContacts"; + this.Text = "Contacts"; + this.Load += new System.EventHandler(this.FrmContacts_Load); + this.grbAjout.ResumeLayout(false); + this.grbAjout.PerformLayout(); + this.grbContacts.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.imgPhoto)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lblChoixPhoto; + private System.Windows.Forms.PictureBox imgPhoto; + private System.Windows.Forms.ListBox lstContact; + private System.Windows.Forms.Button btnModif; + private System.Windows.Forms.Button btnSuppr; + private System.Windows.Forms.GroupBox grbAjout; + private System.Windows.Forms.Button btnAnnuler; + private System.Windows.Forms.Button btnAjouter; + private System.Windows.Forms.TextBox txtTel; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtPrenom; + private System.Windows.Forms.Label lblPrenom; + private System.Windows.Forms.TextBox txtNom; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnNouveauContact; + private System.Windows.Forms.GroupBox grbContacts; + private System.Windows.Forms.RadioButton radioEntreprise; + private System.Windows.Forms.RadioButton radioPerso; + } +} + diff --git a/Contacts/FrmContacts.cs b/Contacts/FrmContacts.cs new file mode 100644 index 0000000..ce305c3 --- /dev/null +++ b/Contacts/FrmContacts.cs @@ -0,0 +1,383 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace Contacts +{ + /// + /// Classe frmContacts + /// Formulaire des contacts + /// + public partial class frmContacts : Form + { + // liste des contacts + private List lesContacts = new List(); + // nom du fichier de sérialisation + private string fichier = "ficcontact"; + + /// + /// Constructeur + /// + public frmContacts() + { + InitializeComponent(); + } + + /// + /// Préparer l'ajout en gérant les objets graphiques + /// + private void DebutAjout() + { + // Gérer les accès aux objets graphiques + grbAjout.Enabled = true; + grbContacts.Enabled = false; + imgPhoto.Enabled = true; + btnNouveauContact.Enabled = false; + lblChoixPhoto.Visible = true; + // désactiver la ligne sélectionnée dans la liste + lstContact.SelectedIndex = -1; + // affiche la photo standard + AffichePhotoStandard(); + // se positionner sur le nom + txtNom.Focus(); + } + + /// + /// Préparer l'après ajout en gérant les objets graphiques + /// + private void FinAjout() + { + // Gérer les accès aux objets graphiques + grbAjout.Enabled = false; + grbContacts.Enabled = true; + imgPhoto.Enabled = false; + btnNouveauContact.Enabled = true; + lblChoixPhoto.Visible = false; + // vider les zones de saisie + txtNom.Text = ""; + txtPrenom.Text = ""; + txtTel.Text = ""; + // se positoinner sur la liste + lstContact.Focus(); + radioPerso.Checked = true; + } + + /// + /// se positionner sur la ligne demandée en paramètre ou la 1e ligne si la liste n'est pas vide + /// + /// ligne à sélectionner + private void PositionDansListe(String ligne) + { + try + { + if (ligne != null) + { + int index = lstContact.FindStringExact(ligne); + lstContact.SelectedIndex = index; + } + else + { + lstContact.SelectedIndex = 0; + } + } + catch + { + lstContact.SelectedIndex = -1; + } + } + + /// + /// Mettre à jour la listbox avec tous les contacts + /// et si demandé, se positionner sur la ligne reçue en paramètre + /// + /// ligne à sélectionner + private void MajListBox(String ligne) + { + // trier la liste + lesContacts.Sort(); + // lier la ListBox avec lesContacts pour la remplir + BindingList bdlContacts = new BindingList(lesContacts); + lstContact.DataSource = bdlContacts; + // si le dictionnaire est vide, mettre la photo vide + if (lesContacts.Count == 0) + { + VidePhoto(); + } + // sauver la liste dans le fichier + Serialise.Sauve(fichier, lesContacts); + // se positionner sur la ligne demandée en paramètre ou la 1e ligne si la liste n'est pas vide + PositionDansListe(ligne); + } + + /// + /// Vider l'affichage de la photo (afficher une photo blanche) + /// + private void VidePhoto() + { + imgPhoto.Image = Properties.Resources.vide; + } + + /// + /// Afficher la photo standard + /// + private void AffichePhotoStandard() + { + imgPhoto.Image = Properties.Resources.standard; + } + + /// + /// Supprimer le contact donc l'index est reçu en paramètre + /// + /// index du contact à supprimer + private void SupprContact(int index) + { + if (index != -1) + { + lesContacts.RemoveAt(index); + MajListBox(null); + } + } + + /// + /// Evénement Click sur le bouton bntSuppr + /// Supprimer le contact sélectionné + /// + /// + /// + private void BtnSuppr_Click(object sender, EventArgs e) + { + // contrôler qu'une ligne est bien sélectionnée + if (lstContact.SelectedIndex != -1) + { + // demander une confirmation de suppression + if (MessageBox.Show("Supprimer le contact ?", "Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK) + { + // supprimer le contact sélectionné + SupprContact(lstContact.SelectedIndex); + } + } + } + + /// + /// Evénement sélection d'un contact dans la lstContact + /// Charger la photo + /// + /// + /// + private void LstContact_SelectedIndexChanged(object sender, EventArgs e) + { + // si une ligne est sélectionnée + if (lstContact.SelectedIndex != -1) + { + Contact leContact = lesContacts[lstContact.SelectedIndex]; + // afficher l'image + imgPhoto.Image = leContact.getPhoto(); + } + else + { + // affiche une image vide + VidePhoto(); + } + } + + /// + /// Evénement clic sur bouton btnAjouter + /// Ajouter le contact dans la liste + /// + /// + /// + private void BtnAjouter_Click(object sender, EventArgs e) + { + // vérifier que le nom, prénom et tel ne sont pas vides + if (!txtNom.Text.Equals("") && !txtTel.Text.Equals("") && !txtPrenom.Text.Equals("") || radioEntreprise.Checked) + { + // créer le contact et l'ajouter dans la collection + Contact nouveauContact; + if (radioPerso.Checked) + { + nouveauContact = new Contact(txtNom.Text.ToUpper(), txtPrenom.Text, txtTel.Text, imgPhoto.Image); + } + else + { + nouveauContact = new Contact(txtNom.Text.ToUpper(), txtTel.Text, imgPhoto.Image); + } + lesContacts.Add(nouveauContact); + // mettre à jour de la ListBox + MajListBox(nouveauContact.ToString()); + // gérer la fin de l'ajout au niveau des objets graphiques + FinAjout(); + } + else + { + MessageBox.Show("Toutes les zones sont obligatoires"); + } + } + + /// + /// Evénement clic sur le bouton btnModif + /// Supprimer le contact et transférer ces informations dans la zone d'ajout + /// + /// + /// + private void BtnModif_Click(object sender, EventArgs e) + { + // contrôler si un contact est sélectionné + if (lstContact.SelectedIndex != -1) + { + // récupérer l'index du contact + int index = lstContact.SelectedIndex; + // récupérer le contact concerné + Contact leContact = lesContacts[index]; + // supprimer le contact + SupprContact(index); + // remplir les zones d'ajout avec les informations du contact + txtNom.Text = leContact.getNom(); + txtPrenom.Text = leContact.getPrenom(); + txtTel.Text = leContact.getTel(); + // gérer le début de l'ajout au niveau des objets graphiques + DebutAjout(); + // mettre la photo du contact + imgPhoto.Image = leContact.getPhoto(); + } + } + + /// + /// Evénement chargement de frmContacts + /// Préparer les composants et récupérer la sérialisation + /// + /// + /// + private void FrmContacts_Load(object sender, EventArgs e) + { + // préparer les composants graphiques comme pour la fin d'un ajout + FinAjout(); + // récupérer la sauvegarde des contacts, si elle existe + Object recupContacts = Serialise.Recup(fichier); + if (recupContacts != null) + { + lesContacts = (List)recupContacts; + // remplir de la listbox avec les contacts récupérés + MajListBox(null); + } + } + + /// + /// Evénement Click sur le bouton btnAnnuler + /// Annuler la tentative d'ajout + /// + /// + /// + private void BtnAnnuler_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Attention les informations seront perdues.", "Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK) + { + // gérer la fin de l'ajout au niveau des objets graphiques + FinAjout(); + // mettre à jour la listbox + MajListBox(null); + } + } + + /// + /// Evénement Click sur la photo + /// possibilité de sélectionner une photo + /// + /// + /// + private void ImgPhoto_Click(object sender, EventArgs e) + { + // boite de dialogue pour sélectionner un fichier + OpenFileDialog rechercheFichier; + rechercheFichier = new OpenFileDialog(); + DialogResult choix = rechercheFichier.ShowDialog(); + // si un fichier est sélectionné + if (choix == DialogResult.OK) + { + // récupérer le fichier + string nomFichier = rechercheFichier.FileName; + // tente d'afficher l'image + try + { + imgPhoto.Image = Image.FromFile(nomFichier); + } + catch + { + // erreur le fichier n'est pas une image + MessageBox.Show("Le fichier n'est pas une image"); + } + } + } + + /// + /// Evénement Click sur le label lblChoixPhoto + /// mêmes traitements que le clic sur la photo + /// + /// + /// + private void LblChoixPhoto_Click(object sender, EventArgs e) + { + ImgPhoto_Click(null, null); + } + + /// + /// Evénement Click sur le bouton btnNouveauContact + /// Permettre d'ajouter un contact + /// + /// + /// + private void btnNouveauContact_Click(object sender, EventArgs e) + { + DebutAjout(); + } + + /// + /// Evenement lorsque radioPerso est sélectionné + /// + /// + /// + private void radioPerso_CheckedChanged(object sender, EventArgs e) + { + ChangeTypeContact(); + } + + /// + /// Active/Désactive txtPrenom et lblPrenom selon le choix de l'utilisateur + /// + private void ChangeTypeContact() + { + lblPrenom.Visible = radioPerso.Checked; + txtPrenom.Visible = radioPerso.Checked; + } + + /// + /// Evenement lorsque radioEntreprise est sélectionné + /// + /// + /// + private void radioEntreprise_CheckedChanged(object sender, EventArgs e) + { + ChangeTypeContact(); + } + + private void lstContact_DrawItem(object sender, DrawItemEventArgs e) + { + //Récupérer la couleur du radio correspondant + Color couleur; + e.DrawBackground(); + Contact leContacts = lesContacts[e.Index]; + if (leContacts.IsPersonne()) + { + couleur = radioPerso.ForeColor; + }else + { + couleur = radioEntreprise.ForeColor; + } + Brush brush = new SolidBrush(couleur); + + e.Graphics.DrawString(lstContact.Items[e.Index].ToString(), + e.Font, brush, e.Bounds, StringFormat.GenericDefault); + } + } +} diff --git a/Contacts/FrmContacts.resx b/Contacts/FrmContacts.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Contacts/FrmContacts.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Contacts/Program.cs b/Contacts/Program.cs new file mode 100644 index 0000000..bbe0d81 --- /dev/null +++ b/Contacts/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Contacts +{ + static class Program + { + /// + /// Point d'entrée principal de l'application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmContacts()); + } + } +} diff --git a/Contacts/Properties/AssemblyInfo.cs b/Contacts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a449518 --- /dev/null +++ b/Contacts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("Contacts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Contacts")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur true à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("7a989ff0-cb51-4312-b11c-5f8476e5a113")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Contacts/Properties/Resources.Designer.cs b/Contacts/Properties/Resources.Designer.cs new file mode 100644 index 0000000..90e3272 --- /dev/null +++ b/Contacts/Properties/Resources.Designer.cs @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace Contacts.Properties { + using System; + + + /// + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Contacts.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ajouter { + get { + object obj = ResourceManager.GetObject("ajouter", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap annuler { + get { + object obj = ResourceManager.GetObject("annuler", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap modifier { + get { + object obj = ResourceManager.GetObject("modifier", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap playagain { + get { + object obj = ResourceManager.GetObject("playagain", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap standard { + get { + object obj = ResourceManager.GetObject("standard", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap supprimer { + get { + object obj = ResourceManager.GetObject("supprimer", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap vide { + get { + object obj = ResourceManager.GetObject("vide", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Contacts/Properties/Resources.resx b/Contacts/Properties/Resources.resx new file mode 100644 index 0000000..f687809 --- /dev/null +++ b/Contacts/Properties/Resources.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\modifier.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\annuler.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\playagain.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ajouter.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\vide.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\supprimer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\standard.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Contacts/Properties/Settings.Designer.cs b/Contacts/Properties/Settings.Designer.cs new file mode 100644 index 0000000..10e61d8 --- /dev/null +++ b/Contacts/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Contacts.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Contacts/Properties/Settings.settings b/Contacts/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Contacts/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Contacts/Resources/ajouter.png b/Contacts/Resources/ajouter.png new file mode 100644 index 0000000..b7237a2 Binary files /dev/null and b/Contacts/Resources/ajouter.png differ diff --git a/Contacts/Resources/annuler.png b/Contacts/Resources/annuler.png new file mode 100644 index 0000000..b917f31 Binary files /dev/null and b/Contacts/Resources/annuler.png differ diff --git a/Contacts/Resources/modifier.png b/Contacts/Resources/modifier.png new file mode 100644 index 0000000..4108230 Binary files /dev/null and b/Contacts/Resources/modifier.png differ diff --git a/Contacts/Resources/playagain.png b/Contacts/Resources/playagain.png new file mode 100644 index 0000000..9bbd7f4 Binary files /dev/null and b/Contacts/Resources/playagain.png differ diff --git a/Contacts/Resources/standard.png b/Contacts/Resources/standard.png new file mode 100644 index 0000000..c06c176 Binary files /dev/null and b/Contacts/Resources/standard.png differ diff --git a/Contacts/Resources/supprimer.png b/Contacts/Resources/supprimer.png new file mode 100644 index 0000000..29ed5b7 Binary files /dev/null and b/Contacts/Resources/supprimer.png differ diff --git a/Contacts/Resources/vide.png b/Contacts/Resources/vide.png new file mode 100644 index 0000000..2e433c9 Binary files /dev/null and b/Contacts/Resources/vide.png differ diff --git a/Contacts/Serialise.cs b/Contacts/Serialise.cs new file mode 100644 index 0000000..7acd117 --- /dev/null +++ b/Contacts/Serialise.cs @@ -0,0 +1,69 @@ +using System; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + +namespace Contacts +{ + /// + /// Classe Sérialise + /// Permet de sauvegarder en binaire et récupérer des objets + /// + public abstract class Serialise + { + /// + /// Sérialisation + /// + /// nom du fichier de sauvegarde + /// objet à sérialiser + public static void Sauve(string fichier, Object objet) + { + // si le fichier existe, il faut le supprimer + if (File.Exists(fichier)) + { + File.Delete(fichier); + } + // création du flux pour l'écriture dans le fichier + FileStream flux = new FileStream(fichier, FileMode.Create); + // création d'un objet pour le formatage en binaire des informations + BinaryFormatter fbinaire = new BinaryFormatter(); + // sérialisation des objets de la collection + fbinaire.Serialize(flux, objet); + // fermeture du flux + flux.Close(); + } + + /// + /// Désérialisation + /// + /// nom du fichier de sauvegarde + /// objet désérialisé + public static Object Recup(string fichier) + { + // Contrôle de l'existance du fichier + if (File.Exists(fichier)) + { + // ouverture du flux pour la lecture dans le fichier + FileStream flux = new FileStream(fichier, FileMode.Open); + // création d'un objet pour le formatage en binaire des informations + BinaryFormatter fbinaire = new BinaryFormatter(); + // récupération de l'objet sérialisé + try + { + Object objet = fbinaire.Deserialize(flux); + // fermeture du flux + flux.Close(); + // retour de l'objet + return objet; + } + catch + { + return null; + } + } + else + { + return null; + } + } + } +}