private void SetHandlers() { DeleteButton.Click += (object sender, RoutedEventArgs e) => { string message = "Ви впевнені що хочете видалити пацієнта " + Patient.LastName + " " + Patient.FirstName + " " + Patient.MiddleName + " ?"; DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } Patient.DeletedDate = DateTime.Now; unitOfWork.Patients.Update(Patient); unitOfWork.Save(); foreach (var examination in Patient.Examinations) { examination.DeletedDate = DateTime.Now; unitOfWork.Examinations.Update(examination); foreach (var data in examination.ExaminationDatas) { data.DeletedDate = DateTime.Now; unitOfWork.ExaminationDatas.Update(data); } } unitOfWork.Save(); Close(); }; EditButton.Click += (object sender, RoutedEventArgs e) => { PatientWindow patientWindow = new PatientWindow(Patient, ActionType.Edit); patientWindow.ShowDialog(); SetContent(); }; ExaminationListBox.SelectionChanged += (object sender, SelectionChangedEventArgs args) => { var examination = ExaminationListBox.SelectedItem as Examination; if (examination != null) { ExaminationInfoWindow examinationInfoWindow = new ExaminationInfoWindow(examination.Id); examinationInfoWindow.Owner = this; examinationInfoWindow.Closed += (object o, EventArgs eventArgs) => { SetContent(); }; examinationInfoWindow.Show(); } ExaminationListBox.SelectedIndex = -1; }; CreateButton.Click += (object sender, RoutedEventArgs args) => { var examinationToCreate = new Examination(); examinationToCreate.Patient = Patient; examinationToCreate.PatientId = Patient.Id; examinationToCreate.ExaminationDate = DateTime.Now; ExaminationWindow examinationWindow = new ExaminationWindow(examinationToCreate, ActionType.Create); examinationWindow.Owner = this; examinationWindow.Closed += (object o, EventArgs args1) => { SetContent(); }; examinationWindow.Show(); }; }
public void SetHandlers() { DataBox.SelectionChanged += (object sender, SelectionChangedEventArgs args) => { var data = DataBox.SelectedItem as ExaminationData; if (data != null) { ImageWindow imageWindow = new ImageWindow(data.Id); imageWindow.Owner = this; imageWindow.Show(); } DataBox.SelectedIndex = -1; }; DeleteButton.Click += (object sender, RoutedEventArgs e) => { string message = "Ви впевнені що хочете видалити " + Examination.ExaminationType.TypeName + " " + Examination.Diagnosis + " " + Examination.ExaminationDate.ToString("dd.MM.yyyy") + " ?"; DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } Examination.DeletedDate = DateTime.Now; unitOfWork.Examinations.Update(Examination); unitOfWork.Save(); foreach (var data in Examination.ExaminationDatas) { data.DeletedDate = DateTime.Now; unitOfWork.ExaminationDatas.Update(data); } unitOfWork.Save(); Close(); }; EditButton.Click += (object sender, RoutedEventArgs e) => { ExaminationWindow examinationWindow = new ExaminationWindow(Examination, ActionType.Edit); examinationWindow.ShowDialog(); SetContent(); }; CreateButton.Click += (object sender, RoutedEventArgs e) => { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.png;*.jpeg;*.jpg)|*.png;*.jpeg;*.jpg|All files (*.*)|*.*"; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == true) { string fileExt = System.IO.Path.GetExtension(openFileDialog.FileName); if (fileExt == ".jpeg" || fileExt == ".jpg" || fileExt == ".png") { ExaminationData data = new ExaminationData(); data.ExaminationId = Examination.Id; data.Examination = Examination; data.Data = File.ReadAllBytes(openFileDialog.FileName); unitOfWork.ExaminationDatas.Create(data); } else { MessageBox.Show("Ви вибрали файл з непідртимуваним розширенням" + ", будь-ласка виберіть зображення" , "Неправильний файл", MessageBoxButton.OK, MessageBoxImage.Exclamation); } SetContent(); } }; }
public void SetButtonHandlers() { CancelButton.Click += (object sender, RoutedEventArgs e) => { Close(); }; WorkButton.Click += (object sender, RoutedEventArgs e) => { if (NameRule.Validate(LastNameBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult || NameRule.Validate(FirstNameBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult || NameRule.Validate(MiddleNameBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult) { return; } LocalPatient.FirstName = FirstNameBox.Text; LocalPatient.MiddleName = MiddleNameBox.Text; LocalPatient.LastName = LastNameBox.Text; LocalPatient.BirthDate = BirthDatePicker.DisplayDate; if (NameRule.Validate(RegionBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult || NameRule.Validate(SettlementBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult || NameRule.Validate(StreetBox.Text, CultureInfo.CurrentCulture) != ValidationResult.ValidResult) { LocalPatient.Street = null; LocalPatient.StreetId = null; if (Action == ActionType.Edit) { unitOfWork.Patients.Update(LocalPatient); unitOfWork.Save(); Close(); } else if (Action == ActionType.Create) { unitOfWork.Patients.Create(LocalPatient); unitOfWork.Save(); Close(); } } var streets = unitOfWork.Streets.GetAll() .Where(street => street.DeletedDate == null && street.Settlement.SettlementName.CompareTo(SettlementBox.Text) == 0 && street.Settlement.Region.RegionName.CompareTo(RegionBox.Text) == 0 && street.StreetName.CompareTo(StreetBox.Text) == 0).ToList(); Region newRegion = new Region(); Settlement newSettlement = new Settlement(); Street newStreet = new Street(); if (streets.Count == 0) { string message = "Для того щоб " + ActionText(Action) + " пацієнта також потрібно створити вулицю: \"" + StreetBox.Text + "\". Ви впевнені що хочете " + ActionText(Action) + " пацієнта?"; var settlements = unitOfWork.Settlements.GetAll() .Where(settlement => settlement.DeletedDate == null && settlement.SettlementName.CompareTo(SettlementBox.Text) == 0 && settlement.Region.RegionName.CompareTo(RegionBox.Text) == 0).ToList(); if (settlements.Count == 0) { message = "Для того щоб " + ActionText(Action) + " пацієнта також потрібно створити населений пункт: \"" + SettlementBox.Text + "\" та вулицю: \"" + StreetBox.Text + "\" в цьому населеному пункті. Ви впевнені що хочете " + ActionText(Action) + " пацієнта?"; var regions = unitOfWork.Regions.GetAll() .Where(region => region.DeletedDate == null && region.RegionName.CompareTo(RegionBox.Text) == 0).ToList(); if (regions.Count == 0) { message = "Для того щоб " + ActionText(Action) + " пацієнта також потрібно створити область: \"" + RegionBox.Text + "\", населений пункт: \"" + SettlementBox.Text + "\" в цій області та вулицю: \"" + StreetBox.Text + "\" в цьому населеному пункті. Ви впевнені що хочете " + ActionText(Action) + " пацієнта?"; DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } newRegion = new Region { RegionName = RegionBox.Text, DeletedDate = null }; unitOfWork.Regions.Create(newRegion); unitOfWork.Save(); } else { DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } newRegion = regions.First(); } newSettlement = new Settlement { RegionId = newRegion.Id, SettlementName = SettlementBox.Text, DeletedDate = null }; unitOfWork.Settlements.Create(newSettlement); unitOfWork.Save(); } else { DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } newSettlement = settlements.First(); } newStreet = new Street { StreetName = StreetBox.Text, SettlementId = newSettlement.Id, DeletedDate = null }; unitOfWork.Streets.Create(newStreet); unitOfWork.Save(); LocalPatient.Street = newStreet; LocalPatient.StreetId = newStreet.Id; } else { LocalPatient.Street = streets.First(); LocalPatient.StreetId = streets.First().Id; } if (Action == ActionType.Edit) { unitOfWork.Patients.Update(LocalPatient); unitOfWork.Save(); Close(); } else if (Action == ActionType.Create) { unitOfWork.Patients.Create(LocalPatient); unitOfWork.Save(); Close(); } }; }