From bcaa4adae889d4d33038b2353b991ca68f3a3c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=BE=D0=B3=D0=B0=D1=88=D0=BE=D0=B2=D0=B0?= Date: Wed, 5 Apr 2023 00:33:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB.=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC.=20=D0=95=D1=89=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB.=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B8=D1=81=D0=9F=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hospital/Hospital.sln | 14 +- .../BusinessLogics/IllnessLogic.cs | 113 +++++++++++++++++ .../BusinessLogics/KurseLogic.cs | 111 ++++++++++++++++ .../BusinessLogics/MedicinesLogic.cs | 117 +++++++++++++++++ .../BusinessLogics/ProceduresLogic.cs | 117 +++++++++++++++++ .../BusinessLogics/RecipesLogic.cs | 109 ++++++++++++++++ .../BusinessLogics/SymptomsLogic.cs | 113 +++++++++++++++++ .../HospitalBusinessLogic.csproj | 17 +++ .../BindingModels/IllnessBindingModel.cs | 8 +- .../BindingModels/KurseBindingModel.cs | 2 +- .../BindingModels/MedicinesBindingModel.cs | 7 +- .../BindingModels/ProceduresBindingModel.cs | 7 +- .../BindingModels/RecipesBindingModel.cs | 2 +- .../BindingModels/SymptomsBindingModel.cs | 5 +- .../BusinessLogicsContracts/IIllnessLogic.cs | 20 +++ .../BusinessLogicsContracts/IKurseLogic.cs | 20 +++ .../IMedicinesLogic.cs | 20 +++ .../IProceduresLogic.cs | 20 +++ .../BusinessLogicsContracts/IRecipesLogic.cs | 20 +++ .../BusinessLogicsContracts/ISymptomsLogic.cs | 20 +++ HospitalContracts/HospitalContracts.csproj | 5 - .../SearchModels/SymptomsSearchModel.cs | 2 +- .../StoragesContracts/IIllnessStorage.cs | 21 +++ .../StoragesContracts/IKurseStorage.cs | 21 +++ .../StoragesContracts/IMedicinesStorage.cs | 21 +++ .../StoragesContracts/IProceduresStorage.cs | 21 +++ .../StoragesContracts/IRecipesStorage.cs | 21 +++ .../StoragesContracts/ISymptomsStorage.cs | 21 +++ .../ViewModels/IllnessViewModel.cs | 21 ++- .../ViewModels/KurseViewModel.cs | 13 +- .../ViewModels/MedicinesViewModel.cs | 11 +- .../ViewModels/ProceduresViewModel.cs | 11 +- .../ViewModels/RecipesViewModel.cs | 23 +++- .../ViewModels/SymptomsViewModel.cs | 11 +- HospitalDataModels/Models/IMedicinesModel.cs | 2 +- HospitalDataModels/Models/IProceduresModel.cs | 2 +- HospitalView/Form1.cs | 10 -- HospitalView/Form1.resx | 120 ------------------ ...Form1.Designer.cs => FormMain.Designer.cs} | 23 ++-- HospitalView/FormMain.cs | 20 +++ HospitalView/FormMain.resx | 60 +++++++++ HospitalView/FormMedicine.Designer.cs | 119 +++++++++++++++++ HospitalView/FormMedicine.cs | 95 ++++++++++++++ HospitalView/FormMedicine.resx | 60 +++++++++ HospitalView/FormMedicines.Designer.cs | 117 +++++++++++++++++ HospitalView/FormMedicines.cs | 111 ++++++++++++++++ HospitalView/FormMedicines.resx | 60 +++++++++ HospitalView/FormProcedure.Designer.cs | 119 +++++++++++++++++ HospitalView/FormProcedure.cs | 94 ++++++++++++++ HospitalView/FormProcedure.resx | 60 +++++++++ HospitalView/FormProcedures.Designer.cs | 116 +++++++++++++++++ HospitalView/FormProcedures.cs | 114 +++++++++++++++++ HospitalView/FormProcedures.resx | 60 +++++++++ HospitalView/HospitalView.csproj | 9 ++ 54 files changed, 2282 insertions(+), 174 deletions(-) create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/IllnessLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/MedicinesLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/ProceduresLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/RecipesLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/SymptomsLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj create mode 100644 HospitalContracts/BusinessLogicsContracts/IIllnessLogic.cs create mode 100644 HospitalContracts/BusinessLogicsContracts/IKurseLogic.cs create mode 100644 HospitalContracts/BusinessLogicsContracts/IMedicinesLogic.cs create mode 100644 HospitalContracts/BusinessLogicsContracts/IProceduresLogic.cs create mode 100644 HospitalContracts/BusinessLogicsContracts/IRecipesLogic.cs create mode 100644 HospitalContracts/BusinessLogicsContracts/ISymptomsLogic.cs create mode 100644 HospitalContracts/StoragesContracts/IIllnessStorage.cs create mode 100644 HospitalContracts/StoragesContracts/IKurseStorage.cs create mode 100644 HospitalContracts/StoragesContracts/IMedicinesStorage.cs create mode 100644 HospitalContracts/StoragesContracts/IProceduresStorage.cs create mode 100644 HospitalContracts/StoragesContracts/IRecipesStorage.cs create mode 100644 HospitalContracts/StoragesContracts/ISymptomsStorage.cs delete mode 100644 HospitalView/Form1.cs delete mode 100644 HospitalView/Form1.resx rename HospitalView/{Form1.Designer.cs => FormMain.Designer.cs} (55%) create mode 100644 HospitalView/FormMain.cs create mode 100644 HospitalView/FormMain.resx create mode 100644 HospitalView/FormMedicine.Designer.cs create mode 100644 HospitalView/FormMedicine.cs create mode 100644 HospitalView/FormMedicine.resx create mode 100644 HospitalView/FormMedicines.Designer.cs create mode 100644 HospitalView/FormMedicines.cs create mode 100644 HospitalView/FormMedicines.resx create mode 100644 HospitalView/FormProcedure.Designer.cs create mode 100644 HospitalView/FormProcedure.cs create mode 100644 HospitalView/FormProcedure.resx create mode 100644 HospitalView/FormProcedures.Designer.cs create mode 100644 HospitalView/FormProcedures.cs create mode 100644 HospitalView/FormProcedures.resx diff --git a/Hospital/Hospital.sln b/Hospital/Hospital.sln index 8656779..4a838f4 100644 --- a/Hospital/Hospital.sln +++ b/Hospital/Hospital.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalContracts", "..\HospitalContracts\HospitalContracts.csproj", "{852D330A-F5B2-4ADE-A27B-A58F9CAAE379}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalContracts", "..\HospitalContracts\HospitalContracts.csproj", "{852D330A-F5B2-4ADE-A27B-A58F9CAAE379}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalDataModels", "..\HospitalDataModels\HospitalDataModels.csproj", "{D5C93D6A-22C6-4B67-B76C-6FC183D46513}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDataModels", "..\HospitalDataModels\HospitalDataModels.csproj", "{D5C93D6A-22C6-4B67-B76C-6FC183D46513}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalDataBaseImplements", "..\HospitalDataBaseImplements\HospitalDataBaseImplements.csproj", "{2B6A087F-E3CA-439E-9FC8-954575466B8B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDataBaseImplements", "..\HospitalDataBaseImplements\HospitalDataBaseImplements.csproj", "{2B6A087F-E3CA-439E-9FC8-954575466B8B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalView", "..\HospitalView\HospitalView.csproj", "{7CBB7FFE-03C3-4F80-9A30-C1825E2C7340}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalView", "..\HospitalView\HospitalView.csproj", "{7CBB7FFE-03C3-4F80-9A30-C1825E2C7340}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalBusinessLogic", "HospitalBusinessLogic\HospitalBusinessLogic.csproj", "{9E73B25E-6D05-4580-8082-472A1D993A34}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {7CBB7FFE-03C3-4F80-9A30-C1825E2C7340}.Debug|Any CPU.Build.0 = Debug|Any CPU {7CBB7FFE-03C3-4F80-9A30-C1825E2C7340}.Release|Any CPU.ActiveCfg = Release|Any CPU {7CBB7FFE-03C3-4F80-9A30-C1825E2C7340}.Release|Any CPU.Build.0 = Release|Any CPU + {9E73B25E-6D05-4580-8082-472A1D993A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E73B25E-6D05-4580-8082-472A1D993A34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E73B25E-6D05-4580-8082-472A1D993A34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E73B25E-6D05-4580-8082-472A1D993A34}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/IllnessLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/IllnessLogic.cs new file mode 100644 index 0000000..d3472df --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/IllnessLogic.cs @@ -0,0 +1,113 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class IllnessLogic : IIllnessLogic + { + private readonly ILogger _logger; + private readonly IIllnessStorage _illnessStorage; + public IllnessLogic(ILogger logger, IIllnessStorage illnessStorage) + { + _logger = logger; + _illnessStorage = illnessStorage; + } + public List? ReadList(IllnessSearchModel? model) + { + _logger.LogInformation("ReadList. IllnessName:{IllnessName}.Id:{ Id}", model?.IllnessName, model?.Id); + var list = model == null ? _illnessStorage.GetFullList() : _illnessStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public IllnessViewModel? ReadElement(IllnessSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IllnessName:{IllnessName}.Id:{ Id}", model.IllnessName, model.Id); + var element = _illnessStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(IllnessBindingModel model) + { + CheckModel(model); + if (_illnessStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(IllnessBindingModel model) + { + CheckModel(model); + if (_illnessStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IllnessBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_illnessStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(IllnessBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IllnessName)) + { + throw new ArgumentNullException("Нет названия болезни", + nameof(model.IllnessName)); + } + if (string.IsNullOrEmpty(model.Form)) + { + throw new ArgumentNullException("Нет формы болезни", nameof(model.Form)); + } + _logger.LogInformation("Illness. IllnessName:{IllnessName}.Form:{ Form}. Id: { Id}", model.IllnessName, model.Form, model.Id); + var element = _illnessStorage.GetElement(new IllnessSearchModel + { + IllnessName = model.IllnessName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Болезнь с таким названием уже есть"); + } + } + } +} +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs new file mode 100644 index 0000000..76d8820 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs @@ -0,0 +1,111 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class KurseLogic : IKurseLogic { + private readonly ILogger _logger; + private readonly IKurseStorage _kurseStorage; + public KurseLogic(ILogger logger, IKurseStorage kurseStorage) + { + _logger = logger; + _kurseStorage = kurseStorage; + } + public bool Create(KurseBindingModel model) + { + CheckModel(model); + if (_kurseStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(KurseBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_kurseStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public KurseViewModel? ReadElement(KurseSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _kurseStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(KurseSearchModel? model) + { + _logger.LogInformation("ReadElement. Id:{ Id}", model?.Id); + var list = model == null ? _kurseStorage.GetFullList() : _kurseStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(KurseBindingModel model) + { + CheckModel(model); + if (_kurseStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(KurseBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.MedicinesId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор лекарства", nameof(model.MedicinesId)); + } + + if (model.CountInDay <= 0) + { + throw new ArgumentNullException("Количество приемов в день должно быть больше 0", nameof(model.CountInDay)); + } + _logger.LogInformation("Kurse. KurseId:{Id}.CountInDay:{ CountInDay}. MedicinesId: { MedicinesId}", model.Id, model.CountInDay, model.MedicinesId); + } +} +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/MedicinesLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/MedicinesLogic.cs new file mode 100644 index 0000000..0d66496 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/MedicinesLogic.cs @@ -0,0 +1,117 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class MedicinesLogic : IMedicinesLogic + { + private readonly ILogger _logger; + private readonly IMedicinesStorage _medicinesStorage; + public MedicinesLogic(ILogger logger, IMedicinesStorage medicinesStorage) + { + _logger = logger; + _medicinesStorage = medicinesStorage; + } + public bool Create(MedicinesBindingModel model) + { + CheckModel(model); + if (_medicinesStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(MedicinesBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_medicinesStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public MedicinesViewModel? ReadElement(MedicinesSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. MedicinesName:{MedicinesName}. Id:{ Id}", model.MedicinesName, model.Id); + var element = _medicinesStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(MedicinesSearchModel? model) + { + _logger.LogInformation("ReadList. MedicinesName:{MedicinesName}. Id:{ Id}", model?.MedicinesName, model?.Id); + var list = model == null ? _medicinesStorage.GetFullList() : _medicinesStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(MedicinesBindingModel model) + { + CheckModel(model); + if (_medicinesStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(MedicinesBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.MedicinesName)) + { + throw new ArgumentNullException("Нет названия лекарства", nameof(model.MedicinesName)); + } + if (string.IsNullOrEmpty(model.Group)) + { + throw new ArgumentNullException("Нет группы лекарства", nameof(model.Group)); + } + _logger.LogInformation("Medicines. MedicinesName:{MedicinesName}. Group:{ Group}. Id: { Id} ", model.MedicinesName, model.Group, model.Id); + var element = _medicinesStorage.GetElement(new MedicinesSearchModel + { + MedicinesName = model.MedicinesName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Лекарство с таким названием уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/ProceduresLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/ProceduresLogic.cs new file mode 100644 index 0000000..2557789 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/ProceduresLogic.cs @@ -0,0 +1,117 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class ProceduresLogic : IProceduresLogic + { + private readonly ILogger _logger; + private readonly IProceduresStorage _proceduresStorage; + public ProceduresLogic(ILogger logger, IProceduresStorage proceduresStorage) + { + _logger = logger; + _proceduresStorage = proceduresStorage; + } + public bool Create(ProceduresBindingModel model) + { + CheckModel(model); + if (_proceduresStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ProceduresBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_proceduresStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ProceduresViewModel? ReadElement(ProceduresSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProceduresName:{ProceduresName}. Id:{ Id}", model.ProceduresName, model.Id); + var element = _proceduresStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ProceduresSearchModel? model) + { + _logger.LogInformation("ReadList. ProceduresName:{ProceduresName}. Id:{ Id}", model?.ProceduresName, model?.Id); + var list = model == null ? _proceduresStorage.GetFullList() : _proceduresStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ProceduresBindingModel model) + { + CheckModel(model); + if (_proceduresStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ProceduresBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProceduresName)) + { + throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProceduresName)); + } + if (string.IsNullOrEmpty(model.Type)) + { + throw new ArgumentNullException("Нет типа процедуры", nameof(model.Type)); + } + _logger.LogInformation("Procedures. ProceduresName:{ProceduresName}. Type:{ Type}. Id: { Id} ", model.ProceduresName, model.Type, model.Id); + var element = _proceduresStorage.GetElement(new ProceduresSearchModel + { + ProceduresName = model.ProceduresName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Процедура с таким названием уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/RecipesLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/RecipesLogic.cs new file mode 100644 index 0000000..7ea0b15 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/RecipesLogic.cs @@ -0,0 +1,109 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class RecipesLogic : IRecipesLogic + { + private readonly ILogger _logger; + private readonly IRecipesStorage _recipesStorage; + public RecipesLogic(ILogger logger, IRecipesStorage recipesStorage) + { + _logger = logger; + _recipesStorage = recipesStorage; + } + public bool Create(RecipesBindingModel model) + { + CheckModel(model); + if (_recipesStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(RecipesBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_recipesStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public RecipesViewModel? ReadElement(RecipesSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _recipesStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(RecipesSearchModel? model) + { + _logger.LogInformation("ReadElement. Id:{ Id}", model?.Id); + var list = model == null ? _recipesStorage.GetFullList() : _recipesStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(RecipesBindingModel model) + { + CheckModel(model); + if (_recipesStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(RecipesBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Dose)) + { + throw new ArgumentNullException("В рецепте нет дозировки", nameof(model.Dose)); + } + if (string.IsNullOrEmpty(model.ModeOfApplication)) + { + throw new ArgumentNullException("Нет способа приема", nameof(model.ModeOfApplication)); + } + _logger.LogInformation("Recipes. RecipesId:{Id}.Dose:{ Dose}. ModeOfApplication:{ ModeOfApplication}. SymptomsId: { SymptomsId}", model.Id, model.Dose, model.ModeOfApplication); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/SymptomsLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/SymptomsLogic.cs new file mode 100644 index 0000000..4ee3b0d --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/SymptomsLogic.cs @@ -0,0 +1,113 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.BusinessLogics +{ + public class SymptomsLogic : ISymptomsLogic + { + private readonly ILogger _logger; + private readonly ISymptomsStorage _symptomsStorage; + public SymptomsLogic(ILogger logger, ISymptomsStorage symptomsStorage) + { + _logger = logger; + _symptomsStorage = symptomsStorage; + } + public bool Create(SymptomsBindingModel model) + { + CheckModel(model); + if (_symptomsStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(SymptomsBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_symptomsStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public SymptomsViewModel? ReadElement(SymptomsSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SymptomsName:{SymptomsName}. Id:{ Id}", model.SymptomName, model.Id); + var element = _symptomsStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(SymptomsSearchModel? model) + { + _logger.LogInformation("ReadList. SymptomsName:{SymptomsName}. Id:{ Id}", model?.SymptomName, model?.Id); + var list = model == null ? _symptomsStorage.GetFullList() : _symptomsStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(SymptomsBindingModel model) + { + CheckModel(model); + if (_symptomsStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(SymptomsBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SymptomName)) + { + throw new ArgumentNullException("Нет названия симптоматики", nameof(model.SymptomName)); + } + _logger.LogInformation("Symptoms. SymptomName:{SymptomName}. Id: { Id} ", model.SymptomName, model.Id); + var element = _symptomsStorage.GetElement(new SymptomsSearchModel + { + SymptomName = model.SymptomName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Симптоматика с таким названием уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj new file mode 100644 index 0000000..2da2e32 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/HospitalContracts/BindingModels/IllnessBindingModel.cs b/HospitalContracts/BindingModels/IllnessBindingModel.cs index 4b81472..1df56ac 100644 --- a/HospitalContracts/BindingModels/IllnessBindingModel.cs +++ b/HospitalContracts/BindingModels/IllnessBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class IllnessBindingModel + public class IllnessBindingModel: IIllnessModel { public int Id { get; set; } public string IllnessName { get; set; } = string.Empty; @@ -17,6 +17,10 @@ namespace HospitalContracts.BindingModels get; set; } = new(); - + public Dictionary IllnessKurse + { + get; + set; + } = new(); } } diff --git a/HospitalContracts/BindingModels/KurseBindingModel.cs b/HospitalContracts/BindingModels/KurseBindingModel.cs index 1066d7d..ab04866 100644 --- a/HospitalContracts/BindingModels/KurseBindingModel.cs +++ b/HospitalContracts/BindingModels/KurseBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class KurseBindingModel + public class KurseBindingModel: IKurseModel { public int Id { get; set; } public string Duration { get; set; } = string.Empty; diff --git a/HospitalContracts/BindingModels/MedicinesBindingModel.cs b/HospitalContracts/BindingModels/MedicinesBindingModel.cs index 9646db3..e25201f 100644 --- a/HospitalContracts/BindingModels/MedicinesBindingModel.cs +++ b/HospitalContracts/BindingModels/MedicinesBindingModel.cs @@ -1,4 +1,5 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,10 +7,10 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class MedicinesBindingModel + public class MedicinesBindingModel: IMedicinesModel { public int Id { get; set; } - public string MedicineName { get; set; } = string.Empty; + public string MedicinesName { get; set; } = string.Empty; public string Group { get; set; } = string.Empty; } } diff --git a/HospitalContracts/BindingModels/ProceduresBindingModel.cs b/HospitalContracts/BindingModels/ProceduresBindingModel.cs index ded23da..6818bb9 100644 --- a/HospitalContracts/BindingModels/ProceduresBindingModel.cs +++ b/HospitalContracts/BindingModels/ProceduresBindingModel.cs @@ -1,4 +1,5 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,10 +7,10 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class ProceduresBindingModel + public class ProceduresBindingModel: IProceduresModel { public int Id { get; set; } - public string ProcedureName { get; set; } = string.Empty; + public string ProceduresName { get; set; } = string.Empty; public string Type { get; set; } = string.Empty; } } diff --git a/HospitalContracts/BindingModels/RecipesBindingModel.cs b/HospitalContracts/BindingModels/RecipesBindingModel.cs index 7ec5df9..b36999a 100644 --- a/HospitalContracts/BindingModels/RecipesBindingModel.cs +++ b/HospitalContracts/BindingModels/RecipesBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class RecipesBindingModel + public class RecipesBindingModel: IRecipesModel { public int Id { get; set; } public string Dose { get; set; } = string.Empty; diff --git a/HospitalContracts/BindingModels/SymptomsBindingModel.cs b/HospitalContracts/BindingModels/SymptomsBindingModel.cs index d555717..91778f5 100644 --- a/HospitalContracts/BindingModels/SymptomsBindingModel.cs +++ b/HospitalContracts/BindingModels/SymptomsBindingModel.cs @@ -1,4 +1,5 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,7 @@ using System.Threading.Tasks; namespace HospitalContracts.BindingModels { - public class SymptomsBindingModel + public class SymptomsBindingModel: ISymptomsModel { public int Id { get; set; } public string SymptomName { get; set; } = string.Empty; diff --git a/HospitalContracts/BusinessLogicsContracts/IIllnessLogic.cs b/HospitalContracts/BusinessLogicsContracts/IIllnessLogic.cs new file mode 100644 index 0000000..c24f0a6 --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/IIllnessLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IIllnessLogic + { + List? ReadList(IllnessSearchModel? model); + IllnessViewModel? ReadElement(IllnessSearchModel model); + bool Create(IllnessBindingModel model); + bool Update(IllnessBindingModel model); + bool Delete(IllnessBindingModel model); + } +} diff --git a/HospitalContracts/BusinessLogicsContracts/IKurseLogic.cs b/HospitalContracts/BusinessLogicsContracts/IKurseLogic.cs new file mode 100644 index 0000000..8a233ec --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/IKurseLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IKurseLogic + { + List? ReadList(KurseSearchModel? model); + KurseViewModel? ReadElement(KurseSearchModel model); + bool Create(KurseBindingModel model); + bool Update(KurseBindingModel model); + bool Delete(KurseBindingModel model); + } +} diff --git a/HospitalContracts/BusinessLogicsContracts/IMedicinesLogic.cs b/HospitalContracts/BusinessLogicsContracts/IMedicinesLogic.cs new file mode 100644 index 0000000..7478c89 --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/IMedicinesLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IMedicinesLogic + { + List? ReadList(MedicinesSearchModel? model); + MedicinesViewModel? ReadElement(MedicinesSearchModel model); + bool Create(MedicinesBindingModel model); + bool Update(MedicinesBindingModel model); + bool Delete(MedicinesBindingModel model); + } +} diff --git a/HospitalContracts/BusinessLogicsContracts/IProceduresLogic.cs b/HospitalContracts/BusinessLogicsContracts/IProceduresLogic.cs new file mode 100644 index 0000000..7a0b346 --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/IProceduresLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IProceduresLogic + { + List? ReadList(ProceduresSearchModel? model); + ProceduresViewModel? ReadElement(ProceduresSearchModel model); + bool Create(ProceduresBindingModel model); + bool Update(ProceduresBindingModel model); + bool Delete(ProceduresBindingModel model); + } +} diff --git a/HospitalContracts/BusinessLogicsContracts/IRecipesLogic.cs b/HospitalContracts/BusinessLogicsContracts/IRecipesLogic.cs new file mode 100644 index 0000000..84fd178 --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/IRecipesLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface IRecipesLogic + { + List? ReadList(RecipesSearchModel? model); + RecipesViewModel? ReadElement(RecipesSearchModel model); + bool Create(RecipesBindingModel model); + bool Update(RecipesBindingModel model); + bool Delete(RecipesBindingModel model); + } +} diff --git a/HospitalContracts/BusinessLogicsContracts/ISymptomsLogic.cs b/HospitalContracts/BusinessLogicsContracts/ISymptomsLogic.cs new file mode 100644 index 0000000..a943254 --- /dev/null +++ b/HospitalContracts/BusinessLogicsContracts/ISymptomsLogic.cs @@ -0,0 +1,20 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BusinessLogicsContracts +{ + public interface ISymptomsLogic + { + List? ReadList(SymptomsSearchModel? model); + SymptomsViewModel? ReadElement(SymptomsSearchModel model); + bool Create(SymptomsBindingModel model); + bool Update(SymptomsBindingModel model); + bool Delete(SymptomsBindingModel model); + } +} diff --git a/HospitalContracts/HospitalContracts.csproj b/HospitalContracts/HospitalContracts.csproj index da5e060..a2f8c75 100644 --- a/HospitalContracts/HospitalContracts.csproj +++ b/HospitalContracts/HospitalContracts.csproj @@ -6,11 +6,6 @@ enable - - - - - diff --git a/HospitalContracts/SearchModels/SymptomsSearchModel.cs b/HospitalContracts/SearchModels/SymptomsSearchModel.cs index 8938083..ae22c31 100644 --- a/HospitalContracts/SearchModels/SymptomsSearchModel.cs +++ b/HospitalContracts/SearchModels/SymptomsSearchModel.cs @@ -9,6 +9,6 @@ namespace HospitalContracts.SearchModels public class SymptomsSearchModel { public int Id { get; set; } - public string? SymptomsName { get; set; } + public string? SymptomName { get; set; } } } diff --git a/HospitalContracts/StoragesContracts/IIllnessStorage.cs b/HospitalContracts/StoragesContracts/IIllnessStorage.cs new file mode 100644 index 0000000..4414ac6 --- /dev/null +++ b/HospitalContracts/StoragesContracts/IIllnessStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface IIllnessStorage + { + List GetFullList(); + List GetFilteredList(IllnessSearchModel model); + IllnessViewModel? GetElement(IllnessSearchModel model); + IllnessViewModel? Insert(IllnessBindingModel model); + IllnessViewModel? Update(IllnessBindingModel model); + IllnessViewModel? Delete(IllnessBindingModel model); + } +} diff --git a/HospitalContracts/StoragesContracts/IKurseStorage.cs b/HospitalContracts/StoragesContracts/IKurseStorage.cs new file mode 100644 index 0000000..20e8536 --- /dev/null +++ b/HospitalContracts/StoragesContracts/IKurseStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface IKurseStorage + { + List GetFullList(); + List GetFilteredList(KurseSearchModel model); + KurseViewModel? GetElement(KurseSearchModel model); + KurseViewModel? Insert(KurseBindingModel model); + KurseViewModel? Update(KurseBindingModel model); + KurseViewModel? Delete(KurseBindingModel model); + } +} diff --git a/HospitalContracts/StoragesContracts/IMedicinesStorage.cs b/HospitalContracts/StoragesContracts/IMedicinesStorage.cs new file mode 100644 index 0000000..5be8325 --- /dev/null +++ b/HospitalContracts/StoragesContracts/IMedicinesStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface IMedicinesStorage + { + List GetFullList(); + List GetFilteredList(MedicinesSearchModel model); + MedicinesViewModel? GetElement(MedicinesSearchModel model); + MedicinesViewModel? Insert(MedicinesBindingModel model); + MedicinesViewModel? Update(MedicinesBindingModel model); + MedicinesViewModel? Delete(MedicinesBindingModel model); + } +} diff --git a/HospitalContracts/StoragesContracts/IProceduresStorage.cs b/HospitalContracts/StoragesContracts/IProceduresStorage.cs new file mode 100644 index 0000000..bece172 --- /dev/null +++ b/HospitalContracts/StoragesContracts/IProceduresStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface IProceduresStorage + { + List GetFullList(); + List GetFilteredList(ProceduresSearchModel model); + ProceduresViewModel? GetElement(ProceduresSearchModel model); + ProceduresViewModel? Insert(ProceduresBindingModel model); + ProceduresViewModel? Update(ProceduresBindingModel model); + ProceduresViewModel? Delete(ProceduresBindingModel model); + } +} diff --git a/HospitalContracts/StoragesContracts/IRecipesStorage.cs b/HospitalContracts/StoragesContracts/IRecipesStorage.cs new file mode 100644 index 0000000..193c089 --- /dev/null +++ b/HospitalContracts/StoragesContracts/IRecipesStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface IRecipesStorage + { + List GetFullList(); + List GetFilteredList(RecipesSearchModel model); + RecipesViewModel? GetElement(RecipesSearchModel model); + RecipesViewModel? Insert(RecipesBindingModel model); + RecipesViewModel? Update(RecipesBindingModel model); + RecipesViewModel? Delete(RecipesBindingModel model); + } +} diff --git a/HospitalContracts/StoragesContracts/ISymptomsStorage.cs b/HospitalContracts/StoragesContracts/ISymptomsStorage.cs new file mode 100644 index 0000000..180bba0 --- /dev/null +++ b/HospitalContracts/StoragesContracts/ISymptomsStorage.cs @@ -0,0 +1,21 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.StoragesContracts +{ + public interface ISymptomsStorage + { + List GetFullList(); + List GetFilteredList(SymptomsSearchModel model); + SymptomsViewModel? GetElement(SymptomsSearchModel model); + SymptomsViewModel? Insert(SymptomsBindingModel model); + SymptomsViewModel? Update(SymptomsBindingModel model); + SymptomsViewModel? Delete(SymptomsBindingModel model); + } +} diff --git a/HospitalContracts/ViewModels/IllnessViewModel.cs b/HospitalContracts/ViewModels/IllnessViewModel.cs index cdaa27a..574fa0b 100644 --- a/HospitalContracts/ViewModels/IllnessViewModel.cs +++ b/HospitalContracts/ViewModels/IllnessViewModel.cs @@ -1,12 +1,29 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class IllnessViewModel + public class IllnessViewModel: IIllnessModel { + public int Id { get; set; } + [DisplayName("Название болезни")] + public string IllnessName { get; set; } + [DisplayName("Форма болезни")] + public string Form { get; set; } + public Dictionary IllnessSymptoms + { + get; + set; + } = new(); + public Dictionary IllnessKurse + { + get; + set; + } = new(); } } diff --git a/HospitalContracts/ViewModels/KurseViewModel.cs b/HospitalContracts/ViewModels/KurseViewModel.cs index ee0ddda..3c4ab2d 100644 --- a/HospitalContracts/ViewModels/KurseViewModel.cs +++ b/HospitalContracts/ViewModels/KurseViewModel.cs @@ -1,12 +1,21 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class KurseViewModel + public class KurseViewModel: IKurseModel { + public int Id { get; set; } + [DisplayName("Продолжительность курса")] + public string Duration { get; set; } + [DisplayName("Срок приема")] + public int CountInDay { get; set; } + [DisplayName("Название лекарства")] + public int MedicinesId { get; } } } diff --git a/HospitalContracts/ViewModels/MedicinesViewModel.cs b/HospitalContracts/ViewModels/MedicinesViewModel.cs index b29320f..5c6f683 100644 --- a/HospitalContracts/ViewModels/MedicinesViewModel.cs +++ b/HospitalContracts/ViewModels/MedicinesViewModel.cs @@ -1,12 +1,19 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class MedicinesViewModel + public class MedicinesViewModel: IMedicinesModel { + public int Id { get; set; } + [DisplayName("Название лекарства")] + public string MedicinesName { get; set; } + [DisplayName("Группа")] + public string Group { get; set; } } } diff --git a/HospitalContracts/ViewModels/ProceduresViewModel.cs b/HospitalContracts/ViewModels/ProceduresViewModel.cs index 6714634..57813e1 100644 --- a/HospitalContracts/ViewModels/ProceduresViewModel.cs +++ b/HospitalContracts/ViewModels/ProceduresViewModel.cs @@ -1,12 +1,19 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class ProceduresViewModel + public class ProceduresViewModel: IProceduresModel { + public int Id { get; set; } + [DisplayName("Название процедуры")] + public string ProceduresName { get; set; } + [DisplayName("Тип процедуры")] + public string Type { get; set; } } } diff --git a/HospitalContracts/ViewModels/RecipesViewModel.cs b/HospitalContracts/ViewModels/RecipesViewModel.cs index 752e32b..62e6323 100644 --- a/HospitalContracts/ViewModels/RecipesViewModel.cs +++ b/HospitalContracts/ViewModels/RecipesViewModel.cs @@ -1,12 +1,31 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class RecipesViewModel + public class RecipesViewModel: IRecipesModel { + public int Id { get; set; } + [DisplayName("Доза")] + public string Dose { get; set; } + [DisplayName("Дата выписки")] + public DateTime Date { get; set; } + [DisplayName("Способ приготовления")] + public string ModeOfApplication { get; set; } + public Dictionary MedicinesRecipe + { + get; + set; + } = new(); + public Dictionary ProceduresRecipe + { + get; + set; + } = new(); } } diff --git a/HospitalContracts/ViewModels/SymptomsViewModel.cs b/HospitalContracts/ViewModels/SymptomsViewModel.cs index 3128441..096c32c 100644 --- a/HospitalContracts/ViewModels/SymptomsViewModel.cs +++ b/HospitalContracts/ViewModels/SymptomsViewModel.cs @@ -1,12 +1,19 @@ -using System; +using HospitalDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - internal class SymptomsViewModel + public class SymptomsViewModel: ISymptomsModel { + public int Id { get; set; } + [DisplayName("Симптом")] + public string SymptomName { get; set; } + [DisplayName("Описание")] + public string Description { get; set; } } } diff --git a/HospitalDataModels/Models/IMedicinesModel.cs b/HospitalDataModels/Models/IMedicinesModel.cs index 74a4f6b..0076a76 100644 --- a/HospitalDataModels/Models/IMedicinesModel.cs +++ b/HospitalDataModels/Models/IMedicinesModel.cs @@ -8,7 +8,7 @@ namespace HospitalDataModels.Models { public interface IMedicinesModel: IId { - string MedicineName { get; } + string MedicinesName { get; } string Group { get; } } } diff --git a/HospitalDataModels/Models/IProceduresModel.cs b/HospitalDataModels/Models/IProceduresModel.cs index b6c899a..4409fa5 100644 --- a/HospitalDataModels/Models/IProceduresModel.cs +++ b/HospitalDataModels/Models/IProceduresModel.cs @@ -8,7 +8,7 @@ namespace HospitalDataModels.Models { public interface IProceduresModel: IId { - string ProcedureName { get; } + string ProceduresName { get; } string Type { get; } } } diff --git a/HospitalView/Form1.cs b/HospitalView/Form1.cs deleted file mode 100644 index 11f284a..0000000 --- a/HospitalView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace HospitalView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/HospitalView/Form1.resx b/HospitalView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/HospitalView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/HospitalView/Form1.Designer.cs b/HospitalView/FormMain.Designer.cs similarity index 55% rename from HospitalView/Form1.Designer.cs rename to HospitalView/FormMain.Designer.cs index 7e73333..a40c51d 100644 --- a/HospitalView/Form1.Designer.cs +++ b/HospitalView/FormMain.Designer.cs @@ -1,14 +1,14 @@ namespace HospitalView { - partial class Form1 + partial class FormMain { /// - /// Required designer variable. + /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// - /// Clean up any resources being used. + /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) @@ -23,15 +23,22 @@ #region Windows Form Designer generated code /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.SuspendLayout(); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + this.ClientSize = new System.Drawing.Size(1047, 369); + this.Name = "FormMain"; + this.Text = "Поликлиника \"Будьте больны\""; + this.ResumeLayout(false); + } #endregion diff --git a/HospitalView/FormMain.cs b/HospitalView/FormMain.cs new file mode 100644 index 0000000..492e321 --- /dev/null +++ b/HospitalView/FormMain.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HospitalView +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + } +} diff --git a/HospitalView/FormMain.resx b/HospitalView/FormMain.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/HospitalView/FormMain.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/HospitalView/FormMedicine.Designer.cs b/HospitalView/FormMedicine.Designer.cs new file mode 100644 index 0000000..80a12aa --- /dev/null +++ b/HospitalView/FormMedicine.Designer.cs @@ -0,0 +1,119 @@ +namespace HospitalView +{ + partial class FormMedicine + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelNameMedicines = new System.Windows.Forms.Label(); + this.label = new System.Windows.Forms.Label(); + this.textBoxNameMedicine = new System.Windows.Forms.TextBox(); + this.textBoxGroup = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelNameMedicines + // + this.labelNameMedicines.AutoSize = true; + this.labelNameMedicines.Location = new System.Drawing.Point(32, 40); + this.labelNameMedicines.Name = "labelNameMedicines"; + this.labelNameMedicines.Size = new System.Drawing.Size(153, 20); + this.labelNameMedicines.TabIndex = 0; + this.labelNameMedicines.Text = "Название лекарства:"; + // + // label + // + this.label.AutoSize = true; + this.label.Location = new System.Drawing.Point(32, 96); + this.label.Name = "label"; + this.label.Size = new System.Drawing.Size(61, 20); + this.label.TabIndex = 1; + this.label.Text = "Группа:"; + // + // textBoxNameMedicine + // + this.textBoxNameMedicine.Location = new System.Drawing.Point(206, 37); + this.textBoxNameMedicine.Name = "textBoxNameMedicine"; + this.textBoxNameMedicine.Size = new System.Drawing.Size(211, 27); + this.textBoxNameMedicine.TabIndex = 2; + // + // textBoxGroup + // + this.textBoxGroup.Location = new System.Drawing.Point(206, 93); + this.textBoxGroup.Name = "textBoxGroup"; + this.textBoxGroup.Size = new System.Drawing.Size(211, 27); + this.textBoxGroup.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(181, 138); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(323, 138); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormMedicines + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 190); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxGroup); + this.Controls.Add(this.textBoxNameMedicine); + this.Controls.Add(this.label); + this.Controls.Add(this.labelNameMedicines); + this.Name = "FormMedicines"; + this.Text = "Лекарства"; + this.Load += new System.EventHandler(this.FormMedicines_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelNameMedicines; + private Label label; + private TextBox textBoxNameMedicine; + private TextBox textBoxGroup; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/HospitalView/FormMedicine.cs b/HospitalView/FormMedicine.cs new file mode 100644 index 0000000..d39ab34 --- /dev/null +++ b/HospitalView/FormMedicine.cs @@ -0,0 +1,95 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HospitalView +{ + public partial class FormMedicine : Form + { + private readonly ILogger _logger; + private readonly IMedicinesLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormMedicine(ILogger logger, IMedicinesLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormMedicines_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение лекарства"); + var view = _logic.ReadElement(new MedicinesSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxNameMedicine.Text = view.MedicinesName; + textBoxGroup.Text = view.Group; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения лекарства"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxNameMedicine.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение лекарства"); + try + { + var model = new MedicinesBindingModel + { + Id = _id ?? 0, + MedicinesName = textBoxNameMedicine.Text, + Group = textBoxGroup.Text + }; + var operationResult = _id.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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/HospitalView/FormMedicine.resx b/HospitalView/FormMedicine.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/HospitalView/FormMedicine.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/HospitalView/FormMedicines.Designer.cs b/HospitalView/FormMedicines.Designer.cs new file mode 100644 index 0000000..4919bed --- /dev/null +++ b/HospitalView/FormMedicines.Designer.cs @@ -0,0 +1,117 @@ +namespace HospitalView +{ + partial class FormMedicines + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.GridColor = System.Drawing.SystemColors.Control; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(393, 346); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(430, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(140, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(430, 124); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(140, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(430, 210); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(140, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(430, 302); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(140, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMedicines + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(582, 373); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormMedicines"; + this.Text = "Лекарства"; + this.Click += new System.EventHandler(this.FormMedicines_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/HospitalView/FormMedicines.cs b/HospitalView/FormMedicines.cs new file mode 100644 index 0000000..38804bd --- /dev/null +++ b/HospitalView/FormMedicines.cs @@ -0,0 +1,111 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HospitalView +{ + public partial class FormMedicines : Form + { + private readonly ILogger _logger; + private readonly IMedicinesLogic _logic; + public FormMedicines(ILogger logger, IMedicinesLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormMedicines_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["MedicinesName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка лекарств"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки лекарств"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMedicine)); + if (service is FormMedicines form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMedicine)); + if (service is FormMedicine form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 (!_logic.Delete(new MedicinesBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления лекарства"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/HospitalView/FormMedicines.resx b/HospitalView/FormMedicines.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/HospitalView/FormMedicines.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/HospitalView/FormProcedure.Designer.cs b/HospitalView/FormProcedure.Designer.cs new file mode 100644 index 0000000..8b1753b --- /dev/null +++ b/HospitalView/FormProcedure.Designer.cs @@ -0,0 +1,119 @@ +namespace HospitalView +{ + partial class FormProcedure + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelNameProcedure = new System.Windows.Forms.Label(); + this.labelTypeProcedure = new System.Windows.Forms.Label(); + this.textBoxNameProcedure = new System.Windows.Forms.TextBox(); + this.textBoxTypeProcedure = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelNameProcedure + // + this.labelNameProcedure.AutoSize = true; + this.labelNameProcedure.Location = new System.Drawing.Point(39, 28); + this.labelNameProcedure.Name = "labelNameProcedure"; + this.labelNameProcedure.Size = new System.Drawing.Size(163, 20); + this.labelNameProcedure.TabIndex = 0; + this.labelNameProcedure.Text = "Название процедуры:"; + // + // labelTypeProcedure + // + this.labelTypeProcedure.AutoSize = true; + this.labelTypeProcedure.Location = new System.Drawing.Point(39, 88); + this.labelTypeProcedure.Name = "labelTypeProcedure"; + this.labelTypeProcedure.Size = new System.Drawing.Size(121, 20); + this.labelTypeProcedure.TabIndex = 1; + this.labelTypeProcedure.Text = "Тип процедуры:"; + // + // textBoxNameProcedure + // + this.textBoxNameProcedure.Location = new System.Drawing.Point(229, 28); + this.textBoxNameProcedure.Name = "textBoxNameProcedure"; + this.textBoxNameProcedure.Size = new System.Drawing.Size(241, 27); + this.textBoxNameProcedure.TabIndex = 2; + // + // textBoxTypeProcedure + // + this.textBoxTypeProcedure.Location = new System.Drawing.Point(229, 88); + this.textBoxTypeProcedure.Name = "textBoxTypeProcedure"; + this.textBoxTypeProcedure.Size = new System.Drawing.Size(241, 27); + this.textBoxTypeProcedure.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(248, 129); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(376, 129); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormProcedure + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(495, 171); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxTypeProcedure); + this.Controls.Add(this.textBoxNameProcedure); + this.Controls.Add(this.labelTypeProcedure); + this.Controls.Add(this.labelNameProcedure); + this.Name = "FormProcedure"; + this.Text = "Процедура"; + this.Load += new System.EventHandler(this.FormProcedures_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelNameProcedure; + private Label labelTypeProcedure; + private TextBox textBoxNameProcedure; + private TextBox textBoxTypeProcedure; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/HospitalView/FormProcedure.cs b/HospitalView/FormProcedure.cs new file mode 100644 index 0000000..dfc9f60 --- /dev/null +++ b/HospitalView/FormProcedure.cs @@ -0,0 +1,94 @@ +using HospitalContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using HospitalContracts.SearchModels; +using HospitalContracts.BindingModels; + +namespace HospitalView +{ + public partial class FormProcedure : Form + { + private readonly ILogger _logger; + private readonly IProceduresLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormProcedure(ILogger logger, IProceduresLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormProcedures_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение процедуры"); + var view = _logic.ReadElement(new ProceduresSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxNameProcedure.Text = view.ProceduresName; + textBoxTypeProcedure.Text = view.Type; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxNameProcedure.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение процедуры"); + try + { + var model = new ProceduresBindingModel + { + Id = _id ?? 0, + ProceduresName = textBoxNameProcedure.Text, + Type = textBoxTypeProcedure.Text + }; + var operationResult = _id.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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/HospitalView/FormProcedure.resx b/HospitalView/FormProcedure.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/HospitalView/FormProcedure.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/HospitalView/FormProcedures.Designer.cs b/HospitalView/FormProcedures.Designer.cs new file mode 100644 index 0000000..11c6af8 --- /dev/null +++ b/HospitalView/FormProcedures.Designer.cs @@ -0,0 +1,116 @@ +namespace HospitalView +{ + partial class FormProcedures + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(393, 346); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(430, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(140, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(430, 124); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(140, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(430, 210); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(140, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(430, 302); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(140, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormProcedures + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(582, 373); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormProcedures"; + this.Text = "Процедуры"; + this.Load += new System.EventHandler(this.FormProcedures_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/HospitalView/FormProcedures.cs b/HospitalView/FormProcedures.cs new file mode 100644 index 0000000..03fc41c --- /dev/null +++ b/HospitalView/FormProcedures.cs @@ -0,0 +1,114 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HospitalView +{ + public partial class FormProcedures : Form + { + private readonly ILogger _logger; + private readonly IProceduresLogic _logic; + public FormProcedures(ILogger logger, IProceduresLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormProcedures_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ProcedureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка процедур"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки процедур"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProcedure)); + if (service is FormProcedure form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormProcedure)); + if (service is FormProcedure form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 (!_logic.Delete(new ProceduresBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления процедуры"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/HospitalView/FormProcedures.resx b/HospitalView/FormProcedures.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/HospitalView/FormProcedures.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/HospitalView/HospitalView.csproj b/HospitalView/HospitalView.csproj index b57c89e..39d414c 100644 --- a/HospitalView/HospitalView.csproj +++ b/HospitalView/HospitalView.csproj @@ -8,4 +8,13 @@ enable + + + + + + + + + \ No newline at end of file