// Lorsqu'une edition se termine private void addMode() { depEdit = null; depMedEdit = null; editing = false; editingMedical = false; btnOk.Content = "Ajouter"; clearFields(); btnNo.Visibility = Visibility.Hidden; xbIsMedical.IsEnabled = true; }
// Activer l'édition Département private void menuEdit_Click(object sender, RoutedEventArgs e) { if (dgDepts.SelectedItem == null) { return; } editing = true; editingMedical = false; btnOk.Content = "Enregistrer"; depEdit = (dgDepts.SelectedItem as Departement); txtID.Text = depEdit.ID.ToString(); txtNomDep.Text = depEdit.NomDept; btnNo.Visibility = Visibility.Visible; xbIsMedical.IsChecked = false; xbIsMedical.IsEnabled = false; }
// Suppression Département private void menuSupp_Click(object sender, RoutedEventArgs e) { if (dgDepts.SelectedItem == null) { return; } Departement delDept = dgDepts.SelectedItem as Departement; MessageBoxResult confirmer = deptCheck(delDept.NomDept, false, false); if (confirmer == MessageBoxResult.Yes) { if (delDept == depEdit) { addMode(); } mgr.BDD.Departements.Remove(delDept); mgr.SaveChanges(); actualiser(); } }
// Bouton Ajouter/Enregistrer private void btnOk_Click(object sender, RoutedEventArgs e) { if (txtNomDep.Text != String.Empty) { if (!editing) { if (!(bool)xbIsMedical.IsChecked) { // Ajout Département Departement dep = new Departement(); dep.NomDept = txtNomDep.Text; mgr.BDD.Departements.Add(dep); mgr.SaveChanges(); actualiser(); } else { // Ajout Département Médical DepartementMedical depMed = new DepartementMedical(); depMed.NomDeptMed = txtNomDep.Text; mgr.BDD.DepartementMedicals.Add(depMed); mgr.SaveChanges(); actualiser(); } MessageBox.Show("Département Ajouté!", "Succès!", MessageBoxButton.OK); } else { if (!editingMedical) { // Edition Département MessageBoxResult confirmer = deptCheck(depEdit.NomDept, true, false); if (confirmer == MessageBoxResult.Yes) { depEdit.NomDept = txtNomDep.Text; mgr.SaveChanges(); actualiser(); addMode(); } } else { // Edition Département Médical MessageBoxResult confirmer = deptCheck(depMedEdit.NomDeptMed, true, false); if (confirmer == MessageBoxResult.Yes) { depMedEdit.NomDeptMed = txtNomDep.Text; mgr.SaveChanges(); actualiser(); addMode(); } } } } else { // En cas d'erreur MessageBox.Show("Entrez un nom pour le département", "Erreur d'entrée", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }