private void AjoutCommune_Click_1(object sender, EventArgs e)
 {
     try
     {
         if (codePosatelDepartementTextBox.Text.Length > 5)
         {
             throw new CodePostalCommuneInvalideException("Code Postal trop long");
         }
         if (codePosatelDepartementTextBox.Text.Length < 5)
         {
             throw new CodePostalCommuneInvalideException("Code Postal trop court");
         }
         if (codePosatelDepartementTextBox.Text.Length == 0)
         {
             throw new CodePostalCommuneInvalideException("Code Postal requit");
         }
         myDataObject4 = new CommuneViewModel();
         myDataObject4.nomCommuneProperty = nomCommuneTextBox.Text;
         myDataObject4.codePostalProperty = codePosatelDepartementTextBox.Text;
         DepartementViewModel departement = (DepartementViewModel)listeDepartement.SelectedItem;
         CommuneViewModel     nouveau     = new CommuneViewModel(0, myDataObject4.nomCommuneProperty, myDataObject4.codePostalProperty, departement);
         lp4.Add(nouveau);
         CommuneORM.insertCommune(nouveau);
         lp4 = CommuneORM.listeCommune();
         nomCommuneTextBox.Text             = string.Empty;
         codePosatelDepartementTextBox.Text = string.Empty;
         listeDepartement.Items.Refresh();
     }
     catch (CodePostalCommuneInvalideException exptcodepostal)
     {
         MessageBox.Show(exptcodepostal.Message);
     }
 }
        private void ajouterButton(object sender, RoutedEventArgs e)
        {
            myDataObject.nomCommuneProperty = nomTextBox.Text;

            myDataObject.departementCommune = (DepartementViewModel)listeDepartementsCombo.SelectedItem;
            CommuneViewModel nouveau = new CommuneViewModel(CommuneDAL.getMaxIdCommune() + 1, myDataObject.nomCommuneProperty, myDataObject.departementCommuneProperty);

            le.Add(nouveau);
            CommuneORM.insertCommune(nouveau);
            listeCommunes.Items.Refresh();
        }
Exemple #3
0
        private void ajouterCommune_Click(object sender, EventArgs e)
        {
            myDataObject.nomCommuneProperty = Nom.Text;
            if ((DepartementViewModel)listeDepartementsCombo.SelectedItem != null)
            {
                myDataObject.departementCommune = (DepartementViewModel)listeDepartementsCombo.SelectedItem;
            }
            else
            {
                myDataObject.departementCommune = new DepartementViewModel(1, "MauvaisNumeroDepartement", 0);
            }
            CommuneViewModel nouveau = new CommuneViewModel(CommuneDAL.getMaxIdCommune() + 1, myDataObject.nomCommuneProperty, myDataObject.departementCommune);

            lu.Add(nouveau);
            CommuneORM.insertCommune(nouveau);
            listeDepartementsCombo.ItemsSource = lp;
            listeCommunes.Items.Refresh();
            listeDepartementsCombo.Items.Refresh();
            listeCommunes.ItemsSource = lu;
        }
        /////////////////////////////////////   Commune     /////////////////////////////////////
        /////////////////////////////////////   Commune     /////////////////////////////////////
        private void ValideCommune_Click(object sender, RoutedEventArgs e)
        {
            myDataObject2 = new CommuneViewModel();
            myDataObject2.nomCommuneProperty  = NomCommune.Text;
            myDataObject2.CodePostaleProperty = CodePostale.Text;
            myDataObject2.DepartementCommune  = (DepartementViewModel)listeDepartementsCombo.SelectedItem;
            CommuneViewModel nouveau = new CommuneViewModel(CommuneDAL.getMaxIdCommune() + 1, myDataObject2.nomCommuneProperty, myDataObject2.CodePostaleProperty, myDataObject2.DepartementCommune);

            lp2.Add(nouveau);

            CommuneORM.insertCommune(nouveau);

            listeDepartementsCombo.ItemsSource = lp3;
            listeCommunes.Items.Refresh();
            listeDepartementsCombo.Items.Refresh();
            listeCommunes.ItemsSource = lp2;
            compteur = lp2.Count();

            ((TextBox)NomCommune).Text  = string.Empty;
            ((TextBox)CodePostale).Text = string.Empty;

            MessageBox.Show("Commune ajoutée avec succes ! ");
        }