Чето работает, чето нет
This commit is contained in:
parent
f827ae1915
commit
2becaa2045
@ -20,7 +20,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
_storage = storage;
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void CheckModelIsValid(M model);
|
protected abstract void CheckModelIsValid(M model, bool modelUpdate = false);
|
||||||
|
|
||||||
protected abstract bool CheckModelBySearchModel(M model, S searchModel);
|
protected abstract bool CheckModelBySearchModel(M model, S searchModel);
|
||||||
|
|
||||||
@ -41,9 +41,9 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return ReadElement(id, out _);
|
return ReadElement(id, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<V> ReadList(S? searchModel)
|
public List<V> ReadList(S? searchModel = null)
|
||||||
{
|
{
|
||||||
return ReadList(searchModel, out _);
|
return ReadList(out _, searchModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(M model)
|
public bool Update(M model)
|
||||||
@ -51,7 +51,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return Update(model, out _);
|
return Update(model, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<V> ReadList(S? searchModel, out long elapsedMilliseconds)
|
public virtual List<V> ReadList(out long elapsedMilliseconds, S? searchModel = null)
|
||||||
{
|
{
|
||||||
var elements = _storage.GetAll(out elapsedMilliseconds);
|
var elements = _storage.GetAll(out elapsedMilliseconds);
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
elapsedMilliseconds = 0;
|
elapsedMilliseconds = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CheckModelIsValid(model);
|
CheckModelIsValid(model, true);
|
||||||
_storage.Update(model, out elapsedMilliseconds);
|
_storage.Update(model, out elapsedMilliseconds);
|
||||||
_logger.LogInformation($"Update record id:{model.Id} operation success");
|
_logger.LogInformation($"Update record id:{model.Id} operation success");
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,7 +21,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckModelIsValid(Diagnose model)
|
protected override void CheckModelIsValid(Diagnose model, bool modelUpdate = false)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -31,7 +31,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model.Name));
|
throw new ArgumentNullException(nameof(model.Name));
|
||||||
}
|
}
|
||||||
else if (ReadList(new DiagnoseSearchModel { Name = model.Name }).Count != 0)
|
if (!modelUpdate && ReadList(new DiagnoseSearchModel { Name = model.Name }).Count != 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Диагноз с таким названием уже есть: \"{model.Name}\"");
|
throw new InvalidOperationException($"Диагноз с таким названием уже есть: \"{model.Name}\"");
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckModelIsValid(Doctor model)
|
protected override void CheckModelIsValid(Doctor model, bool modelUpdate = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckModelIsValid(Patient model)
|
protected override void CheckModelIsValid(Patient model, bool modelUpdate = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckModelIsValid(Specialization model)
|
protected override void CheckModelIsValid(Specialization model, bool modelUpdate = false)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model.Name));
|
throw new ArgumentNullException(nameof(model.Name));
|
||||||
}
|
}
|
||||||
else if (ReadList(new SpecializationSearchModel { Name = model.Name }).Count != 0)
|
if (!modelUpdate && ReadList(new SpecializationSearchModel { Name = model.Name }).Count != 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Специальность с таким названием уже есть: \"{model.Name}\"");
|
throw new InvalidOperationException($"Специальность с таким названием уже есть: \"{model.Name}\"");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace MedicalBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckModelIsValid(Visit model)
|
protected override void CheckModelIsValid(Visit model, bool modelUpdate = false)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,8 @@ namespace MedicalDatabaseContracts
|
|||||||
where V : AbstractViewModel
|
where V : AbstractViewModel
|
||||||
where S : AbstractSearchModel
|
where S : AbstractSearchModel
|
||||||
{
|
{
|
||||||
List<V> ReadList(S? searchModel);
|
List<V> ReadList(S? searchModel = null);
|
||||||
List<V> ReadList(S? searchModel, out long elapsedMilliseconds);
|
List<V> ReadList(out long elapsedMilliseconds, S? searchModel = null);
|
||||||
V? ReadElement(int id);
|
V? ReadElement(int id);
|
||||||
V? ReadElement(int id, out long elapsedMilliseconds);
|
V? ReadElement(int id, out long elapsedMilliseconds);
|
||||||
bool Create(M model);
|
bool Create(M model);
|
||||||
|
@ -10,5 +10,9 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
public bool IsPediatric { get; set; }
|
public bool IsPediatric { get; set; }
|
||||||
[DisplayName("Терапевт")]
|
[DisplayName("Терапевт")]
|
||||||
public bool IsTherapeutic { get; set; }
|
public bool IsTherapeutic { get; set; }
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,12 +145,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;
|
||||||
//
|
//
|
||||||
// FormDoctor
|
// FormDoctor
|
||||||
//
|
//
|
||||||
@ -172,6 +174,7 @@
|
|||||||
MinimumSize = new Size(0, 255);
|
MinimumSize = new Size(0, 255);
|
||||||
Name = "FormDoctor";
|
Name = "FormDoctor";
|
||||||
Text = "Редактировать врача";
|
Text = "Редактировать врача";
|
||||||
|
Load += FormDoctor_Load;
|
||||||
menuStrip.ResumeLayout(false);
|
menuStrip.ResumeLayout(false);
|
||||||
menuStrip.PerformLayout();
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
@ -1,10 +1,108 @@
|
|||||||
namespace MedicalView.Doctors
|
using MedicalDatabaseContracts;
|
||||||
|
using MedicalDatabaseContracts.Models;
|
||||||
|
using MedicalDatabaseContracts.SearchModels;
|
||||||
|
using MedicalDatabaseContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace MedicalView.Doctors
|
||||||
{
|
{
|
||||||
public partial class FormDoctor : FormAbstractDetail
|
public partial class FormDoctor : FormAbstractDetail
|
||||||
{
|
{
|
||||||
public FormDoctor()
|
private readonly ILogger<FormDoctor> _logger;
|
||||||
|
private readonly ILogic<Doctor, DoctorViewModel, DoctorSearchModel> _doctorLogic;
|
||||||
|
private readonly ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> _specializationLogic;
|
||||||
|
public FormDoctor(
|
||||||
|
ILogger<FormDoctor> logger,
|
||||||
|
ILogic<Doctor, DoctorViewModel, DoctorSearchModel> logic,
|
||||||
|
ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> specializationLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_doctorLogic = logic;
|
||||||
|
_specializationLogic = specializationLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (comboBoxSpecialization.SelectedIndex == -1 || comboBoxSpecialization.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите специальность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение модели врача");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new Doctor
|
||||||
|
{
|
||||||
|
Id = ModelId ?? 0,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Surname = textBoxSurname.Text,
|
||||||
|
Patronymic = textBoxPatronymic.Text,
|
||||||
|
PhoneNumber = textBoxPhoneNumber.Text,
|
||||||
|
SpecializationId = (comboBoxSpecialization.SelectedItem as SpecializationViewModel).Id
|
||||||
|
};
|
||||||
|
var operationResult = ModelId.HasValue ? _doctorLogic.Update(model) : _doctorLogic.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 FormDoctor_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (ModelId.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение модели врача");
|
||||||
|
var view = _doctorLogic.ReadElement(ModelId.Value);
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.Name;
|
||||||
|
textBoxSurname.Text = view.Surname;
|
||||||
|
textBoxPatronymic.Text = view.Patronymic;
|
||||||
|
textBoxPhoneNumber.Text = view.PhoneNumber;
|
||||||
|
|
||||||
|
var specs = _specializationLogic.ReadList();
|
||||||
|
comboBoxSpecialization.DataSource = specs;
|
||||||
|
comboBoxSpecialization.SelectedIndex = specs.FindIndex(x => x.Id == view.SpecializationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения модели врача");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ namespace MedicalView
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
long elapsed;
|
long elapsed;
|
||||||
var items = _logic.ReadList(null, out elapsed);
|
var items = _logic.ReadList(out elapsed);
|
||||||
|
|
||||||
dataGridView.DataSource = items;
|
dataGridView.DataSource = items;
|
||||||
dataGridView.Columns["Id"].DisplayIndex = 0;
|
dataGridView.Columns["Id"].DisplayIndex = 0;
|
||||||
|
@ -68,7 +68,7 @@ namespace MedicalView.Visits
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
long elapsed;
|
long elapsed;
|
||||||
var items = _visitLogic.ReadList(null, out elapsed);
|
var items = _visitLogic.ReadList(out elapsed);
|
||||||
|
|
||||||
dataGridView.DataSource = items;
|
dataGridView.DataSource = items;
|
||||||
foreach (DataGridViewTextBoxColumn column in dataGridView.Columns)
|
foreach (DataGridViewTextBoxColumn column in dataGridView.Columns)
|
||||||
|
@ -53,12 +53,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;
|
||||||
//
|
//
|
||||||
// textBoxName
|
// textBoxName
|
||||||
//
|
//
|
||||||
@ -110,6 +112,7 @@
|
|||||||
MinimumSize = new Size(0, 155);
|
MinimumSize = new Size(0, 155);
|
||||||
Name = "FormSpecialization";
|
Name = "FormSpecialization";
|
||||||
Text = "Редактировать специализацию";
|
Text = "Редактировать специализацию";
|
||||||
|
Load += FormSpecialization_Load;
|
||||||
menuStrip.ResumeLayout(false);
|
menuStrip.ResumeLayout(false);
|
||||||
menuStrip.PerformLayout();
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
@ -1,10 +1,81 @@
|
|||||||
namespace MedicalView.Specializations
|
using MedicalDatabaseContracts;
|
||||||
|
using MedicalDatabaseContracts.Models;
|
||||||
|
using MedicalDatabaseContracts.SearchModels;
|
||||||
|
using MedicalDatabaseContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace MedicalView.Specializations
|
||||||
{
|
{
|
||||||
public partial class FormSpecialization : FormAbstractDetail
|
public partial class FormSpecialization : FormAbstractDetail
|
||||||
{
|
{
|
||||||
public FormSpecialization()
|
private readonly ILogger<FormSpecialization> _logger;
|
||||||
|
private readonly ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> _logic;
|
||||||
|
public FormSpecialization(ILogger<FormSpecialization> logger, ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение специальности");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new Specialization
|
||||||
|
{
|
||||||
|
Id = ModelId ?? 0,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
IsPediatric = checkBoxIsPediatric.Checked,
|
||||||
|
IsTherapeutic = checkBoxIsTherapeutic.Checked
|
||||||
|
};
|
||||||
|
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 FormSpecialization_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (ModelId.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение диагноза");
|
||||||
|
var view = _logic.ReadElement(ModelId.Value);
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.Name;
|
||||||
|
checkBoxIsPediatric.Checked = view.IsPediatric;
|
||||||
|
checkBoxIsTherapeutic.Checked = view.IsTherapeutic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения специальности");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user