117 lines
4.9 KiB
C#
117 lines
4.9 KiB
C#
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
|
|
{
|
|
private readonly ILogger<FormPatient> _logger;
|
|
private readonly ILogic<Patient, PatientViewModel, PatientSearchModel> _logic;
|
|
public FormPatient(
|
|
ILogger<FormPatient> logger,
|
|
ILogic<Patient, PatientViewModel, PatientSearchModel> 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|