コード例 #1
0
    {   /// <summary>
        ///
        /// </summary>
        /// <param name="Carnet d'adresse"></param>
        ///
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ObservableCollection <Contact> contacts = new ObservableCollection <Contact>();
            ListeContact registre = new ListeContact(contacts);

            EntreeSortie.Lecture(registre);
            Application.Run(new Form1(registre));
        }
コード例 #2
0
        /// <summary>
        /// Bouton pour supprimer un contact avec boîte de confirmation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSupp_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Êtes-vous sûr de vouloir supprimer ce contact ?", "", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                Liste.Registre.Remove(Liste.Registre[listeContact.SelectedIndex]); // A modifier pour utiliser Liste.Supprimer(contact)
                EntreeSortie.Ecriture(Liste);
                ViderChamps();
                RafraichirListe();
                ActiverBouton(false);
            }
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSauve_Click(object sender, EventArgs e)
 {
     if (Modification)
     {
         try
         {
             Liste.SupprimerContact(listeContact.SelectedIndex);
             Liste.InsererContact(new Contact(boxNom.Text, boxPrenom.Text, boxAdresse.Text, boxCP.Text, boxVille.Text, boxTel.Text, boxEmail.Text, boxProvince.Text), listeContact.SelectedIndex);
             EntreeSortie.Ecriture(Liste);
             MessageBox.Show("Contact enregistré");
             ActiverChamps(false);
             ViderChamps();
             RafraichirListe();
             Modification = false;
         }
         catch (EmailInvalideException exception)
         {
             MessageBox.Show(exception.Message);
             boxEmail.SelectAll();
             boxEmail.Focus();
         }
         catch (CodePostalException exception)
         {
             MessageBox.Show(exception.Message);
             boxCP.SelectAll();
             boxCP.Focus();
         }
         catch (TelephoneInvalideException exception)
         {
             MessageBox.Show(exception.Message);
             boxTel.SelectAll();
             boxTel.Focus();
         }
         catch (ContactDejaPresentException exception)
         {
             DialogResult dialog = MessageBox.Show(exception.Message + "\nVoulez-vous mettre à jour ?", "", MessageBoxButtons.YesNo);
             if (dialog == DialogResult.Yes)
             {
                 Liste.SupprimerContact(exception.Index);
                 Liste.InsererContact(new Contact(boxNom.Text, boxPrenom.Text, boxAdresse.Text, boxCP.Text, boxVille.Text, boxTel.Text, boxEmail.Text, boxProvince.Text), exception.Index);
                 EntreeSortie.Ecriture(Liste);
             }
             else
             {
                 boxNom.Focus();
                 boxNom.SelectAll();
             }
         }
     }
     else
     {
         try
         {
             Liste.AjouterContact(new Contact(boxNom.Text, boxPrenom.Text, boxAdresse.Text, boxCP.Text, boxVille.Text, boxTel.Text, boxEmail.Text, boxProvince.Text));
             EntreeSortie.Ecriture(Liste);
             MessageBox.Show("Contact enregistré");
             ActiverChamps(false);
             ViderChamps();
             RafraichirListe();
         }
         catch (EmailInvalideException exception)
         {
             MessageBox.Show(exception.Message);
             boxEmail.SelectAll();
             boxEmail.Focus();
         }
         catch (CodePostalException exception)
         {
             MessageBox.Show(exception.Message);
             boxCP.SelectAll();
             boxCP.Focus();
         }
         catch (TelephoneInvalideException exception)
         {
             MessageBox.Show(exception.Message);
             boxTel.SelectAll();
             boxTel.Focus();
         }
         catch (ContactDejaPresentException exception)
         {
             DialogResult dialog = MessageBox.Show(exception.Message + "\nVoulez-vous mettre à jour ?", "", MessageBoxButtons.YesNo);
             if (dialog == DialogResult.Yes)
             {
                 Liste.SupprimerContact(exception.Index);
                 Liste.InsererContact(new Contact(boxNom.Text, boxPrenom.Text, boxAdresse.Text, boxCP.Text, boxVille.Text, boxTel.Text, boxEmail.Text, boxProvince.Text), exception.Index);
                 EntreeSortie.Ecriture(Liste);
             }
             else
             {
                 boxNom.Focus();
                 boxNom.SelectAll();
             }
         }
     }
 }