public ObservableCollection <DataGridTreatmentsViewModel> FillGrid()
        {
            ObservableCollection <DataGridTreatmentsViewModel> dataSource = new ObservableCollection <DataGridTreatmentsViewModel>();
            ObservableCollection <Treatment> treatments = new ObservableCollection <Treatment>();
            DataGridTreatmentsViewModel      data       = new DataGridTreatmentsViewModel();
            CustomPrincipal customPrincipal             = Thread.CurrentPrincipal as CustomPrincipal;
            string          currentEmail = customPrincipal.Identity.Email;
            var             context      = new MedicalDBEntities();
            var             query        = context.Users
                                           .Where(s => s.email == currentEmail)
                                           .FirstOrDefault <User>();
            User user       = query;
            var  queryTreat = from st in context.Treatments
                              where st.idUser == user.idUser
                              select st;

            if (queryTreat != null)
            {
                foreach (Treatment t in queryTreat)
                {
                    treatments.Add(t);
                }


                dataSource = data.FillTreatmentsGrid(treatments);
                return(dataSource);
            }
            else
            {
                MessageBox.Show("Nu aveti introduse tratamente medicale momentan");
                return(null);
            }
        }
        private void SearchUser(object obj)
        {
            if (Cnp != null)
            {
                ObservableCollection <DataGridTreatmentsViewModel> dataSource = new ObservableCollection <DataGridTreatmentsViewModel>();
                ObservableCollection <Treatment> treatments = new ObservableCollection <Treatment>();
                DataGridTreatmentsViewModel      data       = new DataGridTreatmentsViewModel();
                CustomPrincipal customPrincipal             = Thread.CurrentPrincipal as CustomPrincipal;
                string          currentEmail = customPrincipal.Identity.Email;
                var             context      = new MedicalDBEntities();
                var             query        = context.Users
                                               .Where(s => s.email == currentEmail)
                                               .FirstOrDefault <User>();
                User user     = query;
                var  queryDoc = context.Doctors
                                .Where(s => s.idUser == user.idUser)
                                .FirstOrDefault <Doctor>();
                Doctor doc     = queryDoc;
                var    patient = context.Users
                                 .Where(s => s.CNP == Cnp)
                                 .FirstOrDefault <User>();
                if (patient != null)
                {
                    var queryTreat = from st in context.Treatments
                                     where st.idUser == patient.idUser
                                     select st;

                    if (queryTreat.FirstOrDefault <Treatment>() != null)
                    {
                        foreach (Treatment t in queryTreat)
                        {
                            treatments.Add(t);
                        }
                        dataSource  = data.FillTreatmentsGrid(treatments);
                        _dataSource = dataSource;
                        NotifyPropertyChanged("DataSource");
                    }
                    else
                    {
                        MessageBox.Show("Acest pacient nu are tratament momentan");
                    }
                }
                else
                {
                    MessageBox.Show("Nu s-a gasit pacient cu acest CNP");
                }
            }
            else
            {
                MessageBox.Show("Introduceti mai intai CNP-ul!");
            }
        }
Beispiel #3
0
        public ObservableCollection <DataGridTreatmentsViewModel> FillTreatmentsGrid(ObservableCollection <Treatment> treatments)
        {
            ObservableCollection <DataGridTreatmentsViewModel> dataSource = new ObservableCollection <DataGridTreatmentsViewModel>();

            foreach (Treatment t in treatments)
            {
                DataGridTreatmentsViewModel data = new DataGridTreatmentsViewModel();
                data.NamePatient    = GetPatientName(t.idUser);
                data.SurnamePatient = GetPatientSurname(t.idUser);
                data.Cnp            = GetPatientCnp(t.idUser);
                data.Diagnosis      = GetDiagnosis(t.idDiagnosis);
                data.NameDoctor     = GetDoctorName(t.idDoctor);
                data.StartDate      = t.dateStart;
                data.FinishDate     = t.dateFinish;
                data.Medicines      = GetMedicines(t.idTreatment);
                data.Observations   = t.observation;
                dataSource.Add(data);
            }
            return(dataSource);
        }