Работают все формы редактирования
This commit is contained in:
parent
440a888011
commit
92d9928cd2
@ -53,7 +53,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
else if (ReadList(new VisitSearchModel {
|
if (!modelUpdate && ReadList(new VisitSearchModel {
|
||||||
DoctorId = model.DoctorId,
|
DoctorId = model.DoctorId,
|
||||||
Date = model.Date,
|
Date = model.Date,
|
||||||
Time = model.Time
|
Time = model.Time
|
||||||
|
@ -13,5 +13,13 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
public string Patronymic { get; set; } = string.Empty;
|
public string Patronymic { get; set; } = string.Empty;
|
||||||
[DisplayName("Телефон")]
|
[DisplayName("Телефон")]
|
||||||
public string PhoneNumber { get; set; } = string.Empty;
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
public string GetFIO()
|
||||||
|
{
|
||||||
|
return Name + " " + Surname + " " + Patronymic ?? string.Empty;
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return GetFIO();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,9 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
{
|
{
|
||||||
[DisplayName("Название")]
|
[DisplayName("Название")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,9 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
public int SpecializationId { get; set; }
|
public int SpecializationId { get; set; }
|
||||||
[DisplayName("Специальность")]
|
[DisplayName("Специальность")]
|
||||||
public string SpecializationName { get; set; } = string.Empty;
|
public string SpecializationName { get; set; } = string.Empty;
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return GetFIO() + ", " + SpecializationName.ToLower();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,16 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
public class PatientViewModel : AbstractPersonViewModel
|
public class PatientViewModel : AbstractPersonViewModel
|
||||||
{
|
{
|
||||||
[DisplayName("Пол")]
|
[DisplayName("Пол")]
|
||||||
public string Gender { get; set; }
|
public string Gender { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата рождения")]
|
[DisplayName("Дата рождения")]
|
||||||
public DateTime Birthday { get; set; }
|
public DateTime Birthday { get; set; }
|
||||||
[DisplayName("Вес, кг")]
|
[DisplayName("Вес, кг")]
|
||||||
public int Weight { get; set; }
|
public int Weight { get; set; }
|
||||||
[DisplayName("Рост, см")]
|
[DisplayName("Рост, см")]
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return GetFIO() + ", " + Birthday.ToShortDateString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
Medical/MedicalView/FormMain.Designer.cs
generated
1
Medical/MedicalView/FormMain.Designer.cs
generated
@ -148,6 +148,7 @@
|
|||||||
buttonDelete.TabIndex = 3;
|
buttonDelete.TabIndex = 3;
|
||||||
buttonDelete.Text = "Удалить";
|
buttonDelete.Text = "Удалить";
|
||||||
buttonDelete.UseVisualStyleBackColor = true;
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += buttonDelete_Click;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
|
@ -109,10 +109,42 @@ namespace MedicalView.Visits
|
|||||||
|
|
||||||
private void buttonEdit_Click(object sender, EventArgs e)
|
private void buttonEdit_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormVisit));
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
if (service is FormVisit form)
|
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
var service = Program.ServiceProvider?.GetService(typeof(FormVisit));
|
||||||
|
if (service is FormVisit form)
|
||||||
|
{
|
||||||
|
form.ModelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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 (!_visitLogic.Delete(id))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления элемента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
Medical/MedicalView/Visits/FormVisit.Designer.cs
generated
3
Medical/MedicalView/Visits/FormVisit.Designer.cs
generated
@ -61,12 +61,14 @@
|
|||||||
ApplyToolStripMenuItem.Name = "ApplyToolStripMenuItem";
|
ApplyToolStripMenuItem.Name = "ApplyToolStripMenuItem";
|
||||||
ApplyToolStripMenuItem.Size = new Size(97, 24);
|
ApplyToolStripMenuItem.Size = new Size(97, 24);
|
||||||
ApplyToolStripMenuItem.Text = "Сохранить";
|
ApplyToolStripMenuItem.Text = "Сохранить";
|
||||||
|
ApplyToolStripMenuItem.Click += ApplyToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// CancelToolStripMenuItem
|
// CancelToolStripMenuItem
|
||||||
//
|
//
|
||||||
CancelToolStripMenuItem.Name = "CancelToolStripMenuItem";
|
CancelToolStripMenuItem.Name = "CancelToolStripMenuItem";
|
||||||
CancelToolStripMenuItem.Size = new Size(76, 24);
|
CancelToolStripMenuItem.Size = new Size(76, 24);
|
||||||
CancelToolStripMenuItem.Text = "Отмена";
|
CancelToolStripMenuItem.Text = "Отмена";
|
||||||
|
CancelToolStripMenuItem.Click += CancelToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
@ -198,6 +200,7 @@
|
|||||||
MinimumSize = new Size(484, 500);
|
MinimumSize = new Size(484, 500);
|
||||||
Name = "FormVisit";
|
Name = "FormVisit";
|
||||||
Text = "Редактировать прием";
|
Text = "Редактировать прием";
|
||||||
|
Load += FormVisit_Load;
|
||||||
menuStrip.ResumeLayout(false);
|
menuStrip.ResumeLayout(false);
|
||||||
menuStrip.PerformLayout();
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
@ -1,10 +1,113 @@
|
|||||||
namespace MedicalView.Visits
|
using MedicalDatabaseContracts;
|
||||||
|
using MedicalDatabaseContracts.Models;
|
||||||
|
using MedicalDatabaseContracts.SearchModels;
|
||||||
|
using MedicalDatabaseContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace MedicalView.Visits
|
||||||
{
|
{
|
||||||
public partial class FormVisit : FormAbstractDetail
|
public partial class FormVisit : FormAbstractDetail
|
||||||
{
|
{
|
||||||
public FormVisit()
|
private readonly ILogger _logger;
|
||||||
|
private readonly ILogic<Visit, VisitViewModel, VisitSearchModel> _visitLogic;
|
||||||
|
private readonly ILogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel> _diagnoseLogic;
|
||||||
|
private readonly ILogic<Doctor, DoctorViewModel, DoctorSearchModel> _doctorLogic;
|
||||||
|
private readonly ILogic<Patient, PatientViewModel, PatientSearchModel> _patientLogic;
|
||||||
|
public FormVisit(
|
||||||
|
ILogger<FormVisit> logger,
|
||||||
|
ILogic<Visit, VisitViewModel, VisitSearchModel> visitLogic,
|
||||||
|
ILogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel> diagnoseLogic,
|
||||||
|
ILogic<Doctor, DoctorViewModel, DoctorSearchModel> doctorLogic,
|
||||||
|
ILogic<Patient, PatientViewModel, PatientSearchModel> patientLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_visitLogic = visitLogic;
|
||||||
|
_diagnoseLogic = diagnoseLogic;
|
||||||
|
_doctorLogic = doctorLogic;
|
||||||
|
_patientLogic = patientLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxPatient.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите пациента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (comboBoxDoctor.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите врача", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение модели приема");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new Visit
|
||||||
|
{
|
||||||
|
Id = ModelId ?? 0,
|
||||||
|
Comment = textBoxComment.Text,
|
||||||
|
PatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id,
|
||||||
|
DoctorId = (comboBoxDoctor.SelectedItem as DoctorViewModel).Id,
|
||||||
|
DiagnoseId = comboBoxDiagnose.SelectedItem != null ? (comboBoxDiagnose.SelectedItem as DiagnoseViewModel).Id : null,
|
||||||
|
Date = DateOnly.FromDateTime(datePicker.Value),
|
||||||
|
Time = TimeOnly.FromDateTime(timePicker.Value)
|
||||||
|
};
|
||||||
|
var operationResult = ModelId.HasValue ? _visitLogic.Update(model) : _visitLogic.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 FormVisit_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (ModelId.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение модели приема");
|
||||||
|
var view = _visitLogic.ReadElement(ModelId.Value);
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxComment.Text = view.Comment;
|
||||||
|
datePicker.Value = view.Date.ToDateTime(view.Time);
|
||||||
|
timePicker.Value = view.Date.ToDateTime(view.Time);
|
||||||
|
var patients = _patientLogic.ReadList();
|
||||||
|
var doctors = _doctorLogic.ReadList();
|
||||||
|
var diagnoses = _diagnoseLogic.ReadList();
|
||||||
|
comboBoxPatient.DataSource = patients;
|
||||||
|
comboBoxDoctor.DataSource = doctors;
|
||||||
|
comboBoxDiagnose.DataSource = diagnoses;
|
||||||
|
if (view.DiagnoseId != null)
|
||||||
|
{
|
||||||
|
comboBoxDiagnose.SelectedIndex = diagnoses.FindIndex(x => x.Id == view.DiagnoseId);
|
||||||
|
}
|
||||||
|
comboBoxDoctor.SelectedIndex = doctors.FindIndex(x => x.Id == view.DoctorId);
|
||||||
|
comboBoxPatient.SelectedIndex = patients.FindIndex(x => x.Id == view.PatientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения модели приема");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user