private void btnValider_Click(object sender, RoutedEventArgs e) { if (champsRempli()) { try { using (NorthenLightsHopitalEntities db = new NorthenLightsHopitalEntities()) { if (cePatient == null) { patient nouveauPatient = new patient { nom = txtNom.Text, prenom = txtPrenom.Text, date_naissance = (DateTime)dateNais.SelectedDate, proche_parent = txtParent.Text }; db.patients.Add(nouveauPatient); db.SaveChanges(); int idPatient = nouveauPatient.id; if (ckbxAss.IsChecked == true) { assurance nouvellePolice = new assurance { no_police = int.Parse(txtAssNoPol.Text), nom_societe_assurance = txtAssNom.Text, id_client = idPatient }; db.assurances.Add(nouvellePolice); db.SaveChanges(); } } else { patient aModif = cePatient; aModif.date_naissance = (DateTime)dateNais.SelectedDate; aModif.nom = txtNom.Text; aModif.prenom = txtPrenom.Text; aModif.proche_parent = txtParent.Text; if (ckbxAss.IsChecked == true) { assurance nouvellePolice = new assurance { no_police = int.Parse(txtAssNoPol.Text), nom_societe_assurance = txtAssNom.Text, id_client = aModif.id }; db.assurances.Add(nouvellePolice); } db.Entry(aModif).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } succes(); } catch (Exception ex) { MessageBox.Show("Une erreur s'est produite : \n" + ex.Message.ToString(), "Attention" , MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } } else { MessageBox.Show("Veuillez remplir tous les champs.", "ATTENTION" , MessageBoxButton.OK, MessageBoxImage.Error); } }
public NouveauPatient(patient patient) { InitializeComponent(); cePatient = patient; initialiserChamps(cePatient); }