//Delete public override bool delete(Utilisateur unUtilisateur) { List <Enfant> sesEnfants = EnfantDAO.findByEmploye(unUtilisateur.getId()); if (sesEnfants.Count() != 0) { try { EnfantDAO unDAO = new EnfantDAO(); foreach (Enfant e in sesEnfants) { unDAO.delete(e); } } catch (Exception ex) { throw new Exception("Oups: " + ex); } } Boolean retour = false; try { String requete = "DELETE FROM Utilisateur WHERE id=" + unUtilisateur.getId(); SqlCommand maCommande = new SqlCommand(requete, seConnecter()); Int32 resultat = maCommande.ExecuteNonQuery(); retour = true; } catch (Exception ex) { throw new Exception("Oups: " + ex); } return(retour); }
private void btnSupprEnfant_Click(object sender, EventArgs e) { var result = MessageBox.Show("Vous êtes sûr de vouloir supprimer cet enfant?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int idEnfant = (Int32)cbEnfants.SelectedValue; UtilisateurDAO unUtilisateurDAO = new UtilisateurDAO(); EnfantDAO enfantDao = new EnfantDAO(); Enfant unEnfant = enfantDao.find(idEnfant); Boolean check = enfantDao.delete(unEnfant); if (check == true) { MessageBox.Show("Enfant supprimé."); } else { MessageBox.Show("Incident dans la suppression de l'enfant."); } } else { MessageBox.Show("Suppression annulée"); } cbEnfants.DataSource = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue); cbEnfants.DisplayMember = "Infos"; cbEnfants.ValueMember = "Id"; }