コード例 #1
0
        public void InitDoctor()
        {
            _btnSaveDoctor.Click += (sender, args) =>
            {
                if (string.IsNullOrEmpty(_txtFirstName.Text) ||
                    string.IsNullOrEmpty(_txtSecondName.Text) ||
                    string.IsNullOrEmpty(_txtThirdName.Text) ||
                    string.IsNullOrEmpty(_txtPhone.Text))
                {
                    MessageBox.Show("Заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (_dtpBirthDay.Value > new DateTime(2008, 1, 1))
                {
                    MessageBox.Show("Неправильно указан день рождения", "Внимание", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    return;
                }

                try
                {
                    using (var context = new DentalContext())
                    {
                        var selectDoctore = new Doctor(_txtFirstName.Text, _txtSecondName.Text, _txtThirdName.Text, _txtPhone.Text, _dtpBirthDay.Value);
                        context.Doctors.AddOrUpdate(selectDoctore);
                        context.SaveChanges();
                        _objectListViewDoctore.SetObjects(context.Doctors);
                        ResetDoctorControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };
            _btnUpdateDoctore.Click += (sender, args) =>
            {
                try
                {
                    using (var contex = new DentalContext())
                    {
                        var updateDoctore = _objectListViewDoctore.SelectedObject as Doctor;
                        if (updateDoctore == null)
                        {
                            MessageBox.Show("Укажите доктора для редактирования", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        updateDoctore.FirstName   = _txtFirstName.Text;
                        updateDoctore.SecondName  = _txtSecondName.Text;
                        updateDoctore.ThirdName   = _txtThirdName.Text;
                        updateDoctore.PhoneNumber = _txtPhone.Text;
                        updateDoctore.BirthDay    = _dtpBirthDay.Value;
                        contex.Doctors.AddOrUpdate(updateDoctore);
                        contex.SaveChanges();
                        _objectListViewDoctore.SetObjects(contex.Doctors);
                        ResetDoctorControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };

            _btnDeleteDoctore.Click += (sender, args) =>
            {
                using (var dentalContext = new DentalContext())
                {
                    var selectDoctore  = _objectListViewDoctore.SelectedObject as Doctor;
                    var deletedDoctore = dentalContext.Patients.Include("MedicationHistories").First(d => d.Id == selectDoctore.Id);
                    if (selectDoctore == null)
                    {
                        MessageBox.Show("Укажите доктора", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    dentalContext.Doctors.Remove(selectDoctore);

                    dentalContext.SaveChanges();

                    _objectListViewDoctore.SetObjects(dentalContext.Doctors);

                    ResetDoctorControls();
                }

                Close();
            };

            _objectListViewDoctore.SelectedIndexChanged += (sender, args) =>
            {
                var selectedPatient = _objectListViewDoctore.SelectedObject as Doctor;
                if (selectedPatient == null)
                {
                    return;
                }
                _txtFirstName.Text  = selectedPatient.FirstName;
                _txtSecondName.Text = selectedPatient.SecondName;
                _txtThirdName.Text  = selectedPatient.ThirdName;
                _txtPhone.Text      = selectedPatient.PhoneNumber;
                _dtpBirthDay.Value  = selectedPatient.BirthDay;
            };
        }
コード例 #2
0
ファイル: PatientForm.cs プロジェクト: TilyaGit/Dental
        private void InitMedicationPage()
        {
            _olvColumnDiagnosis.AspectToStringConverter = (ob) =>
            {
                var diagnosis = (Diagnosis)ob;
                return(diagnosis.GetDesc());
            };

            if (_selectedPatient != null)
            {
                _listOfMedications.SetObjects(_selectedPatient.MedicationHistories);
            }

            _comboDiagnostics.DataSource    = typeof(Diagnosis).ToList();
            _comboDiagnostics.DisplayMember = "value";
            _comboDiagnostics.ValueMember   = "key";

            using (var db = new DentalContext())
            {
                _comboBoxDoctor.DataSource      = db.Doctors.ToList();
                _comboDiagnostics.DisplayMember = "value";
                _comboDiagnostics.ValueMember   = "key";

                _comboServce.DataSource         = db.ServiceCategories.ToList();
                _comboDiagnostics.DisplayMember = "value";
                _comboDiagnostics.ValueMember   = "key";
            }

            _btnSaveMedication.Click += (sender, args) =>
            {
                if (_selectedPatient == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(_txtPlan.Text))
                {
                    MessageBox.Show("Заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var plan       = _txtPlan.Text;
                var diagnosis  = (Diagnosis)((KeyValuePair <int, string>)(_comboDiagnostics.SelectedItem)).Key;
                var medication = new Medication(plan, diagnosis);

                if (_pictureboxImage.Image != null)
                {
                    var imageName = Path.GetFileName(_pictureboxImage.ImageLocation);

                    var image = ImageToByteArray(_pictureboxImage.Image);

                    medication.AddImage(imageName, image);
                }

                using (var context = new DentalContext())
                {
                    context.Patients.AddOrUpdate(_selectedPatient);
                    var patient = context.Patients.Include("MedicationHistories").First(f => f.Id == _selectedPatient.Id);
                    patient.AddSick(medication);
                    context.SaveChanges();
                    _listOfMedications.SetObjects(patient.MedicationHistories);
                }

                ResetMedicationControls();
            };

            _btnDeleteMedication.Click += (sender, args) =>
            {
                using (var context = new DentalContext())
                {
                    var deletedMedication = _listOfMedications.SelectedObject as Medication;
                    if (deletedMedication == null)
                    {
                        return;
                    }
                    if (MessageBox.Show($"Удалить лечения '{deletedMedication.Diagnosis.GetDesc()}' ?",
                                        "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        return;
                    }

                    _selectedPatient = context.Patients.Include("MedicationHistories")
                                       .First(q => q.Id == _selectedPatient.Id);

                    _selectedPatient.DeleteSick(deletedMedication.Id);
                    context.SaveChanges();
                    _listOfMedications.SetObjects(_selectedPatient.MedicationHistories);
                }
            };

            _btnUpdateMedication.Click += (sender, args) =>
            {
                try
                {
                    using (var context = new DentalContext())
                    {
                        var updateMedication = _listOfMedications.SelectedObject as Medication;
                        if (updateMedication == null)
                        {
                            MessageBox.Show("Укажите лечения для редактирования", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        updateMedication.Plan = _txtPlan.Text;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };

            _listOfMedications.SelectedIndexChanged += (sender, args) =>
            {
                Medication selectedMedication = _listOfMedications.SelectedObject as Medication;
                if (selectedMedication == null)
                {
                    return;
                }

                _comboDiagnostics.SelectedIndex = (int)selectedMedication.Diagnosis - 1;
                _txtPlan.Text = selectedMedication.Plan;

                var image = selectedMedication.Images.FirstOrDefault()?.Image;
                _pictureboxImage.Image = ConvertToImage(image);
            };

            _btnLoadSnapshot.Click += (sender, args) =>
            {
                using (var dialog = new OpenFileDialog())
                {
                    dialog.Title  = "Open Image";
                    dialog.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG";

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        _pictureboxImage.Load(dialog.FileName);
                    }
                }
            };
            //_listOfMedications.SmallImageList = new ImageList();
            //_listOfMedications.LargeImageList = new ImageList();
            ////_olvColumnImage.ImageGetter += rowObject =>
            ////{
            ////    var item = rowObject as Medication;
            ////    var image = item?.Fir
            ////};
        }
コード例 #3
0
ファイル: PatientForm.cs プロジェクト: TilyaGit/Dental
        private void InitPatientPage()
        {
            if (_selectedPatient != null)
            {
                _txtFirstName.Text  = _selectedPatient.FirstName;
                _txtSecondName.Text = _selectedPatient.SecondName;
                _txtThirdName.Text  = _selectedPatient.ThirdName;
                _txtPhone.Text      = _selectedPatient.PhoneNumber;
                _dtpBirthDay.Value  = _selectedPatient.BirthDay;
            }

            _btnSave.Click += (sender, args) =>
            {
                if (string.IsNullOrEmpty(_txtFirstName.Text) ||
                    string.IsNullOrEmpty(_txtSecondName.Text) ||
                    string.IsNullOrEmpty(_txtThirdName.Text) ||
                    string.IsNullOrEmpty(_txtPhone.Text))
                {
                    MessageBox.Show("Заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (_dtpBirthDay.Value > new DateTime(2020, 1, 1))
                {
                    MessageBox.Show("Неправильно указан день рождения", "Внимание", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    return;
                }

                using (var context = new DentalContext())
                {
                    _selectedPatient?.With(_txtFirstName.Text, _txtSecondName.Text, _txtThirdName.Text, _txtPhone.Text, _dtpBirthDay.Value);

                    _selectedPatient = _selectedPatient ?? new Patient(_txtFirstName.Text, _txtSecondName.Text, _txtThirdName.Text,
                                                                       _txtPhone.Text, _dtpBirthDay.Value);

                    context.Patients.Add(_selectedPatient);

                    context.SaveChanges();

                    _listOfPations.SetObjects(context.Patients);

                    ResetPatientControls();
                }
            };
            _btnUpdate.Click += (sender, args) =>
            {
                try
                {
                    using (var contex = new DentalContext())
                    {
                        var updatePatien = _listOfPations.SelectedObject as Patient;
                        if (updatePatien == null)
                        {
                            MessageBox.Show("Укажите пациента для редактирования", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        updatePatien.FirstName   = _txtFirstName.Text;
                        updatePatien.SecondName  = _txtSecondName.Text;
                        updatePatien.ThirdName   = _txtThirdName.Text;
                        updatePatien.PhoneNumber = _txtPhone.Text;
                        updatePatien.BirthDay    = _dtpBirthDay.Value;
                        contex.Patients.AddOrUpdate(updatePatien);
                        contex.SaveChanges();
                        _listOfPations.SetObjects(contex.Patients);
                        ResetPatientControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };

            _btnDelete.Click += (sender, args) =>
            {
                if (_selectedPatient == null)
                {
                    MessageBox.Show("Укажите пациента", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                using (var dentalContext = new DentalContext())
                {
                    var deletedPatient = dentalContext.Patients.Include("MedicationHistories").First(d => d.Id == _selectedPatient.Id);

                    if (deletedPatient.MedicationHistories.Count != 0)
                    {
                        MessageBox.Show(" У пациента есть лечение", "Перейдите в лечение пациента",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (deletedPatient.MedicationHistories.Any() ||
                        MessageBox.Show(
                            $"Удалить пациента '{_selectedPatient.FirstName} {_selectedPatient.SecondName}' ?",
                            "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes
                        )
                    {
                        return;
                    }

                    dentalContext.Patients.Remove(deletedPatient);

                    dentalContext.SaveChanges();

                    ResetPatientControls();
                }

                Close();
            };

            _listOfPations.SelectedIndexChanged += (sender, args) =>
            {
                var selectedPatient = _listOfPations.SelectedObject as Patient;
                if (selectedPatient == null)
                {
                    return;
                }
                _txtFirstName.Text  = selectedPatient.FirstName;
                _txtSecondName.Text = selectedPatient.SecondName;
                _txtThirdName.Text  = selectedPatient.ThirdName;
                _txtPhone.Text      = selectedPatient.PhoneNumber;
                _dtpBirthDay.Value  = selectedPatient.BirthDay;
            };
        }
コード例 #4
0
        public void InitService()
        {
            _btnSaveService.Click += (sender, args) =>
            {
                if (string.IsNullOrEmpty(_txtNameService.Text) || string.IsNullOrEmpty(_txtDesscribe.Text))
                {
                    MessageBox.Show("Заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                try
                {
                    using (var context = new DentalContext())
                    {
                        var selectService = new ServiceCategory(_txtNameService.Text, _txtDesscribe.Text);
                        context.ServiceCategories.Add(selectService);
                        context.SaveChanges();
                        _objectListViewService.SetObjects(context.ServiceCategories);
                        ResetServiceControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };

            _btnUpdateService.Click += (sender, args) =>
            {
                try
                {
                    using (var contex = new DentalContext())
                    {
                        var updateService = _objectListViewService.SelectedObject as ServiceCategory;
                        if (updateService == null)
                        {
                            MessageBox.Show("Укажите услугу для редактирования", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        updateService.Name      = _txtNameService.Text;
                        updateService.Desscribe = _txtDesscribe.Text;
                        contex.ServiceCategories.AddOrUpdate(updateService);
                        contex.SaveChanges();
                        _objectListViewService.SetObjects(contex.ServiceCategories);
                        ResetServiceControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка", ex.Message);
                }
            };

            _btnDeleteService.Click += (sender, args) =>
            {
                using (var context = new DentalContext())
                {
                    var selectService  = _objectListViewService.SelectedObject as ServiceCategory;
                    var deletedDoctore = context.Patients.First(d => d.Id == selectService.Id);
                    if (selectService == null)
                    {
                        MessageBox.Show("Укажите услугу", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    context.ServiceCategories.Remove(selectService);

                    context.SaveChanges();

                    _objectListViewService.SetObjects(context.ServiceCategories);

                    ResetServiceControls();
                }

                Close();
            };

            _objectListViewService.SelectedIndexChanged += (sender, args) =>
            {
                var selectedService = _objectListViewService.SelectedObject as ServiceCategory;
                if (selectedService == null)
                {
                    return;
                }
                _txtNameService.Text = selectedService.Name;
                _txtDesscribe.Text   = selectedService.Desscribe;
            };
        }