Exemple #1
0
 public DonnerConge(int id)
 {
     InitializeComponent();
     using (NorthenLightsHopitalEntities db = new NorthenLightsHopitalEntities())
     {
         dossier = db.dossier_admission
                   .Where(dos => dos.id == id)
                   .FirstOrDefault();
     }
     id_admission = id;
     estAssurer   = verifierAssurance();
 }
        private void btnValider_Click(object sender, RoutedEventArgs e)
        {
            using (NorthenLightsHopitalEntities db = new NorthenLightsHopitalEntities())
            {
                if (dgLits.SelectedItem != null)
                {
                    accomodation_sejour nouvelAccTelevision = null;
                    accomodation_sejour nouvelAccTelephone  = null;
                    try
                    {
                        dossier_admission nouvelAdmission = new dossier_admission
                        {
                            id_client        = int.Parse(admissionData["id_client"]),
                            id_medecin       = int.Parse(admissionData["id_medecin"]),
                            date_admission   = Convert.ToDateTime(admissionData["date_admission"]),
                            raison_admission = admissionData["raison_admission"],
                            id_lit           = litChoisi.id
                        };
                        db.dossier_admission.Add(nouvelAdmission);
                        db.SaveChanges();
                        int idDossier = nouvelAdmission.id;

                        if (ckbxTelephone.IsChecked == true)
                        {
                            nouvelAccTelephone = new accomodation_sejour
                            {
                                id_dossier_admission = idDossier,
                                id_accomodation      = 5,
                                date_debut           = nouvelAdmission.date_admission,
                                upgrade_sans_frais   = false
                            };
                        }
                        if (ckbxTelevision.IsChecked == true)
                        {
                            nouvelAccTelevision = new accomodation_sejour
                            {
                                id_dossier_admission = idDossier,
                                id_accomodation      = 4,
                                date_debut           = nouvelAdmission.date_admission,
                                upgrade_sans_frais   = false
                            };
                        }
                        accomodation_sejour nouvelAccChambre = new accomodation_sejour
                        {
                            id_dossier_admission = idDossier,
                            id_accomodation      = litChoisi.id_accomodation,
                            date_debut           = nouvelAdmission.date_admission,
                            upgrade_sans_frais   = freeUpgrade
                        };
                        if (ckbxTelevision.IsChecked == true)
                        {
                            db.accomodation_sejour.Add(nouvelAccTelephone);
                        }


                        if (ckbxTelephone.IsChecked == true)
                        {
                            db.accomodation_sejour.Add(nouvelAccTelevision);
                        }
                        db.accomodation_sejour.Add(nouvelAccChambre);
                        db.lits
                        .Where(li => li.id == litChoisi.id)
                        .ToList()
                        .FirstOrDefault().occupe = true;
                        db.SaveChanges();
                        MessageBox.Show("Le patient a ete admis avec succes", "Succes"
                                        , MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Une erreur s'est produite : \n" +
                                        ex.Message.ToString(), "Attention"
                                        , MessageBoxButton.OK, MessageBoxImage.Error);
                        this.Close();
                    }
                }
            }
        }