From c4dc8cbec65b999f1eca1247f348853eff6481ce Mon Sep 17 00:00:00 2001 From: Nastya_Kozlova Date: Tue, 5 Mar 2024 22:19:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/PrecastConcretePlant.sln | 24 ++ .../BusinessLogics/ComponentLogic.cs | 118 +++++++++ .../BusinessLogics/OrderLogic.cs | 135 ++++++++++ .../BusinessLogics/ReinforcedLogic.cs | 124 +++++++++ .../PrecastConcretePlantBusinessLogic.csproj | 18 ++ .../BindingModels/ComponentBindingModel.cs | 19 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/ReinforcedBindingModel.cs | 22 ++ .../IComponentLogic.cs | 21 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 21 ++ .../IReinforcedLogic.cs | 20 ++ .../PrecastConcretePlantContracts.csproj | 14 ++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/ReinforcedSearchModel.cs | 15 ++ .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IReinforcedStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../ViewModels/ReinforcedViewModel.cs | 25 ++ .../Enums/OrderStatus.cs | 21 ++ .../PrecastConcretePlantDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 14 ++ .../Models/IOrderModel.cs | 19 ++ .../Models/IReinforcedModel.cs | 15 ++ .../PrecastConcretePlantDataModels.csproj | 10 + .../DataListSingleton.cs | 26 ++ .../Implements/ComponentStorage.cs | 102 ++++++++ .../Implements/OrderStorage.cs | 122 +++++++++ .../Implements/ReinforcedStorage.cs | 109 ++++++++ .../Models/Component.cs | 46 ++++ .../Models/Order.cs | 64 +++++ .../Models/Reinforced.cs | 54 ++++ .../PrecastConcretePlantListImplement.csproj | 15 ++ .../Form1.Designer.cs | 39 --- .../PrecastConcretePlantView/Form1.cs | 10 - .../FormComponent.Designer.cs | 119 +++++++++ .../PrecastConcretePlantView/FormComponent.cs | 82 ++++++ .../{Form1.resx => FormComponent.resx} | 50 ++-- .../FormComponents.Designer.cs | 123 +++++++++ .../FormComponents.cs | 110 ++++++++ .../FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 145 +++++++++++ .../FormCreateOrder.cs | 131 ++++++++++ .../FormCreateOrder.resx | 120 +++++++++ .../FormMain.Designer.cs | 181 +++++++++++++ .../PrecastConcretePlantView/FormMain.cs | 156 ++++++++++++ .../PrecastConcretePlantView/FormMain.resx | 126 ++++++++++ .../FormReinforced.Designer.cs | 237 ++++++++++++++++++ .../FormReinforced.cs | 216 ++++++++++++++++ .../FormReinforced.resx | 138 ++++++++++ .../FormReinforcedComponent.Designer.cs | 120 +++++++++ .../FormReinforcedComponent.cs | 77 ++++++ .../FormReinforcedComponent.resx | 120 +++++++++ .../FormReinforceds.Designer.cs | 123 +++++++++ .../FormReinforceds.cs | 111 ++++++++ .../FormReinforceds.resx | 120 +++++++++ .../PrecastConcretePlantView.csproj | 12 + .../PrecastConcretePlantView/Program.cs | 39 ++- .../PrecastConcretePlantView/nlog.config | 15 ++ 61 files changed, 4134 insertions(+), 75 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/PrecastConcretePlantBusinessLogic.csproj create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ReinforcedBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReinforcedLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ComponentSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ReinforcedSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IComponentStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IOrderStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IReinforcedStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Enums/OrderStatus.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/IId.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IComponentModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IReinforcedModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/PrecastConcretePlantDataModels.csproj create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ComponentStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Component.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Reinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/Form1.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs rename PrecastConcretePlant/PrecastConcretePlantView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/nlog.config diff --git a/PrecastConcretePlant/PrecastConcretePlant.sln b/PrecastConcretePlant/PrecastConcretePlant.sln index 0dec718..7be2235 100644 --- a/PrecastConcretePlant/PrecastConcretePlant.sln +++ b/PrecastConcretePlant/PrecastConcretePlant.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.9.34616.47 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantView", "PrecastConcretePlantView\PrecastConcretePlantView.csproj", "{5A2F146C-8B8A-43F2-BEA0-D4C40BE8C91D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantDataModels", "PrecastConcretePlantDataModels\PrecastConcretePlantDataModels.csproj", "{8A44C6B3-1B4C-420A-8BEC-253C429C2C5E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantContracts", "PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj", "{BAF50D85-3072-4FD3-93DB-24BD1A1E570F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantBusinessLogic", "PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj", "{00DDE5FD-7B4B-481B-BA35-64BB7C6DC20A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{408C3C58-DFEA-45C0-ABF2-7F4435D3E16A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {5A2F146C-8B8A-43F2-BEA0-D4C40BE8C91D}.Debug|Any CPU.Build.0 = Debug|Any CPU {5A2F146C-8B8A-43F2-BEA0-D4C40BE8C91D}.Release|Any CPU.ActiveCfg = Release|Any CPU {5A2F146C-8B8A-43F2-BEA0-D4C40BE8C91D}.Release|Any CPU.Build.0 = Release|Any CPU + {8A44C6B3-1B4C-420A-8BEC-253C429C2C5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8A44C6B3-1B4C-420A-8BEC-253C429C2C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8A44C6B3-1B4C-420A-8BEC-253C429C2C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8A44C6B3-1B4C-420A-8BEC-253C429C2C5E}.Release|Any CPU.Build.0 = Release|Any CPU + {BAF50D85-3072-4FD3-93DB-24BD1A1E570F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAF50D85-3072-4FD3-93DB-24BD1A1E570F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAF50D85-3072-4FD3-93DB-24BD1A1E570F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAF50D85-3072-4FD3-93DB-24BD1A1E570F}.Release|Any CPU.Build.0 = Release|Any CPU + {00DDE5FD-7B4B-481B-BA35-64BB7C6DC20A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00DDE5FD-7B4B-481B-BA35-64BB7C6DC20A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00DDE5FD-7B4B-481B-BA35-64BB7C6DC20A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00DDE5FD-7B4B-481B-BA35-64BB7C6DC20A}.Release|Any CPU.Build.0 = Release|Any CPU + {408C3C58-DFEA-45C0-ABF2-7F4435D3E16A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {408C3C58-DFEA-45C0-ABF2-7F4435D3E16A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {408C3C58-DFEA-45C0-ABF2-7F4435D3E16A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {408C3C58-DFEA-45C0-ABF2-7F4435D3E16A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ComponentLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..7b800ee --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,118 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantContracts.StoragesContracts; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + + +namespace PrecastConcretePlantBusinessLogic.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("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..f552884 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,135 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.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 List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId: {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 FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ReinforcedId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ReinforcedId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ReinforcedId: {ReinforcedId}. ReinforcedCount: {Count}", model.Id, model.Sum, + model.ReinforcedId, model.Count); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) + { + _logger.LogWarning("Change status operation failed. Order not found"); + return false; + } + if (order.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}", + newStatus, order.Status); + return false; + } + model.ReinforcedId = order.ReinforcedId; + model.Count = order.Count; + model.Sum = order.Sum; + model.DateCreate = order.DateCreate; + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs new file mode 100644 index 0000000..7b54d7f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs @@ -0,0 +1,124 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogics +{ + public class ReinforcedLogic : IReinforcedLogic + { + private readonly ILogger _logger; + + private readonly IReinforcedStorage _reinforcedStorage; + + public ReinforcedLogic(ILogger logger, IReinforcedStorage reinforcedStorage) + { + _logger = logger; + _reinforcedStorage = reinforcedStorage; + } + + public List? ReadList(ReinforcedSearchModel? model) + { + _logger.LogInformation("ReadList. ReinforcedName: {ReinforcedName}. Id: {Id}", model?.ReinforcedName, model?.Id); + var list = model == null ? _reinforcedStorage.GetFullList() : _reinforcedStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ReinforcedViewModel? ReadElement(ReinforcedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ReinforcedName: {ReinforcedName}. Id: {Id}", model.ReinforcedName, model.Id); + var element = _reinforcedStorage.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(ReinforcedBindingModel model) + { + CheckModel(model); + if (_reinforcedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ReinforcedBindingModel model) + { + CheckModel(model); + if (_reinforcedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ReinforcedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_reinforcedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ReinforcedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.ReinforcedName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + if (model.ReinforcedComponents == null || model.ReinforcedComponents.Count == 0) + { + throw new ArgumentNullException("Изделие должно состоять хотя бы из одного компонента"); + } + _logger.LogInformation("Reinforced. ReinforcedName: {ReinforcedName}. Price: {Price}. Id: {Id}", model.ReinforcedName, model.Price, model.Id); + var element = _reinforcedStorage.GetElement(new ReinforcedSearchModel + { + ReinforcedName = model.ReinforcedName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/PrecastConcretePlantBusinessLogic.csproj b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/PrecastConcretePlantBusinessLogic.csproj new file mode 100644 index 0000000..82a7c0f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/PrecastConcretePlantBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..22712f9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + + +namespace PrecastConcretePlantContracts.BindingModels + +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..fe5f3ff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; + + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ReinforcedId { 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; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ReinforcedBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ReinforcedBindingModel.cs new file mode 100644 index 0000000..58696d6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ReinforcedBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ReinforcedBindingModel : IReinforcedModel + { + public int Id { get; set; } + public string ReinforcedName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ReinforcedComponents + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IComponentLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..523dd57 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..7aa3b84 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReinforcedLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReinforcedLogic.cs new file mode 100644 index 0000000..4618843 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReinforcedLogic.cs @@ -0,0 +1,20 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IReinforcedLogic + { + List? ReadList(ReinforcedSearchModel? model); + ReinforcedViewModel? ReadElement(ReinforcedSearchModel model); + bool Create(ReinforcedBindingModel model); + bool Update(ReinforcedBindingModel model); + bool Delete(ReinforcedBindingModel model); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj b/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj new file mode 100644 index 0000000..b01d6f6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj @@ -0,0 +1,14 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ComponentSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..c5f5348 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..14a8d3f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ReinforcedSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ReinforcedSearchModel.cs new file mode 100644 index 0000000..a33290e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ReinforcedSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ReinforcedSearchModel + { + public int? Id { get; set; } + public string? ReinforcedName { get; set; } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..3f4b869 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IOrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..2fa214b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IReinforcedStorage.cs new file mode 100644 index 0000000..3921b68 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IReinforcedStorage.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.StoragesContracts +{ + public interface IReinforcedStorage + { + List GetFullList(); + List GetFilteredList(ReinforcedSearchModel model); + ReinforcedViewModel? GetElement(ReinforcedSearchModel model); + ReinforcedViewModel? Insert(ReinforcedBindingModel model); + ReinforcedViewModel? Update(ReinforcedBindingModel model); + ReinforcedViewModel? Delete(ReinforcedBindingModel model); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..037d8c7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..e9e7094 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ReinforcedId { get; set; } + [DisplayName("Изделие")] + public string ReinforcedName { 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; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs new file mode 100644 index 0000000..485d967 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs @@ -0,0 +1,25 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReinforcedViewModel : IReinforcedModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ReinforcedName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ReinforcedComponents + { + get; + set; + } = new(); + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Enums/OrderStatus.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..9e463c1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IId.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IId.cs new file mode 100644 index 0000000..aba777f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IComponentModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..41fab82 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..db89e4e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IOrderModel : IId + { + int ReinforcedId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IReinforcedModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IReinforcedModel.cs new file mode 100644 index 0000000..6a42c6f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IReinforcedModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IReinforcedModel : IId + { + string ReinforcedName { get; } + double Price { get; } + Dictionary ReinforcedComponents { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/PrecastConcretePlantDataModels.csproj b/PrecastConcretePlant/PrecastConcretePlantDataModels/PrecastConcretePlantDataModels.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/PrecastConcretePlantDataModels.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs new file mode 100644 index 0000000..c676181 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantListImplement.Models; + +namespace PrecastConcretePlantListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Reinforceds { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Reinforceds = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..0658217 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; + +namespace PrecastConcretePlantListImplement.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; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..1aeb4a1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs @@ -0,0 +1,122 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AddReinforcedName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AddReinforcedName(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return AddReinforcedName(order.GetViewModel); + } + } + return null; + } + + 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 AddReinforcedName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddReinforcedName(order.GetViewModel); + } + } + return null; + } + + 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 AddReinforcedName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AddReinforcedName(OrderViewModel model) + { + var selectedReinforced = _source.Reinforceds.Find(reinforced => reinforced.Id == model.ReinforcedId); + if (selectedReinforced != null) + { + model.ReinforcedName = selectedReinforced.ReinforcedName; + } + return model; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..0ace7db --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,109 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class ReinforcedStorage : IReinforcedStorage + { + private readonly DataListSingleton _source; + + public ReinforcedStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var reinforced in _source.Reinforceds) + { + result.Add(reinforced.GetViewModel); + } + return result; + } + + public List GetFilteredList(ReinforcedSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + return result; + } + foreach (var reinforced in _source.Reinforceds) + { + if (reinforced.ReinforcedName.Contains(model.ReinforcedName)) + { + result.Add(reinforced.GetViewModel); + } + } + return result; + } + + public ReinforcedViewModel? GetElement(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue) + { + return null; + } + foreach (var reinforced in _source.Reinforceds) + { + if ((!string.IsNullOrEmpty(model.ReinforcedName) && + reinforced.ReinforcedName == model.ReinforcedName) || + (model.Id.HasValue && reinforced.Id == model.Id)) + { + return reinforced.GetViewModel; + } + } + return null; + } + + public ReinforcedViewModel? Insert(ReinforcedBindingModel model) + { + model.Id = 1; + foreach (var reinforced in _source.Reinforceds) + { + if (model.Id <= reinforced.Id) + { + model.Id = reinforced.Id + 1; + } + } + var newReinforced = Reinforced.Create(model); + if (newReinforced == null) + { + return null; + } + _source.Reinforceds.Add(newReinforced); + return newReinforced.GetViewModel; + } + + public ReinforcedViewModel? Update(ReinforcedBindingModel model) + { + foreach (var reinforced in _source.Reinforceds) + { + if (reinforced.Id == model.Id) + { + reinforced.Update(model); + return reinforced.GetViewModel; + } + } + return null; + } + + public ReinforcedViewModel? Delete(ReinforcedBindingModel model) + { + for (int i = 0; i < _source.Reinforceds.Count; ++i) + { + if (_source.Reinforceds[i].Id == model.Id) + { + var element = _source.Reinforceds[i]; + _source.Reinforceds.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Component.cs new file mode 100644 index 0000000..3873eff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public 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 + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs new file mode 100644 index 0000000..ae03ae2 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs @@ -0,0 +1,64 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; + + +namespace PrecastConcretePlantListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ReinforcedId { 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 static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ReinforcedId = model.ReinforcedId, + 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, + ReinforcedId = ReinforcedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Reinforced.cs new file mode 100644 index 0000000..61f7322 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Reinforced.cs @@ -0,0 +1,54 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Reinforced : IReinforcedModel + { + public int Id { get; private set; } + public string ReinforcedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ReinforcedComponents + { + get; + private set; + } = new Dictionary(); + public static Reinforced? Create(ReinforcedBindingModel? model) + { + if (model == null) + { + return null; + } + return new Reinforced() + { + Id = model.Id, + ReinforcedName = model.ReinforcedName, + Price = model.Price, + ReinforcedComponents = model.ReinforcedComponents + }; + } + public void Update(ReinforcedBindingModel? model) + { + if (model == null) + { + return; + } + ReinforcedName = model.ReinforcedName; + Price = model.Price; + ReinforcedComponents = model.ReinforcedComponents; + } + public ReinforcedViewModel GetViewModel => new() + { + Id = Id, + ReinforcedName = ReinforcedName, + Price = Price, + ReinforcedComponents = ReinforcedComponents + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj new file mode 100644 index 0000000..c721cdc --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj @@ -0,0 +1,15 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs deleted file mode 100644 index 4543bfd..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PrecastConcretePlantView -{ - 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 - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs b/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs deleted file mode 100644 index 2bfbb5f..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PrecastConcretePlantView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..b4c436b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace PrecastConcretePlantView +{ + 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() + { + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 23); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(17, 63); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(48, 20); + labelCost.TabIndex = 1; + labelCost.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(100, 20); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(291, 27); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(100, 63); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(148, 27); + textBoxCost.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 112); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(182, 112); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(417, 165); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonCancel; + private Button buttonSave; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs new file mode 100644 index 0000000..be77e5e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantView +{ + 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("Receiving component"); + 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, "Component retrieval error"); + 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("Saving component"); + 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, "Component saving error"); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx similarity index 93% rename from PrecastConcretePlant/PrecastConcretePlantView/Form1.resx rename to PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx index 1af7de1..af32865 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Form1.resx +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..b87d861 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs @@ -0,0 +1,123 @@ +namespace PrecastConcretePlantView +{ + 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(450, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(494, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(105, 40); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(494, 92); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(105, 40); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonDel + // + buttonDel.Location = new Point(494, 157); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(105, 41); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(494, 221); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(105, 39); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(636, 450); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs new file mode 100644 index 0000000..c29ab43 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + 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("Components loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Components loading error"); + 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 ButtonEdit_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("Deletion of component"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Component deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..9ed7ec7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace PrecastConcretePlantView +{ + 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() + { + labelCount = new Label(); + labelSum = new Label(); + labelReinforced = new Label(); + comboBoxReinforced = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(20, 61); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(20, 104); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(62, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма :"; + // + // labelReinforced + // + labelReinforced.AutoSize = true; + labelReinforced.Location = new Point(20, 15); + labelReinforced.Name = "labelReinforced"; + labelReinforced.Size = new Size(71, 20); + labelReinforced.TabIndex = 3; + labelReinforced.Text = "Изделие:"; + // + // comboBoxReinforced + // + comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxReinforced.FormattingEnabled = true; + comboBoxReinforced.Location = new Point(124, 12); + comboBoxReinforced.Name = "comboBoxReinforced"; + comboBoxReinforced.Size = new Size(300, 28); + comboBoxReinforced.TabIndex = 4; + comboBoxReinforced.SelectedIndexChanged += ComboBoxReinforced_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(124, 58); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(300, 27); + textBoxCount.TabIndex = 5; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(124, 104); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(300, 27); + textBoxSum.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(195, 153); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 36); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(312, 153); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 36); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(452, 199); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxReinforced); + Controls.Add(labelReinforced); + Controls.Add(labelSum); + Controls.Add(labelCount); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelCount; + private Label labelSum; + private Label labelReinforced; + private ComboBox comboBoxReinforced; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs new file mode 100644 index 0000000..3f099a7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs @@ -0,0 +1,131 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantBusinessLogic.BusinessLogics; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IReinforcedLogic _logicR; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IReinforcedLogic + logicR, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicR = logicR; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var reinforcedList = _logicR.ReadList(null); + if (reinforcedList != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = reinforcedList; + comboBoxReinforced.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при загрузке изделия для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxReinforced.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxReinforced.SelectedValue); + var product = _logicR.ReadElement(new ReinforcedSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.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 ComboBoxReinforced_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 (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ReinforcedId = Convert.ToInt32(comboBoxReinforced.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(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs new file mode 100644 index 0000000..5fa79a5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -0,0 +1,181 @@ +namespace PrecastConcretePlantView +{ + 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() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonUpd = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1257, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(182, 26); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 45); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(1031, 412); + dataGridView.TabIndex = 0; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1068, 85); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(177, 40); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(1068, 143); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(177, 40); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(1068, 206); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(177, 40); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1068, 265); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(177, 40); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(1068, 324); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(177, 40); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Обновить список"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1257, 469); + Controls.Add(buttonUpd); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Завод"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs new file mode 100644 index 0000000..bc48aaa --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -0,0 +1,156 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + 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["ReinforcedId"].Visible = false; + dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _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(FormReinforceds)); + if (service is FormReinforceds 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 ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx new file mode 100644 index 0000000..e527639 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 25 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs new file mode 100644 index 0000000..b9bae38 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs @@ -0,0 +1,237 @@ +namespace PrecastConcretePlantView +{ + partial class FormReinforced + { + /// + /// 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() + { + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelName = new Label(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(29, 76); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(90, 20); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость :"; + // + // textBoxName + // + textBoxName.Location = new Point(125, 28); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(297, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(125, 76); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(141, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonEdit); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(29, 129); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(667, 314); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // buttonUpd + // + buttonUpd.Location = new Point(533, 191); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(109, 39); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(533, 136); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(109, 39); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(533, 81); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(109, 39); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(533, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(109, 39); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(493, 277); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.FillWeight = 100.53476F; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 93; + // + // buttonSave + // + buttonSave.Location = new Point(380, 460); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(109, 39); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(506, 460); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(109, 39); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(29, 31); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 7; + labelName.Text = "Название :"; + // + // FormReinforced + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(749, 511); + Controls.Add(labelName); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Name = "FormReinforced"; + Text = "Изделие"; + Load += FormReinforced_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs new file mode 100644 index 0000000..770dd30 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs @@ -0,0 +1,216 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormReinforced : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logic; + + private int? _id; + + private Dictionary _reinforcedComponents; + + public int Id { set { _id = value; } } + public FormReinforced(ILogger logger, IReinforcedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _reinforcedComponents = new Dictionary(); + } + private void FormReinforced_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ReinforcedSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ReinforcedName; + textBoxPrice.Text = view.Price.ToString(); + _reinforcedComponents = view.ReinforcedComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_reinforcedComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _reinforcedComponents) + { + 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(FormReinforcedComponent)); + if (service is FormReinforcedComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_reinforcedComponents.ContainsKey(form.Id)) + { + _reinforcedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _reinforcedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedComponent)); + if (service is FormReinforcedComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _reinforcedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + _reinforcedComponents[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, + dataGridView.SelectedRows[0].Cells[2].Value); + _reinforcedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpd_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 (_reinforcedComponents == null || _reinforcedComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ReinforcedBindingModel + { + Id = _id ?? 0, + ReinforcedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ReinforcedComponents = _reinforcedComponents + }; + 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 _reinforcedComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.resx new file mode 100644 index 0000000..cb70e49 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs new file mode 100644 index 0000000..979b6ae --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace PrecastConcretePlantView +{ + partial class FormReinforcedComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 26); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(95, 20); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 84); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(113, 23); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(281, 28); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(113, 81); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(281, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(168, 136); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(104, 36); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(290, 136); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(104, 36); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormReinforcedComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(433, 201); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormReinforcedComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs new file mode 100644 index 0000000..62e3a49 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs @@ -0,0 +1,77 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormReinforcedComponent : 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 FormReinforcedComponent(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(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs new file mode 100644 index 0000000..bc88997 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs @@ -0,0 +1,123 @@ +namespace PrecastConcretePlantView +{ + partial class FormReinforceds + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(453, 450); + dataGridView.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.Location = new Point(474, 49); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(122, 39); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(474, 107); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(122, 39); + buttonEdit.TabIndex = 3; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonDel + // + buttonDel.Location = new Point(474, 165); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(122, 39); + buttonDel.TabIndex = 4; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(474, 224); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(122, 39); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormReinforceds + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(608, 450); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormReinforceds"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Изделия"; + Load += FormReinforceds_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs new file mode 100644 index 0000000..b51866d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormReinforceds : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logic; + public FormReinforceds(ILogger logger, IReinforcedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormReinforceds_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["ReinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ReinforcedComponents"].Visible = false; + } + _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(FormReinforced)); + if (service is FormReinforced form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforced)); + if (service is FormReinforced 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 ReinforcedBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj index b57c89e..b36d435 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index e0bc094..68511c7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -1,7 +1,18 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantBusinessLogic.BusinessLogics; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + + namespace PrecastConcretePlantView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,33 @@ namespace PrecastConcretePlantView // 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/PrecastConcretePlant/PrecastConcretePlantView/nlog.config b/PrecastConcretePlant/PrecastConcretePlantView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file