private void btnAssignerMedecin_Click(object sender, RoutedEventArgs e)
        {
            Dossier_Admission dossier = dgDossiersMedecin.SelectedItem as Dossier_Admission;
            Medecin           medecin = cbAutresMedecins.SelectedItem as Medecin;

            if (dossier == null)
            {
                MessageBox.Show("Veuillez sélectionner un patient dans la liste de patients.", "Avertissement", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (medecin == null)
            {
                MessageBox.Show("Veuillez sélectionner un médecin dans la liste de médecin pour assignation.", "Avertissement", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            dossier.idMedecin = medecin.idMedecin;

            try
            {
                Singleton.Instance.bd.SaveChanges();
                MessageBox.Show("Médecin assigné avec succès!", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                refresh();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnRetirerMedecin_Click(object sender, RoutedEventArgs e)
        {
            Medecin medecin = cbMedecins.SelectedItem as Medecin;

            var reponse = MessageBox.Show("Vous souhaitez retirer le Dr. " + medecin.prenomMedecin + " " + medecin.nomMedecin + " du système?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            Singleton.Instance.bd.Medecins.Remove(medecin);

            //Retirer ce médecin de tous les dossiers de patients
            List <Dossier_Admission> dossiersMedecin = Singleton.Instance.bd.Dossier_Admission.Where(d => d.idMedecin == medecin.idMedecin).ToList();

            foreach (Dossier_Admission dossier in dossiersMedecin)
            {
                dossier.idMedecin = null;
            }

            if (reponse == MessageBoxResult.Yes)
            {
                try
                {
                    Singleton.Instance.bd.SaveChanges();
                    MessageBox.Show("Médecin effacé.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
                    refresh();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btnAjouterMed_Click(object sender, RoutedEventArgs e)
        {
            Medecin med = new Medecin();

            med.nomMedecin        = txtNom.Text;
            med.prenomMedecin     = txtPrenom.Text;
            med.specialiteMedecin = txtSpecialite.Text;
            Departement dep = cbDepartement.SelectedItem as Departement;

            med.departementMedecin = dep.idDepartement;

            Singleton.Instance.bd.Medecins.Add(med);

            try
            {
                Singleton.Instance.bd.SaveChanges();
                MessageBox.Show("Médecin ajouté avec succès.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
                //J'utilise la méthode refresh() de la fenêtre "owner" (i.e. AdminWindow).
                ((AdminWindow)this.Owner).refresh();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSupprimer_Click(object sender, RoutedEventArgs e)
        {
            using (NLHContext context = new NLHContext())
            {
                Medecin med = dataGridMedecins.SelectedItem as Medecin;

                var deleteMed = context.Medecins.Where(m => m.IdMedecin == med.IdMedecin).SingleOrDefault();

                var nbrDos = context.DossierAdmissions.Count(d => d.IdMedecin == deleteMed.IdMedecin);

                if (nbrDos > 0)
                {
                    MessageBox.Show("Ce médecin a déjà un patient", "Attention", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    MessageBoxResult messageBoxResult = MessageBox.Show("Êtes-vous sûr ?", "Confirmation de suppression", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        context.Medecins.Remove(deleteMed);

                        dataGridMedecins.Items.Remove(med);

                        context.SaveChanges();

                        Clear();

                        MessageBox.Show("Médecin supprimé !", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void cbMedecinNomCompletPrep_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Medecin med = cbMedecinNomCompletPrep.SelectedItem as Medecin;

            if (med != null)
            {
                txtSpecialitePrep.Text = med.specialiteMedecin;
            }
        }
        private void cbMedecins_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Medecin medecin = cbMedecins.SelectedItem as Medecin;
            List <Dossier_Admission> dossiers = Singleton.Instance.bd.Dossier_Admission.Where(d => d.idMedecin == medecin.idMedecin).Where(d => d.dateConge == null).ToList();

            dgDossiersMedecin.ItemsSource = dossiers;

            List <Medecin> autresMedecins = Singleton.Instance.bd.Medecins.Where(m => m.idMedecin != medecin.idMedecin).ToList();

            cbAutresMedecins.DataContext = autresMedecins;

            txtSpecialite.Text = medecin.specialiteMedecin;
            cbDepartementsChanger.SelectedIndex = (int)medecin.departementMedecin - 1;
        }
        private void btnAjouter_Click(object sender, RoutedEventArgs e)
        {
            using (NLHContext context = new NLHContext())
            {
                // validate if fields are empty
                if (txtPrenom.Text == string.Empty || txtNom.Text == string.Empty || txtSpecialite.Text == string.Empty)
                {
                    MessageBox.Show("Une ou plus des champs est vide", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if ((string)btnAjouter.Content == "Ajouter")
                {
                    Medecin medecin = new Medecin
                    {
                        Prenom     = txtPrenom.Text.Trim(),
                        Nom        = txtNom.Text.Trim(),
                        Specialite = txtSpecialite.Text.Trim()
                    };


                    context.Medecins.Add(medecin);

                    dataGridMedecins.Items.Add(medecin);

                    context.SaveChanges();

                    Clear();

                    MessageBox.Show("Nouveau médecin ajouté !", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else if ((string)btnAjouter.Content == "Modifier")
                {
                    var med = dataGridMedecins.SelectedItem as Medecin;

                    med.Prenom     = txtPrenom.Text;
                    med.Nom        = txtNom.Text;
                    med.Specialite = txtSpecialite.Text;

                    context.Entry(med).State = EntityState.Modified;

                    context.SaveChanges();

                    MessageBox.Show("Médecin modifié !", "Info", MessageBoxButton.OK, MessageBoxImage.Information);

                    LoadDataGrid();
                }
            }
        }
        private void cbSansMedecin_Unchecked(object sender, RoutedEventArgs e)
        {
            //Reinitialiser tous les champs et listes comme ils étaient avant d'avoir checké le checkbox.
            Medecin medecin = cbMedecins.SelectedItem as Medecin;
            List <Dossier_Admission> dossiers = Singleton.Instance.bd.Dossier_Admission.Where(d => d.idMedecin == medecin.idMedecin).Where(d => d.dateConge == null).ToList();

            dgDossiersMedecin.ItemsSource = dossiers;

            List <Medecin> autresMedecins = Singleton.Instance.bd.Medecins.Where(m => m.idMedecin != medecin.idMedecin).ToList();

            cbAutresMedecins.DataContext = autresMedecins;

            cbMedecins.IsEnabled             = true;
            cbDepartementsChanger.IsEnabled  = true;
            btnChangerDpt.IsEnabled          = true;
            btnChangerDpt.Foreground         = Brushes.Black;
            btnRetirerMedecin.IsEnabled      = true;
            cbMedecins.Foreground            = Brushes.Black;
            cbDepartementsChanger.Foreground = Brushes.Black;
            txtSpecialite.Foreground         = Brushes.Black;
            lblGrid.Content = "Patients présentement sous charge";
        }
        private void btnChangerDpt_Click(object sender, RoutedEventArgs e)
        {
            Medecin     medecin     = cbMedecins.SelectedItem as Medecin;
            Departement departement = cbDepartementsChanger.SelectedItem as Departement;

            medecin.departementMedecin = departement.idDepartement;

            var reponse = MessageBox.Show("Vous souhaitez assigner le Dr. " + medecin.prenomMedecin + " " + medecin.nomMedecin + " au département " + departement.nomDepartement + "?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (reponse == MessageBoxResult.Yes)
            {
                try
                {
                    Singleton.Instance.bd.SaveChanges();
                    MessageBox.Show("Modification effectuée.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btnENregistrer_Click(object sender, RoutedEventArgs e)
        {
            Medecin medecin = cbMedecins.SelectedItem as Medecin;

            txtSpecialite.Text = medecin.specialiteMedecin;
        }