private void comb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Medicin med = comb1.SelectedItem as Medicin;

            tbxNom.Text    = Convert.ToString(med.Nom);
            tbxPrenom.Text = Convert.ToString(med.Prenom);
            tbxspes.Text   = Convert.ToString(med.Specialite);
        }
Beispiel #2
0
        private void btnAjouter_Click(object sender, RoutedEventArgs e)
        {
            Medicin m1 = new Medicin();

            m1.Nom        = tbxNom.Text;
            m1.Prenom     = tbxPrenom.Text;
            m1.Specialite = tbxspes.Text;
            db.Medicins.Add(m1);
            db.SaveChanges();
            datemed.ItemsSource = db.Medicins.ToList();
            tbxNom.Text         = "";
            tbxPrenom.Text      = "";
            tbxspes.Text        = "";
        }
 private void btnMod_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Medicin rez = (Medicin)comb1.SelectedItem;
         rez.Nom        = tbxNom.Text;
         rez.Prenom     = tbxPrenom.Text;
         rez.Specialite = tbxspes.Text;
         db.SaveChanges();
         datemed.ItemsSource = db.Medicins.ToList();
     }
     catch (Exception)
     {
         MessageBox.Show("Modification du donnees du medicin impossible car il est lie avec un patient!", "Message", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        private void btnSup_Click(object sender, RoutedEventArgs e)
        {
            int nr  = Convert.ToInt32(comb1.Text);
            var rez = db.Patients.Where(w => w.IdMedicin == nr).FirstOrDefault();

            if (rez != null)
            {
                MessageBox.Show("Suppression du medicin impossible car il est lie avec un patient!", "Message", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                Medicin m = db.Medicins.Where(w => w.IdMedicin == nr).FirstOrDefault();
                db.Medicins.Remove(m);

                db.SaveChanges();
                MessageBox.Show("Medicin supprime avec succes!", "Message", MessageBoxButton.OK, MessageBoxImage.Warning);
                datemed.ItemsSource = db.Medicins.ToList();
                comb1.DataContext   = db.Medicins.ToList();
            }
        }