From 889ff362ce5c7e4c585e254e9e132d26e731ee71 Mon Sep 17 00:00:00 2001 From: sardq Date: Sat, 23 Mar 2024 11:06:35 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlumbingRepair/PlumbingRepair.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 115 ++++++++ .../BusinessLogics/OrderLogic.cs | 129 +++++++++ .../BusinessLogics/WorkLogic.cs | 112 ++++++++ .../PlumbingRepairBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 13 + .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/WorkBindingModel.cs | 15 + .../IComponentLogic.cs | 19 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 19 ++ .../BusinessLogicsContracts/IWorkLogic.cs | 19 ++ .../PlumbingRepairContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/WorkSearchModel.cs | 9 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IWorkStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 16 ++ .../ViewModels/OrderViewModel.cs | 31 +++ .../ViewModels/WorkViewModel.cs | 18 ++ .../Enums/OrderStatus.cs | 15 + .../PlumbingRepairDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 9 + .../Models/IOrderModel.cs | 18 ++ .../Models/IWorkModel.cs | 11 + .../PlumbingRepairDataModels.csproj | 9 + .../DataListSingleton.cs | 32 +++ .../Implements/ComponentStorage.cs | 108 ++++++++ .../Implements/OrderStorage.cs | 113 ++++++++ .../Implements/WorkStorage.cs | 106 ++++++++ .../Models/Component.cs | 46 ++++ .../Models/Order.cs | 64 +++++ .../Models/Work.cs | 51 ++++ .../PlumbingRepairListImplement.csproj | 14 + .../PlumbingRepairView/Form1.Designer.cs | 39 --- PlumbingRepair/PlumbingRepairView/Form1.cs | 10 - PlumbingRepair/PlumbingRepairView/Form1.resx | 120 -------- .../FormComponent.Designer.cs | 125 +++++++++ .../PlumbingRepairView/FormComponent.cs | 85 ++++++ .../PlumbingRepairView/FormComponent.resx | 60 ++++ .../FormComponents.Designer.cs | 127 +++++++++ .../PlumbingRepairView/FormComponents.cs | 103 +++++++ .../PlumbingRepairView/FormComponents.resx | 60 ++++ .../FormCreateOrder.Designer.cs | 154 +++++++++++ .../PlumbingRepairView/FormCreateOrder.cs | 119 ++++++++ .../PlumbingRepairView/FormCreateOrder.resx | 60 ++++ .../PlumbingRepairView/FormMain.Designer.cs | 196 ++++++++++++++ PlumbingRepair/PlumbingRepairView/FormMain.cs | 148 ++++++++++ .../PlumbingRepairView/FormMain.resx | 63 +++++ .../PlumbingRepairView/FormWork.Designer.cs | 256 ++++++++++++++++++ PlumbingRepair/PlumbingRepairView/FormWork.cs | 208 ++++++++++++++ .../PlumbingRepairView/FormWork.resx | 60 ++++ .../FormWorkComponent.Designer.cs | 126 +++++++++ .../PlumbingRepairView/FormWorkComponent.cs | 71 +++++ .../PlumbingRepairView/FormWorkComponent.resx | 60 ++++ .../PlumbingRepairView/FormWorks.Designer.cs | 127 +++++++++ .../PlumbingRepairView/FormWorks.cs | 105 +++++++ .../PlumbingRepairView/FormWorks.resx | 60 ++++ .../PlumbingRepairView.csproj | 9 + PlumbingRepair/PlumbingRepairView/Program.cs | 40 ++- PlumbingRepair/PlumbingRepairView/nlog.config | 14 + 62 files changed, 3709 insertions(+), 171 deletions(-) create mode 100644 PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj create mode 100644 PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj create mode 100644 PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/IId.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs create mode 100644 PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj create mode 100644 PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj delete mode 100644 PlumbingRepair/PlumbingRepairView/Form1.Designer.cs delete mode 100644 PlumbingRepair/PlumbingRepairView/Form1.cs delete mode 100644 PlumbingRepair/PlumbingRepairView/Form1.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponent.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponent.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponent.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponents.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponents.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormComponents.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormCreateOrder.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormCreateOrder.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormCreateOrder.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormMain.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormMain.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormWork.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWork.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWork.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorkComponent.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorkComponent.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorkComponent.resx create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorks.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorks.cs create mode 100644 PlumbingRepair/PlumbingRepairView/FormWorks.resx create mode 100644 PlumbingRepair/PlumbingRepairView/nlog.config diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index af84c6e..9fef091 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33110.190 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairView", "PlumbingRepairView\PlumbingRepairView.csproj", "{C267FC29-91DC-4543-9EF8-678A3A5556E7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairView", "PlumbingRepairView\PlumbingRepairView.csproj", "{C267FC29-91DC-4543-9EF8-678A3A5556E7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairBusinessLogic", "PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj", "{7C2FE920-E8CA-4F50-9EEC-B6EDBAE47480}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairContracts", "PlumbingRepairContracts\PlumbingRepairContracts.csproj", "{9D62913E-8AC0-48E6-B131-B7E744E4B48A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDataModels", "PlumbingRepairDataModels\PlumbingRepairDataModels.csproj", "{1889C02D-BF89-47E5-BF8B-897DBFF8D726}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{A5D22B59-19BC-4DB6-A234-24AEA47605C2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {C267FC29-91DC-4543-9EF8-678A3A5556E7}.Debug|Any CPU.Build.0 = Debug|Any CPU {C267FC29-91DC-4543-9EF8-678A3A5556E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {C267FC29-91DC-4543-9EF8-678A3A5556E7}.Release|Any CPU.Build.0 = Release|Any CPU + {7C2FE920-E8CA-4F50-9EEC-B6EDBAE47480}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C2FE920-E8CA-4F50-9EEC-B6EDBAE47480}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C2FE920-E8CA-4F50-9EEC-B6EDBAE47480}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C2FE920-E8CA-4F50-9EEC-B6EDBAE47480}.Release|Any CPU.Build.0 = Release|Any CPU + {9D62913E-8AC0-48E6-B131-B7E744E4B48A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D62913E-8AC0-48E6-B131-B7E744E4B48A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D62913E-8AC0-48E6-B131-B7E744E4B48A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D62913E-8AC0-48E6-B131-B7E744E4B48A}.Release|Any CPU.Build.0 = Release|Any CPU + {1889C02D-BF89-47E5-BF8B-897DBFF8D726}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1889C02D-BF89-47E5-BF8B-897DBFF8D726}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1889C02D-BF89-47E5-BF8B-897DBFF8D726}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1889C02D-BF89-47E5-BF8B-897DBFF8D726}.Release|Any CPU.Build.0 = Release|Any CPU + {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5D22B59-19BC-4DB6-A234-24AEA47605C2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..029acac --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,115 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.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(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..5e0ba7e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,129 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairDataModels.Enums; +using Microsoft.Extensions.Logging; + + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + model.Status = newStatus; + model.WorkId = viewModel.WorkId; + model.Count = viewModel.Count; + model.Sum = viewModel.Sum; + model.DateCreate = viewModel.DateCreate; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.WorkId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор работы", nameof(model.WorkId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество работ в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}. WorkId: {WorkId}", model.Id, model.Sum, model.WorkId); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs new file mode 100644 index 0000000..18fae72 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs @@ -0,0 +1,112 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class WorkLogic : IWorkLogic + { + private readonly ILogger _logger; + + private readonly IWorkStorage _workStorage; + public WorkLogic(ILogger logger, IWorkStorage workStorage) + { + _logger = logger; + _workStorage = workStorage; + } + public bool Create(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(WorkBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_workStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public WorkViewModel? ReadElement(WorkSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. WorkName:{WorkName}. Id:{Id}", model.WorkName, model.Id); + var element = _workStorage.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(WorkSearchModel? model) + { + _logger.LogInformation("ReadList. WorkName:{WorkName}. Id:{Id}", model?.WorkName, model?.Id); + var list = model == null ? _workStorage.GetFullList() : _workStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(WorkBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.WorkName)) + { + throw new ArgumentNullException("Нет названия работы", nameof(model.WorkName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Стоимость работы должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Component. WorkName:{WorkName}. Price:{Price}. Id:{Id}", model.WorkName, model.Price, model.Id); + var element = _workStorage.GetElement(new WorkSearchModel + { + WorkName = model.WorkName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Работа с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj new file mode 100644 index 0000000..cc1bb73 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..88d3f1f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,13 @@ +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + + public string ComponentName { get; set; } = string.Empty; + + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..098d7b9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + + public int WorkId { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs new file mode 100644 index 0000000..3f1edd1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs @@ -0,0 +1,15 @@ +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class WorkBindingModel : IWorkModel + { + public int Id { get; set; } + + public string WorkName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary WorkComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..3888de2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,19 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + + ComponentViewModel? ReadElement(ComponentSearchModel model); + + bool Create(ComponentBindingModel model); + + bool Update(ComponentBindingModel model); + + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..3588a21 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,19 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + + bool CreateOrder(OrderBindingModel model); + + bool TakeOrderInWork(OrderBindingModel model); + + bool FinishOrder(OrderBindingModel model); + + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs new file mode 100644 index 0000000..8f6aa05 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs @@ -0,0 +1,19 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IWorkLogic + { + List? ReadList(WorkSearchModel? model); + + WorkViewModel? ReadElement(WorkSearchModel model); + + bool Create(WorkBindingModel model); + + bool Update(WorkBindingModel model); + + bool Delete(WorkBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj new file mode 100644 index 0000000..5c96a30 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..229ccc9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..e3d3743 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs new file mode 100644 index 0000000..890cbd7 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs @@ -0,0 +1,9 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class WorkSearchModel + { + public int? Id { get; set; } + + public string? WorkName { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..2b33444 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + + List GetFilteredList(ComponentSearchModel model); + + ComponentViewModel? GetElement(ComponentSearchModel model); + + ComponentViewModel? Insert(ComponentBindingModel model); + + ComponentViewModel? Update(ComponentBindingModel model); + + ComponentViewModel? Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..e4bda41 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + + List GetFilteredList(OrderSearchModel model); + + OrderViewModel? GetElement(OrderSearchModel model); + + OrderViewModel? Insert(OrderBindingModel model); + + OrderViewModel? Update(OrderBindingModel model); + + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs new file mode 100644 index 0000000..958fdde --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IWorkStorage + { + List GetFullList(); + + List GetFilteredList(WorkSearchModel model); + + WorkViewModel? GetElement(WorkSearchModel model); + + WorkViewModel? Insert(WorkBindingModel model); + + WorkViewModel? Update(WorkBindingModel model); + + WorkViewModel? Delete(WorkBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..d01ac75 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,16 @@ +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..beb6a1d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,31 @@ +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int WorkId { get; set; } + + [DisplayName("Работа")] + public string WorkName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs new file mode 100644 index 0000000..f367de5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs @@ -0,0 +1,18 @@ +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class WorkViewModel : IWorkModel + { + public int Id { get; set; } + + [DisplayName("Название работ")] + public string WorkName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + [DisplayName("Компоненты")] + public Dictionary WorkComponents { get; set; } = new(); + } +} diff --git a/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..8b72a9c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs @@ -0,0 +1,15 @@ +namespace PlumbingRepairDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/IId.cs b/PlumbingRepair/PlumbingRepairDataModels/IId.cs new file mode 100644 index 0000000..bb2cdbd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..6aa8d5a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs @@ -0,0 +1,9 @@ +namespace PlumbingRepairDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..c7b50f2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs @@ -0,0 +1,18 @@ +using PlumbingRepairDataModels.Enums; +namespace PlumbingRepairDataModels.Models +{ + public interface IOrderModel : IId + { + int WorkId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs new file mode 100644 index 0000000..5f6ad8e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs @@ -0,0 +1,11 @@ +namespace PlumbingRepairDataModels.Models +{ + public interface IWorkModel : IId + { + string WorkName { get; } + + double Price { get; } + + Dictionary WorkComponents { get; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj b/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs new file mode 100644 index 0000000..556458d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + + public List Components { get; set; } + + public List Orders { get; set; } + + public List Works { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Works = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e422f26 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..ffc5ccd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs @@ -0,0 +1,113 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AttachWorkName(element.GetViewModel); + } + } + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if ( !model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ( model.Id.HasValue && order.Id == model.Id) + { + return AttachWorkName(order.GetViewModel); + } + } + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachWorkName(order.GetViewModel)); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AttachWorkName(order.GetViewModel)); + } + return result; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AttachWorkName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachWorkName(order.GetViewModel); + } + } + return null; + } + private OrderViewModel AttachWorkName(OrderViewModel model) + { + var work = _source.Works.Find(b => b.Id == model.WorkId); + model.WorkName = work is null ? String.Empty : work.WorkName; + + return model; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs new file mode 100644 index 0000000..b919e38 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs @@ -0,0 +1,106 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class WorkStorage : IWorkStorage + { + private readonly DataListSingleton _source; + + public WorkStorage() + { + _source = DataListSingleton.GetInstance(); + } + public WorkViewModel? Delete(WorkBindingModel model) + { + for (int i = 0; i < _source.Works.Count; ++i) + { + if (_source.Works[i].Id == model.Id) + { + var element = _source.Works[i]; + _source.Works.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public WorkViewModel? GetElement(WorkSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) + { + return null; + } + foreach (var work in _source.Works) + { + if ((!string.IsNullOrEmpty(model.WorkName) && work.WorkName == model.WorkName) || (model.Id.HasValue && work.Id == model.Id)) + { + return work.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(WorkSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.WorkName)) + { + return result; + } + foreach (var work in _source.Works) + { + if (work.WorkName.Contains(model.WorkName)) + { + result.Add(work.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var work in _source.Works) + { + result.Add(work.GetViewModel); + } + return result; + } + + public WorkViewModel? Insert(WorkBindingModel model) + { + model.Id = 1; + foreach (var work in _source.Works) + { + if (model.Id <= work.Id) + { + model.Id = work.Id + 1; + } + } + var newWork = Work.Create(model); + if (newWork == null) + { + return null; + } + _source.Works.Add(newWork); + return newWork.GetViewModel; + } + + public WorkViewModel? Update(WorkBindingModel model) + { + foreach (var work in _source.Works) + { + if (work.Id == model.Id) + { + work.Update(model); + return work.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs new file mode 100644 index 0000000..0e39dd5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + + public string ComponentName { get; private set; } = string.Empty; + + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs new file mode 100644 index 0000000..91e182b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs @@ -0,0 +1,64 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + internal class Order : IOrderModel + { + public int WorkId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WorkId = model.WorkId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement= model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + WorkId = WorkId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs new file mode 100644 index 0000000..c2f717a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs @@ -0,0 +1,51 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + internal class Work : IWorkModel + { + public int Id { get; private set; } + + public string WorkName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary WorkComponents { get; private set; } = new Dictionary(); + + public static Work? Create(WorkBindingModel? model) + { + if (model == null) + { + return null; + } + return new Work() + { + Id = model.Id, + WorkName = model.WorkName, + Price = model.Price, + WorkComponents = model.WorkComponents + }; + } + + public void Update(WorkBindingModel? model) + { + if (model == null) + { + return; + } + WorkName = model.WorkName; + Price = model.Price; + WorkComponents = model.WorkComponents; + } + + public WorkViewModel GetViewModel => new() + { + Id = Id, + WorkName = WorkName, + Price = Price, + WorkComponents = WorkComponents + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj new file mode 100644 index 0000000..05f8377 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairView/Form1.Designer.cs b/PlumbingRepair/PlumbingRepairView/Form1.Designer.cs deleted file mode 100644 index 00cca42..0000000 --- a/PlumbingRepair/PlumbingRepairView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PlumbingRepairView -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/Form1.cs b/PlumbingRepair/PlumbingRepairView/Form1.cs deleted file mode 100644 index 93e900a..0000000 --- a/PlumbingRepair/PlumbingRepairView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PlumbingRepairView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/Form1.resx b/PlumbingRepair/PlumbingRepairView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/PlumbingRepair/PlumbingRepairView/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/PlumbingRepair/PlumbingRepairView/FormComponent.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormComponent.Designer.cs new file mode 100644 index 0000000..61ef604 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponent.Designer.cs @@ -0,0 +1,125 @@ +namespace PlumbingRepairView +{ + partial class FormComponent + { + /// + /// 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.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(135, 68); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(183, 31); + this.textBoxCost.TabIndex = 9; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(25, 73); + this.labelCost.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(57, 25); + this.labelCost.TabIndex = 8; + this.labelCost.Text = "Цена:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(372, 126); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(236, 126); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(135, 20); + this.textBoxName.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(358, 31); + this.textBoxName.TabIndex = 7; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(25, 25); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 6; + this.labelName.Text = "Название:"; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(512, 195); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxCost; + private Label labelCost; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxName; + private Label labelName; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormComponent.cs b/PlumbingRepair/PlumbingRepairView/FormComponent.cs new file mode 100644 index 0000000..107b6bc --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponent.cs @@ -0,0 +1,85 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormComponent.resx b/PlumbingRepair/PlumbingRepairView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponent.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/PlumbingRepair/PlumbingRepairView/FormComponents.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormComponents.Designer.cs new file mode 100644 index 0000000..c8bf352 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponents.Designer.cs @@ -0,0 +1,127 @@ +namespace PlumbingRepairView +{ + partial class FormComponents + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(646, 254); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(646, 175); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(646, 96); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(646, 23); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(583, 650); + this.dataGridView.TabIndex = 5; + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 650); + 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 = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormComponents.cs b/PlumbingRepair/PlumbingRepairView/FormComponents.cs new file mode 100644 index 0000000..78b92a7 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponents.cs @@ -0,0 +1,103 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_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["ComponentName"].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(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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 ComponentBindingModel { 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormComponents.resx b/PlumbingRepair/PlumbingRepairView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormComponents.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/PlumbingRepair/PlumbingRepairView/FormCreateOrder.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..2cb8baa --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.Designer.cs @@ -0,0 +1,154 @@ +namespace PlumbingRepairView +{ + partial class FormCreateOrder + { + /// + /// 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.labelSum = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxWork = new System.Windows.Forms.ComboBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelWork = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(9, 122); + this.labelSum.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(71, 25); + this.labelSum.TabIndex = 12; + this.labelSum.Text = "Сумма:"; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(134, 116); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(359, 31); + this.textBoxSum.TabIndex = 13; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(9, 72); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(111, 25); + this.labelCount.TabIndex = 10; + this.labelCount.Text = "Количество:"; + // + // comboBoxWork + // + this.comboBoxWork.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxWork.FormattingEnabled = true; + this.comboBoxWork.Location = new System.Drawing.Point(134, 15); + this.comboBoxWork.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxWork.Name = "comboBoxWork"; + this.comboBoxWork.Size = new System.Drawing.Size(359, 33); + this.comboBoxWork.TabIndex = 9; + this.comboBoxWork.SelectedIndexChanged += new System.EventHandler(this.ComboBoxWork_SelectedIndexChanged); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(354, 166); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(125, 44); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(219, 166); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(125, 44); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(134, 66); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(359, 31); + this.textBoxCount.TabIndex = 11; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelWork + // + this.labelWork.AutoSize = true; + this.labelWork.Location = new System.Drawing.Point(9, 20); + this.labelWork.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelWork.Name = "labelWork"; + this.labelWork.Size = new System.Drawing.Size(72, 25); + this.labelWork.TabIndex = 8; + this.labelWork.Text = "Работа:"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(534, 228); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxWork); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelWork); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelSum; + private TextBox textBoxSum; + private Label labelCount; + private ComboBox comboBoxWork; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelWork; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormCreateOrder.cs b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.cs new file mode 100644 index 0000000..9eb8bf8 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.cs @@ -0,0 +1,119 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace PlumbingRepairView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IWorkLogic _logicW; + + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IWorkLogic logicW, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicW; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWork.DataSource = list; + comboBoxWork.DisplayMember = "WorkName"; + comboBoxWork.ValueMember = "Id"; + comboBoxWork.SelectedItem= null; + } + _logger.LogInformation("Загрузка работ"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки работ"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void CalcSum() + { + if (comboBoxWork.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxWork.SelectedValue); + var work = _logicW.ReadElement(new WorkSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (work?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxWork_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxWork.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + WorkId = Convert.ToInt32(comboBoxWork.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormCreateOrder.resx b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormCreateOrder.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/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs new file mode 100644 index 0000000..39e09b3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs @@ -0,0 +1,196 @@ +namespace PlumbingRepairView +{ + partial class FormMain + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.РаботыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(1113, 373); + this.buttonRef.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(249, 45); + this.buttonRef.TabIndex = 11; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1113, 297); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45); + this.buttonIssuedOrder.TabIndex = 10; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOrderReady.Location = new System.Drawing.Point(1113, 225); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(249, 45); + this.buttonOrderReady.TabIndex = 9; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1113, 158); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(249, 45); + this.buttonTakeOrderInWork.TabIndex = 8; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCreateOrder.Location = new System.Drawing.Point(1113, 83); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45); + this.buttonCreateOrder.TabIndex = 7; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(2, 44); + this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(1055, 533); + this.dataGridView.TabIndex = 6; + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1377, 33); + this.menuStrip1.TabIndex = 12; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.РаботыToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // РаботыToolStripMenuItem + // + this.РаботыToolStripMenuItem.Name = "РаботыToolStripMenuItem"; + this.РаботыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.РаботыToolStripMenuItem.Text = "Работы"; + this.РаботыToolStripMenuItem.Click += new System.EventHandler(this.РаботыToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1377, 602); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Ремонт труб"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonRef; + private Button buttonIssuedOrder; + private Button buttonOrderReady; + private Button buttonTakeOrderInWork; + private Button buttonCreateOrder; + private DataGridView dataGridView; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem РаботыToolStripMenuItem; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormMain.cs b/PlumbingRepair/PlumbingRepairView/FormMain.cs new file mode 100644 index 0000000..e1e6e98 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormMain.cs @@ -0,0 +1,148 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; + +namespace PlumbingRepairView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["WorkId"].Visible= false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void РаботыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); + if (service is FormWorks form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormMain.resx b/PlumbingRepair/PlumbingRepairView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWork.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormWork.Designer.cs new file mode 100644 index 0000000..4c718f0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWork.Designer.cs @@ -0,0 +1,256 @@ +namespace PlumbingRepairView +{ + partial class FormWork + { + /// + /// 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.textBoxPrice = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(126, 64); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(208, 31); + this.textBoxPrice.TabIndex = 10; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(15, 69); + this.labelPrice.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(103, 25); + this.labelPrice.TabIndex = 9; + this.labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(126, 14); + this.textBoxName.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(358, 31); + this.textBoxName.TabIndex = 8; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(15, 19); + this.labelName.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 7; + this.labelName.Text = "Название:"; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(630, 53); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 45); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(15, 114); + this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.groupBoxComponents.Size = new System.Drawing.Size(797, 480); + this.groupBoxComponents.TabIndex = 11; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(630, 285); + this.buttonRef.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 45); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(630, 205); + this.buttonDel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 45); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(630, 127); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 45); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(6, 29); + this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(583, 446); + this.dataGridView.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 8; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Visible = false; + this.ColumnId.Width = 150; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnName.HeaderText = "Компонент"; + this.ColumnName.MinimumWidth = 8; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 8; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + this.ColumnCount.Width = 150; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(645, 605); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(509, 605); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormWork + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 656); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormWork"; + this.Text = "Работа"; + this.Load += new System.EventHandler(this.FormWork_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPrice; + private Label labelPrice; + private TextBox textBoxName; + private Label labelName; + private Button buttonAdd; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWork.cs b/PlumbingRepair/PlumbingRepairView/FormWork.cs new file mode 100644 index 0000000..dc16495 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWork.cs @@ -0,0 +1,208 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairView +{ + public partial class FormWork : Form + { + private readonly ILogger _logger; + + private readonly IWorkLogic _logic; + + private int? _id; + + private Dictionary _workComponents; + + public int Id { set { _id = value; } } + + public FormWork(ILogger logger, IWorkLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _workComponents = new Dictionary(); + } + + private void FormWork_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new WorkSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.WorkName; + textBoxPrice.Text = view.Price.ToString(); + _workComponents = view.WorkComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_workComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _workComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + 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(FormWorkComponent)); + if (service is FormWorkComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_workComponents.ContainsKey(form.Id)) + { + _workComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _workComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); + if (service is FormWorkComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _workComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _workComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _workComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_workComponents == null || _workComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new WorkBindingModel + { + Id = _id ?? 0, + WorkName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + WorkComponents = _workComponents + }; + 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(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _workComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWork.resx b/PlumbingRepair/PlumbingRepairView/FormWork.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWork.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/PlumbingRepair/PlumbingRepairView/FormWorkComponent.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.Designer.cs new file mode 100644 index 0000000..a39f7f9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace PlumbingRepairView +{ + partial class FormWorkComponent + { + /// + /// 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.labelCount = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelComponent = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(4, 91); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(111, 25); + this.labelCount.TabIndex = 8; + this.labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(129, 34); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(359, 33); + this.comboBoxComponent.TabIndex = 7; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(347, 135); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(125, 44); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(212, 135); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(125, 44); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(129, 85); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(359, 31); + this.textBoxCount.TabIndex = 9; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(4, 39); + this.labelComponent.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(107, 25); + this.labelComponent.TabIndex = 6; + this.labelComponent.Text = "Компонент:"; + // + // FormWorkComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(513, 210); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelComponent); + this.Name = "FormWorkComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelCount; + private ComboBox comboBoxComponent; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelComponent; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWorkComponent.cs b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.cs new file mode 100644 index 0000000..1bd768d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.cs @@ -0,0 +1,71 @@ +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairView +{ + public partial class FormWorkComponent : Form + { + private readonly List? _list; + + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + + public FormWorkComponent(IComponentLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWorkComponent.resx b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorkComponent.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/PlumbingRepair/PlumbingRepairView/FormWorks.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormWorks.Designer.cs new file mode 100644 index 0000000..b2cbeec --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorks.Designer.cs @@ -0,0 +1,127 @@ +namespace PlumbingRepairView +{ + partial class FormWorks + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(804, 252); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(804, 173); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(804, 94); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(804, 21); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(767, 450); + this.dataGridView.TabIndex = 10; + // + // FormWorks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(943, 450); + 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 = "FormWorks"; + this.Text = "Работы"; + this.Load += new System.EventHandler(this.FormWorks_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWorks.cs b/PlumbingRepair/PlumbingRepairView/FormWorks.cs new file mode 100644 index 0000000..cdb76cc --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorks.cs @@ -0,0 +1,105 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairView +{ + public partial class FormWorks : Form + { + private readonly ILogger _logger; + + private readonly IWorkLogic _logic; + + public FormWorks(ILogger logger, IWorkLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormWorks_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["WorkComponents"].Visible = false; + dataGridView.Columns["WorkName"].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(FormWork)); + if (service is FormWork 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(FormWork)); + if (service is FormWork 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 WorkBindingModel { 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormWorks.resx b/PlumbingRepair/PlumbingRepairView/FormWorks.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormWorks.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/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj index b57c89e..ee2e00f 100644 --- a/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj +++ b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj @@ -8,4 +8,13 @@ enable + + + + + + + + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs index 8733ddc..03a1750 100644 --- a/PlumbingRepair/PlumbingRepairView/Program.cs +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -1,7 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PlumbingRepairBusinessLogic.BusinessLogics; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairListImplement.Implements; + namespace PlumbingRepairView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +22,34 @@ namespace PlumbingRepairView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/nlog.config b/PlumbingRepair/PlumbingRepairView/nlog.config new file mode 100644 index 0000000..76ffd67 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file