From 69f973f2528f52f1737074e766470e706d81d228 Mon Sep 17 00:00:00 2001 From: "Pyatkin I.A" <4234.sunrise.234@gmail.com> Date: Fri, 9 Feb 2024 16:47:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcretePlant/PrecastConcretePlant.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 112 ++++++++ .../BusinessLogics/OrderLogic.cs | 123 +++++++++ .../BusinessLogics/ReinforcedLogic.cs | 112 ++++++++ .../PrecastConcretePlantBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/ReinforcedBindingModel.cs | 18 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../IReinforcedLogic.cs | 20 ++ .../PrecastConcretePlantContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 14 + .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/ReinforcedSearchModel.cs | 14 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IReinforcedStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 19 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../ViewModels/ReinforcedViewModel.cs | 20 ++ .../Enums/OrderStatus.cs | 17 ++ .../PrecastConcretePlantDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 14 + .../Models/IOrderModel.cs | 20 ++ .../Models/IReinforcedModel.cs | 15 ++ .../PrecastConcretePlantDataModels.csproj | 9 + .../DataListSingleton.cs | 32 +++ .../Implements/ComponentStorage.cs | 106 ++++++++ .../Implements/OrderStorage.cs | 105 ++++++++ .../Implements/ReinforcedStorage.cs | 106 ++++++++ .../Models/Component.cs | 46 ++++ .../Models/Order.cs | 62 +++++ .../Models/Reinforced.cs | 50 ++++ .../PrecastConcretePlantListImplement.csproj | 14 + .../Form1.Designer.cs | 39 --- .../PrecastConcretePlantView/Form1.cs | 10 - .../PrecastConcretePlantView/Form1.resx | 120 --------- .../FormComponent.Designer.cs | 124 +++++++++ .../PrecastConcretePlantView/FormComponent.cs | 90 +++++++ .../FormComponent.resx | 60 +++++ .../FormComponents.Designer.cs | 138 ++++++++++ .../FormComponents.cs | 113 ++++++++ .../FormComponents.resx | 60 +++++ .../FormCreateOrder.Designer.cs | 153 +++++++++++ .../FormCreateOrder.cs | 127 +++++++++ .../FormCreateOrder.resx | 60 +++++ .../FormMain.Designer.cs | 188 +++++++++++++ .../PrecastConcretePlantView/FormMain.cs | 156 +++++++++++ .../PrecastConcretePlantView/FormMain.resx | 63 +++++ .../FormReinforced.Designer.cs | 249 ++++++++++++++++++ .../FormReinforced.cs | 213 +++++++++++++++ .../FormReinforced.resx | 60 +++++ .../FormReinforcedComponent.Designer.cs | 125 +++++++++ .../FormReinforcedComponent.cs | 83 ++++++ .../FormReinforcedComponent.resx | 60 +++++ .../FormReinforceds.Designer.cs | 138 ++++++++++ .../FormReinforceds.cs | 109 ++++++++ .../FormReinforceds.resx | 60 +++++ .../PrecastConcretePlantView.csproj | 23 ++ .../PrecastConcretePlantView/Program.cs | 40 ++- .../PrecastConcretePlantView/nlog.config | 15 ++ 62 files changed, 3806 insertions(+), 171 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 delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/Form1.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx 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 ac4cfd4..83fc82a 100644 --- a/PrecastConcretePlant/PrecastConcretePlant.sln +++ b/PrecastConcretePlant/PrecastConcretePlant.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantView", "PrecastConcretePlantView\PrecastConcretePlantView.csproj", "{24A07954-5B42-4DA7-8BD3-6C2481185885}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantView", "PrecastConcretePlantView\PrecastConcretePlantView.csproj", "{24A07954-5B42-4DA7-8BD3-6C2481185885}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantDataModels", "PrecastConcretePlantDataModels\PrecastConcretePlantDataModels.csproj", "{18B37793-79C5-4A82-9240-C7E12F19D5ED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantContracts", "PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj", "{B05B9322-2F26-4849-B140-057BC377F30F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{890F8676-DFB2-4F5B-89F6-7D9DC82C5357}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantBusinessLogic", "PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj", "{EC5D3BC3-5454-4BE2-8FCB-ECE014F93FE1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {24A07954-5B42-4DA7-8BD3-6C2481185885}.Debug|Any CPU.Build.0 = Debug|Any CPU {24A07954-5B42-4DA7-8BD3-6C2481185885}.Release|Any CPU.ActiveCfg = Release|Any CPU {24A07954-5B42-4DA7-8BD3-6C2481185885}.Release|Any CPU.Build.0 = Release|Any CPU + {18B37793-79C5-4A82-9240-C7E12F19D5ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18B37793-79C5-4A82-9240-C7E12F19D5ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18B37793-79C5-4A82-9240-C7E12F19D5ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18B37793-79C5-4A82-9240-C7E12F19D5ED}.Release|Any CPU.Build.0 = Release|Any CPU + {B05B9322-2F26-4849-B140-057BC377F30F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B05B9322-2F26-4849-B140-057BC377F30F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B05B9322-2F26-4849-B140-057BC377F30F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B05B9322-2F26-4849-B140-057BC377F30F}.Release|Any CPU.Build.0 = Release|Any CPU + {890F8676-DFB2-4F5B-89F6-7D9DC82C5357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {890F8676-DFB2-4F5B-89F6-7D9DC82C5357}.Debug|Any CPU.Build.0 = Debug|Any CPU + {890F8676-DFB2-4F5B-89F6-7D9DC82C5357}.Release|Any CPU.ActiveCfg = Release|Any CPU + {890F8676-DFB2-4F5B-89F6-7D9DC82C5357}.Release|Any CPU.Build.0 = Release|Any CPU + {EC5D3BC3-5454-4BE2-8FCB-ECE014F93FE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC5D3BC3-5454-4BE2-8FCB-ECE014F93FE1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC5D3BC3-5454-4BE2-8FCB-ECE014F93FE1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC5D3BC3-5454-4BE2-8FCB-ECE014F93FE1}.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..85b35c0 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,112 @@ +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 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..4711f8b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,123 @@ +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 List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id: {Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model, false); + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Принят) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order?.Status != OrderStatus.Готов) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Выдан; + model.DateImplement = order.DateImplement; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ReinforcedId: {ReinforcedId}", model.Id, model.Sum, model.ReinforcedId); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким номером уже есть"); + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs new file mode 100644 index 0000000..b333f37 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ReinforcedLogic.cs @@ -0,0 +1,112 @@ +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)); + } + _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..87c12b3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/PrecastConcretePlantBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..fad4e83 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..e8e0bff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ReinforcedId { get; set; } + public string ReinforcedName { get; set; } = string.Empty; + 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..97d254a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ReinforcedBindingModel.cs @@ -0,0 +1,18 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..11cb568 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IComponentLogic.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 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..5b3c94b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.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 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..51219ff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/PrecastConcretePlantContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + 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..9c41732 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ReinforcedSearchModel.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 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..f72230f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +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..4e6817e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReinforcedViewModel.cs @@ -0,0 +1,20 @@ +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..1ec34c9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +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..50d8b16 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +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; } + string ReinforcedName { 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..132c02c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/PrecastConcretePlantDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs new file mode 100644 index 0000000..04a9ff5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..2c3cf59 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,106 @@ +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 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..ce71720 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +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(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 (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return 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 newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return 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 element.GetViewModel; + } + } + return null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..bf2b300 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,106 @@ +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 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..07efc85 --- /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; private 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..5b08bd4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ReinforcedId { get; private set; } + public string ReinforcedName { get; private set; } = String.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + 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, + ReinforcedName = model.ReinforcedName, + 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, + ReinforcedName = ReinforcedName, + 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..a68c7b8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Reinforced.cs @@ -0,0 +1,50 @@ +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..3b2c1a9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/PrecastConcretePlantListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/Form1.Designer.cs deleted file mode 100644 index fc09a3d..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 - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs b/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs deleted file mode 100644 index cb7d485..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PrecastConcretePlantView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Form1.resx b/PrecastConcretePlant/PrecastConcretePlantView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..0bcd1eb --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.Designer.cs @@ -0,0 +1,124 @@ +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() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(275, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(86, 32); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(122, 23); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(10, 32); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(143, 72); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 26); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(245, 72); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(97, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs new file mode 100644 index 0000000..28f9ef9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +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 FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");//При обновлении, может быть, тоже ошибка появиться.. + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..2811441 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.Designer.cs @@ -0,0 +1,138 @@ +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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 2); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(519, 360); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.dataGridView); + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(-1, -1); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(675, 364); + this.ToolsPanel.TabIndex = 1; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(528, 155); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(528, 107); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(528, 58); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(528, 13); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(673, 361); + this.Controls.Add(this.ToolsPanel); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs new file mode 100644 index 0000000..a9833ab --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.cs @@ -0,0 +1,113 @@ +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("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..1194728 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,153 @@ +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() + { + this.labelReinforced = new System.Windows.Forms.Label(); + this.comboBoxReinforced = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelSumm = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelReinforced + // + this.labelReinforced.AutoSize = true; + this.labelReinforced.Location = new System.Drawing.Point(10, 11); + this.labelReinforced.Name = "labelReinforced"; + this.labelReinforced.Size = new System.Drawing.Size(59, 15); + this.labelReinforced.TabIndex = 0; + this.labelReinforced.Text = "Изделие: "; + // + // comboBoxReinforced + // + this.comboBoxReinforced.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxReinforced.FormattingEnabled = true; + this.comboBoxReinforced.Location = new System.Drawing.Point(101, 9); + this.comboBoxReinforced.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxReinforced.Name = "comboBoxReinforced"; + this.comboBoxReinforced.Size = new System.Drawing.Size(200, 23); + this.comboBoxReinforced.TabIndex = 1; + this.comboBoxReinforced.SelectedIndexChanged += new System.EventHandler(this.ComboBoxReinforced_SelectedIndexChanged); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 37); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(78, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(101, 34); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(200, 23); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelSumm + // + this.labelSumm.AutoSize = true; + this.labelSumm.Location = new System.Drawing.Point(10, 60); + this.labelSumm.Name = "labelSumm"; + this.labelSumm.Size = new System.Drawing.Size(51, 15); + this.labelSumm.TabIndex = 4; + this.labelSumm.Text = "Сумма: "; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(101, 60); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(200, 23); + this.textBoxSum.TabIndex = 5; + this.textBoxSum.Click += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(203, 87); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(96, 24); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(101, 87); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 24); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(315, 118); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelSumm); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxReinforced); + this.Controls.Add(this.labelReinforced); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelReinforced; + private ComboBox comboBoxReinforced; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSumm; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs new file mode 100644 index 0000000..8162bed --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +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) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logicR.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + _logger.LogInformation("Загрузка изделий для заказа"); + } + 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 Reinforced = _logicR.ReadElement(new ReinforcedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Reinforced?.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), + ReinforcedName = comboBoxReinforced.Text, + 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..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs new file mode 100644 index 0000000..d16aedd --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -0,0 +1,188 @@ +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() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(1099, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникToolStripMenuItem + // + this.справочникToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; + this.справочникToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 23); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(861, 297); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(867, 40); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(867, 91); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(867, 143); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(216, 22); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(867, 191); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(867, 232); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(216, 22); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1099, 320); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormMain"; + this.Text = "Завод ЖБИ"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + 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 buttonRef; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs new file mode 100644 index 0000000..536a41b --- /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("Заказ No{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("Заказ No{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("Заказ No{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs new file mode 100644 index 0000000..b3a7b2e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.Designer.cs @@ -0,0 +1,249 @@ +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() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 11); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(65, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 9); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(246, 23); + this.textBoxName.TabIndex = 1; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 38); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(73, 15); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(98, 38); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(135, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(10, 63); + this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Size = new System.Drawing.Size(562, 239); + this.groupBoxComponents.TabIndex = 4; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(439, 158); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 26); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(439, 118); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 26); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(439, 76); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 26); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(439, 35); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 26); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(416, 215); + this.dataGridView.TabIndex = 0; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(361, 313); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(245, 313); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 26); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormReinforced + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(599, 347); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormReinforced"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormReinforced_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelPrice; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn id; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs new file mode 100644 index 0000000..79b707c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.cs @@ -0,0 +1,213 @@ +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 ButtonUpd_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); + _ReinforcedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_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..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforced.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs new file mode 100644 index 0000000..b8374ca --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.Designer.cs @@ -0,0 +1,125 @@ +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() + { + this.labelComponent = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(10, 7); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(72, 15); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(104, 7); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(235, 23); + this.comboBoxComponent.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 38); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(104, 38); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(235, 23); + this.textBoxCount.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(253, 70); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(86, 31); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 70); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 31); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormReinforcedComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 110); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelComponent); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormReinforcedComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs new file mode 100644 index 0000000..7ddcc9c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.cs @@ -0,0 +1,83 @@ +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..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs new file mode 100644 index 0000000..f753865 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.Designer.cs @@ -0,0 +1,138 @@ +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() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.dataGridView); + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(-1, -1); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(717, 361); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(534, 173); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(534, 125); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(534, 76); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(534, 31); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 359); + this.dataGridView.TabIndex = 2; + // + // FormReinforceds + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(707, 359); + this.Controls.Add(this.ToolsPanel); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormReinforceds"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormReinforcedes_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs new file mode 100644 index 0000000..a033d4d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.cs @@ -0,0 +1,109 @@ +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 FormReinforcedes_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["ReinforcedComponents"].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 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 ButtonUpd_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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforceds.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj index b57c89e..651defa 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj @@ -8,4 +8,27 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index e0bc094..c8c6ebd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -1,7 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PrecastConcretePlantBusinessLogic.BusinessLogics; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantListImplement.Implements; +using System; + 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,34 @@ 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..dcd37c8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file