diff --git a/Medical/MedicalView/Diagnoses/FormDiagnose.Designer.cs b/Medical/MedicalView/Diagnoses/FormDiagnose.Designer.cs index 5434abb..8df243f 100644 --- a/Medical/MedicalView/Diagnoses/FormDiagnose.Designer.cs +++ b/Medical/MedicalView/Diagnoses/FormDiagnose.Designer.cs @@ -68,12 +68,14 @@ ApplyToolStripMenuItem.Name = "ApplyToolStripMenuItem"; ApplyToolStripMenuItem.Size = new Size(97, 24); ApplyToolStripMenuItem.Text = "Сохранить"; + ApplyToolStripMenuItem.Click += ApplyToolStripMenuItem_Click; // // CancelToolStripMenuItem // CancelToolStripMenuItem.Name = "CancelToolStripMenuItem"; CancelToolStripMenuItem.Size = new Size(76, 24); CancelToolStripMenuItem.Text = "Отмена"; + CancelToolStripMenuItem.Click += CancelToolStripMenuItem_Click; // // FormDiagnose // @@ -86,6 +88,7 @@ MinimumSize = new Size(0, 125); Name = "FormDiagnose"; Text = "Редактировать диагноз"; + Load += FormDiagnose_Load; menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); ResumeLayout(false); diff --git a/Medical/MedicalView/Diagnoses/FormDiagnose.cs b/Medical/MedicalView/Diagnoses/FormDiagnose.cs index ae72656..8a0e4bf 100644 --- a/Medical/MedicalView/Diagnoses/FormDiagnose.cs +++ b/Medical/MedicalView/Diagnoses/FormDiagnose.cs @@ -1,10 +1,78 @@ -namespace MedicalView.Diagnoses +using MedicalDatabaseContracts; +using MedicalDatabaseContracts.Models; +using MedicalDatabaseContracts.SearchModels; +using MedicalDatabaseContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace MedicalView.Diagnoses { - public partial class FormDiagnose : Form + public partial class FormDiagnose : FormAbstractDetail { - public FormDiagnose() + private readonly ILogger _logger; + private readonly ILogic _diagnoseLogic; + public FormDiagnose(ILogger logger, + ILogic diagnoseLogic) { InitializeComponent(); + _diagnoseLogic = diagnoseLogic; + _logger = logger; + } + + private void FormDiagnose_Load(object sender, EventArgs e) + { + if (ModelId.HasValue) + { + try + { + _logger.LogInformation("Получение диагноза"); + var view = _diagnoseLogic.ReadElement(ModelId.Value); + if (view != null) + { + textBoxName.Text = view.Name; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения диагноза"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void CancelToolStripMenuItem_Click(object sender, EventArgs e) + { + Cancel(); + } + + private void ApplyToolStripMenuItem_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение диагноза"); + try + { + var model = new Diagnose + { + Id = ModelId ?? 0, + Name = textBoxName.Text, + }; + var operationResult = ModelId.HasValue ? _diagnoseLogic.Update(model) : _diagnoseLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения диагноза"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/Medical/MedicalView/Diagnoses/FormDiagnoses.cs b/Medical/MedicalView/Diagnoses/FormDiagnoses.cs index e347365..7fd256d 100644 --- a/Medical/MedicalView/Diagnoses/FormDiagnoses.cs +++ b/Medical/MedicalView/Diagnoses/FormDiagnoses.cs @@ -2,11 +2,12 @@ using MedicalDatabaseContracts.Models; using MedicalDatabaseContracts.SearchModels; using MedicalDatabaseContracts.ViewModels; +using MedicalView.Visits; using Microsoft.Extensions.Logging; namespace MedicalView.Diagnoses { - public class FormDiagnoses : FormAbstractList + public class FormDiagnoses : FormAbstractList { public FormDiagnoses( ILogger logger, diff --git a/Medical/MedicalView/Diagnoses/FormDiagnoses.resx b/Medical/MedicalView/Diagnoses/FormDiagnoses.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Medical/MedicalView/Diagnoses/FormDiagnoses.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Medical/MedicalView/Doctors/FormDoctor.cs b/Medical/MedicalView/Doctors/FormDoctor.cs index 140b246..5b08cc4 100644 --- a/Medical/MedicalView/Doctors/FormDoctor.cs +++ b/Medical/MedicalView/Doctors/FormDoctor.cs @@ -1,6 +1,6 @@ namespace MedicalView.Doctors { - public partial class FormDoctor : Form + public partial class FormDoctor : FormAbstractDetail { public FormDoctor() { diff --git a/Medical/MedicalView/Doctors/FormDoctors.cs b/Medical/MedicalView/Doctors/FormDoctors.cs index a9eae23..b7ba021 100644 --- a/Medical/MedicalView/Doctors/FormDoctors.cs +++ b/Medical/MedicalView/Doctors/FormDoctors.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace MedicalView.Doctors { - public class FormDoctors : FormAbstractList + public class FormDoctors : FormAbstractList { public FormDoctors( ILogger logger, diff --git a/Medical/MedicalView/FormAbstractDetail.cs b/Medical/MedicalView/FormAbstractDetail.cs new file mode 100644 index 0000000..7ff7390 --- /dev/null +++ b/Medical/MedicalView/FormAbstractDetail.cs @@ -0,0 +1,12 @@ +namespace MedicalView +{ + public class FormAbstractDetail : Form + { + public int? ModelId { protected get; set; } + protected virtual void Cancel() + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Medical/MedicalView/FormAbstractDetail.resx b/Medical/MedicalView/FormAbstractDetail.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Medical/MedicalView/FormAbstractDetail.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Medical/MedicalView/FormAbstractList.Designer.cs b/Medical/MedicalView/FormAbstractList.Designer.cs index b812a70..c27ef9b 100644 --- a/Medical/MedicalView/FormAbstractList.Designer.cs +++ b/Medical/MedicalView/FormAbstractList.Designer.cs @@ -1,6 +1,6 @@ namespace MedicalView { - partial class FormAbstractList + partial class FormAbstractList { /// /// Required designer variable. @@ -70,7 +70,7 @@ изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem"; изменитьToolStripMenuItem.Size = new Size(92, 24); изменитьToolStripMenuItem.Text = "Изменить"; - изменитьToolStripMenuItem.Click += EsitItemToolStripMenuItem_Click; + изменитьToolStripMenuItem.Click += EditItemToolStripMenuItem_Click; // // удалитьToolStripMenuItem // diff --git a/Medical/MedicalView/FormAbstractList.cs b/Medical/MedicalView/FormAbstractList.cs index b212667..64a986c 100644 --- a/Medical/MedicalView/FormAbstractList.cs +++ b/Medical/MedicalView/FormAbstractList.cs @@ -8,14 +8,15 @@ using Microsoft.Extensions.Logging; namespace MedicalView { - public partial class FormAbstractList : Form + public partial class FormAbstractList : Form where M : AbstractModel where V : AbstractViewModel where S : AbstractSearchModel + where F : FormAbstractDetail { protected ILogger _logger; protected ILogic _logic; - public FormAbstractList(ILogger> logger, ILogic logic) + public FormAbstractList(ILogger> logger, ILogic logic) { InitializeComponent(); _logger = logger; @@ -34,17 +35,55 @@ namespace MedicalView protected virtual void AddItemToolStripMenuItem_Click(object sender, EventArgs e) { - // code + var service = Program.ServiceProvider?.GetService(typeof(F)); + if (service is F form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } } - protected virtual void EsitItemToolStripMenuItem_Click(object sender, EventArgs e) + protected virtual void EditItemToolStripMenuItem_Click(object sender, EventArgs e) { - // code + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(F)); + if (service is F form) + { + form.ModelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } } protected virtual void DeleteItemToolStripMenuItem_Click(object sender, EventArgs e) { - // code + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление элемента"); + try + { + if (!_logic.Delete(id)) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления элемента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } protected virtual void LoadData() diff --git a/Medical/MedicalView/Patients/FormPatient.cs b/Medical/MedicalView/Patients/FormPatient.cs index f871522..ef46892 100644 --- a/Medical/MedicalView/Patients/FormPatient.cs +++ b/Medical/MedicalView/Patients/FormPatient.cs @@ -1,6 +1,6 @@ namespace MedicalView.Patients { - public partial class FormPatient : Form + public partial class FormPatient : FormAbstractDetail { public FormPatient() { diff --git a/Medical/MedicalView/Patients/FormPatients.cs b/Medical/MedicalView/Patients/FormPatients.cs index 79a97ed..4a1a7d6 100644 --- a/Medical/MedicalView/Patients/FormPatients.cs +++ b/Medical/MedicalView/Patients/FormPatients.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace MedicalView.Patients { - public class FormPatients : FormAbstractList + public class FormPatients : FormAbstractList { public FormPatients( ILogger logger, diff --git a/Medical/MedicalView/Specializations/FormSpecialization.cs b/Medical/MedicalView/Specializations/FormSpecialization.cs index 1b04c4d..cdb7ced 100644 --- a/Medical/MedicalView/Specializations/FormSpecialization.cs +++ b/Medical/MedicalView/Specializations/FormSpecialization.cs @@ -1,6 +1,6 @@ namespace MedicalView.Specializations { - public partial class FormSpecialization : Form + public partial class FormSpecialization : FormAbstractDetail { public FormSpecialization() { diff --git a/Medical/MedicalView/Specializations/FormSpecializations.cs b/Medical/MedicalView/Specializations/FormSpecializations.cs index ccadab0..870f8f6 100644 --- a/Medical/MedicalView/Specializations/FormSpecializations.cs +++ b/Medical/MedicalView/Specializations/FormSpecializations.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace MedicalView.Specializations { - public class FormSpecializations : FormAbstractList + public class FormSpecializations : FormAbstractList { public FormSpecializations( ILogger logger, diff --git a/Medical/MedicalView/Visits/FormVisit.cs b/Medical/MedicalView/Visits/FormVisit.cs index ab33f4f..6e2d3f8 100644 --- a/Medical/MedicalView/Visits/FormVisit.cs +++ b/Medical/MedicalView/Visits/FormVisit.cs @@ -1,6 +1,6 @@ namespace MedicalView.Visits { - public partial class FormVisit : Form + public partial class FormVisit : FormAbstractDetail { public FormVisit() {