From 440a888011ecd9fac1cc2643e5a9f7eed8b33e4c Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Thu, 16 May 2024 01:04:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=86=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=B2,=20=D0=B2=D1=80=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=B9,=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=B2=D0=BE=D0=B9=D0=BD=D0=BE=D0=BC=D1=83=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Patient.cs | 2 +- .../SearchModels/PatientSearchModel.cs | 2 +- .../ViewModels/PatientViewModel.cs | 2 +- .../Storages/PatientStorage.cs | 2 +- Medical/MedicalView/FormAbstractList.cs | 2 + Medical/MedicalView/FormMain.cs | 2 + .../Patients/FormPatient.Designer.cs | 68 ++++++----- Medical/MedicalView/Patients/FormPatient.cs | 110 +++++++++++++++++- 8 files changed, 155 insertions(+), 35 deletions(-) diff --git a/Medical/MedicalDatabaseContracts/Models/Patient.cs b/Medical/MedicalDatabaseContracts/Models/Patient.cs index 9ef5351..92c4a47 100644 --- a/Medical/MedicalDatabaseContracts/Models/Patient.cs +++ b/Medical/MedicalDatabaseContracts/Models/Patient.cs @@ -4,7 +4,7 @@ namespace MedicalDatabaseContracts.Models { public class Patient : AbstractPersonModel { - public char Gender { get; set; } + public string Gender { get; set; } = string.Empty; public DateTime Birthday { get; set; } public int Weight { get; set; } public int Height { get; set; } diff --git a/Medical/MedicalDatabaseContracts/SearchModels/PatientSearchModel.cs b/Medical/MedicalDatabaseContracts/SearchModels/PatientSearchModel.cs index c0d6fee..190d65f 100644 --- a/Medical/MedicalDatabaseContracts/SearchModels/PatientSearchModel.cs +++ b/Medical/MedicalDatabaseContracts/SearchModels/PatientSearchModel.cs @@ -2,6 +2,6 @@ { public class PatientSearchModel : AbstractPersonSearchModel { - public char? Gender { get; set; } + public string? Gender { get; set; } } } diff --git a/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs b/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs index 0bdd3bb..91d89e2 100644 --- a/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs +++ b/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs @@ -5,7 +5,7 @@ namespace MedicalDatabaseContracts.ViewModels public class PatientViewModel : AbstractPersonViewModel { [DisplayName("Пол")] - public char Gender { get; set; } + public string Gender { get; set; } [DisplayName("Дата рождения")] public DateTime Birthday { get; set; } [DisplayName("Вес, кг")] diff --git a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs index 2f991d9..7078a12 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs @@ -18,7 +18,7 @@ namespace MedicalPostgresqlDatabase.Storages Surname = Convert.ToString(reader.GetValue("surname")), Patronymic = Convert.ToString(reader.GetValue("patronymic")), PhoneNumber = Convert.ToString(reader.GetValue("phone_number")), - Gender = Convert.ToChar(reader.GetValue("gender")), + Gender = Convert.ToString(reader.GetValue("gender")), Birthday = Convert.ToDateTime(reader.GetValue("birthday")), Weight = Convert.ToInt32(reader.GetValue("weight")), Height = Convert.ToInt32(reader.GetValue("height")), diff --git a/Medical/MedicalView/FormAbstractList.cs b/Medical/MedicalView/FormAbstractList.cs index 33cb96d..ce1bc82 100644 --- a/Medical/MedicalView/FormAbstractList.cs +++ b/Medical/MedicalView/FormAbstractList.cs @@ -19,6 +19,8 @@ namespace MedicalView public FormAbstractList(ILogger> logger, ILogic logic) { InitializeComponent(); + dataGridView.CellDoubleClick += EditItemToolStripMenuItem_Click; + dataGridView.CellContentDoubleClick += EditItemToolStripMenuItem_Click; _logger = logger; _logic = logic; } diff --git a/Medical/MedicalView/FormMain.cs b/Medical/MedicalView/FormMain.cs index ee98d82..314bdd8 100644 --- a/Medical/MedicalView/FormMain.cs +++ b/Medical/MedicalView/FormMain.cs @@ -17,6 +17,8 @@ namespace MedicalView.Visits public FormMain(ILogger logger, ILogic visitLogic) { InitializeComponent(); + dataGridView.CellDoubleClick += buttonEdit_Click; + dataGridView.CellContentDoubleClick += buttonEdit_Click; _logger = logger; _visitLogic = visitLogic; } diff --git a/Medical/MedicalView/Patients/FormPatient.Designer.cs b/Medical/MedicalView/Patients/FormPatient.Designer.cs index 6940f4a..f33dc35 100644 --- a/Medical/MedicalView/Patients/FormPatient.Designer.cs +++ b/Medical/MedicalView/Patients/FormPatient.Designer.cs @@ -28,11 +28,11 @@ /// private void InitializeComponent() { - numericUpDown2 = new NumericUpDown(); - numericUpDown1 = new NumericUpDown(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownHeight = new NumericUpDown(); radioButtonGenderFemale = new RadioButton(); radioButtonGenderMale = new RadioButton(); - dateTimePicker1 = new DateTimePicker(); + datePickerBirthday = new DateTimePicker(); label8 = new Label(); label7 = new Label(); label6 = new Label(); @@ -48,24 +48,28 @@ label3 = new Label(); label2 = new Label(); label1 = new Label(); - ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownHeight).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); // - // numericUpDown2 + // numericUpDownWeight // - numericUpDown2.Location = new Point(86, 263); - numericUpDown2.Name = "numericUpDown2"; - numericUpDown2.Size = new Size(150, 27); - numericUpDown2.TabIndex = 44; + numericUpDownWeight.Location = new Point(86, 263); + numericUpDownWeight.Maximum = new decimal(new int[] { 500, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(150, 27); + numericUpDownWeight.TabIndex = 44; + numericUpDownWeight.Value = new decimal(new int[] { 50, 0, 0, 0 }); // - // numericUpDown1 + // numericUpDownHeight // - numericUpDown1.Location = new Point(86, 230); - numericUpDown1.Name = "numericUpDown1"; - numericUpDown1.Size = new Size(150, 27); - numericUpDown1.TabIndex = 43; + numericUpDownHeight.Location = new Point(86, 230); + numericUpDownHeight.Maximum = new decimal(new int[] { 300, 0, 0, 0 }); + numericUpDownHeight.Name = "numericUpDownHeight"; + numericUpDownHeight.Size = new Size(150, 27); + numericUpDownHeight.TabIndex = 43; + numericUpDownHeight.Value = new decimal(new int[] { 150, 0, 0, 0 }); // // radioButtonGenderFemale // @@ -74,27 +78,30 @@ radioButtonGenderFemale.Name = "radioButtonGenderFemale"; radioButtonGenderFemale.Size = new Size(43, 24); radioButtonGenderFemale.TabIndex = 42; - radioButtonGenderFemale.TabStop = true; + radioButtonGenderFemale.Tag = "Ж"; radioButtonGenderFemale.Text = "Ж"; radioButtonGenderFemale.UseVisualStyleBackColor = true; // // radioButtonGenderMale // radioButtonGenderMale.AutoSize = true; + radioButtonGenderMale.Checked = true; radioButtonGenderMale.Location = new Point(71, 199); radioButtonGenderMale.Name = "radioButtonGenderMale"; radioButtonGenderMale.Size = new Size(43, 24); radioButtonGenderMale.TabIndex = 41; radioButtonGenderMale.TabStop = true; + radioButtonGenderMale.Tag = "М"; radioButtonGenderMale.Text = "М"; radioButtonGenderMale.UseVisualStyleBackColor = true; // - // dateTimePicker1 + // datePickerBirthday // - dateTimePicker1.Location = new Point(140, 165); - dateTimePicker1.Name = "dateTimePicker1"; - dateTimePicker1.Size = new Size(185, 27); - dateTimePicker1.TabIndex = 40; + datePickerBirthday.Format = DateTimePickerFormat.Short; + datePickerBirthday.Location = new Point(140, 165); + datePickerBirthday.Name = "datePickerBirthday"; + datePickerBirthday.Size = new Size(120, 27); + datePickerBirthday.TabIndex = 40; // // label8 // @@ -147,12 +154,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; // // textBoxPhoneNumber // @@ -227,11 +236,11 @@ AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(570, 297); - Controls.Add(numericUpDown2); - Controls.Add(numericUpDown1); + Controls.Add(numericUpDownWeight); + Controls.Add(numericUpDownHeight); Controls.Add(radioButtonGenderFemale); Controls.Add(radioButtonGenderMale); - Controls.Add(dateTimePicker1); + Controls.Add(datePickerBirthday); Controls.Add(label8); Controls.Add(label7); Controls.Add(label6); @@ -248,8 +257,9 @@ MinimumSize = new Size(0, 344); Name = "FormPatient"; Text = "Редактировать пациента"; - ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); + Load += FormPatient_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownHeight).EndInit(); menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); ResumeLayout(false); @@ -258,11 +268,11 @@ #endregion - private NumericUpDown numericUpDown2; - private NumericUpDown numericUpDown1; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownHeight; private RadioButton radioButtonGenderFemale; private RadioButton radioButtonGenderMale; - private DateTimePicker dateTimePicker1; + private DateTimePicker datePickerBirthday; private Label label8; private Label label7; private Label label6; diff --git a/Medical/MedicalView/Patients/FormPatient.cs b/Medical/MedicalView/Patients/FormPatient.cs index ef46892..47296b0 100644 --- a/Medical/MedicalView/Patients/FormPatient.cs +++ b/Medical/MedicalView/Patients/FormPatient.cs @@ -1,10 +1,116 @@ -namespace MedicalView.Patients +using MedicalDatabaseContracts.Models; +using MedicalDatabaseContracts.SearchModels; +using MedicalDatabaseContracts.ViewModels; +using MedicalDatabaseContracts; +using Microsoft.Extensions.Logging; +using MedicalBusinessLogic.BusinessLogics; + +namespace MedicalView.Patients { public partial class FormPatient : FormAbstractDetail { - public FormPatient() + private readonly ILogger _logger; + private readonly ILogic _logic; + public FormPatient( + ILogger logger, + ILogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ApplyToolStripMenuItem_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + else if (string.IsNullOrEmpty(textBoxSurname.Text)) + { + MessageBox.Show("Заполните фамилию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + else if (string.IsNullOrEmpty(textBoxPhoneNumber.Text)) + { + MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + else if (!radioButtonGenderMale.Checked && !radioButtonGenderFemale.Checked) + { + MessageBox.Show("Укажите пол", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение модели пациента"); + try + { + var model = new Patient + { + Id = ModelId ?? 0, + Name = textBoxName.Text, + Surname = textBoxSurname.Text, + Patronymic = textBoxPatronymic.Text, + PhoneNumber = textBoxPhoneNumber.Text, + Birthday = datePickerBirthday.Value, + Gender = (string)(radioButtonGenderMale.Checked ? radioButtonGenderMale.Tag : radioButtonGenderFemale.Tag), + Weight = (int)numericUpDownWeight.Value, + Height = (int)numericUpDownHeight.Value + }; + var operationResult = ModelId.HasValue ? _logic.Update(model) : _logic.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); + } + } + + private void CancelToolStripMenuItem_Click(object sender, EventArgs e) + { + Cancel(); + } + + private void FormPatient_Load(object sender, EventArgs e) + { + if (ModelId.HasValue) + { + try + { + _logger.LogInformation("Получение модели врача"); + var view = _logic.ReadElement(ModelId.Value); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxSurname.Text = view.Surname; + textBoxPatronymic.Text = view.Patronymic; + textBoxPhoneNumber.Text = view.PhoneNumber; + datePickerBirthday.Value = view.Birthday; + if (view.Gender == (string)radioButtonGenderMale.Tag) + { + radioButtonGenderMale.Checked = true; + } + else + { + radioButtonGenderFemale.Checked = true; + } + numericUpDownHeight.Value = view.Height; + numericUpDownWeight.Value = view.Weight; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения модели пациента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } }