From 458b8f03686073599a219f94d1e67accb1ed65e5 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Mon, 11 Mar 2024 00:46:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=201?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GarmentFactory/GarmentFactory.sln | 24 ++ .../BusinessLogics/ComponentLogic.cs | 115 +++++++++ .../BusinessLogics/OrderLogic.cs | 135 ++++++++++ .../BusinessLogics/TextileLogic.cs | 124 +++++++++ .../GarmentFactoryBusinessLogic.csproj | 18 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/TextileBindingModel.cs | 21 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/ITextileLogic.cs | 20 ++ .../GarmentFactoryContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/TextileSearchModel.cs | 14 + .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 22 ++ .../StoragesContracts/ITextileStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 19 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../ViewModels/TextileViewModel.cs | 24 ++ .../Enums/OrderStatus.cs | 17 ++ .../GarmentFactoryDataModels.csproj | 9 + .../GarmentFactoryDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 14 + .../Models/IOrderModel.cs | 20 ++ .../Models/ITextileModel.cs | 15 ++ .../DataListSingleton.cs | 31 +++ .../GarmentFactoryListImplement.csproj | 14 + .../Implements/ComponentStorage.cs | 109 ++++++++ .../Implements/OrderStorage.cs | 122 +++++++++ .../Implements/TextileStorage.cs | 114 ++++++++ .../Models/Component.cs | 46 ++++ .../Models/Order.cs | 68 +++++ .../Models/Textile.cs | 51 ++++ .../GarmentFactoryView/Form1.Designer.cs | 39 --- GarmentFactory/GarmentFactoryView/Form1.cs | 10 - .../FormComponent.Designer.cs | 123 +++++++++ .../GarmentFactoryView/FormComponent.cs | 93 +++++++ .../{Form1.resx => FormComponent.resx} | 50 ++-- .../FormComponents.Designer.cs | 123 +++++++++ .../GarmentFactoryView/FormComponents.cs | 121 +++++++++ .../GarmentFactoryView/FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 147 +++++++++++ .../GarmentFactoryView/FormCreateOrder.cs | 135 ++++++++++ .../GarmentFactoryView/FormCreateOrder.resx | 120 +++++++++ .../GarmentFactoryView/FormMain.Designer.cs | 180 +++++++++++++ GarmentFactory/GarmentFactoryView/FormMain.cs | 159 ++++++++++++ .../GarmentFactoryView/FormMain.resx | 123 +++++++++ .../FormTextile.Designer.cs | 243 ++++++++++++++++++ .../GarmentFactoryView/FormTextile.cs | 227 ++++++++++++++++ .../GarmentFactoryView/FormTextile.resx | 129 ++++++++++ .../FormTextileComponent.Designer.cs | 120 +++++++++ .../FormTextileComponent.cs | 93 +++++++ .../FormTextileComponent.resx | 120 +++++++++ .../FormTextiles.Designer.cs | 123 +++++++++ .../GarmentFactoryView/FormTextiles.cs | 114 ++++++++ .../GarmentFactoryView/FormTextiles.resx | 120 +++++++++ .../GarmentFactoryView.csproj | 12 + GarmentFactory/GarmentFactoryView/Program.cs | 45 +++- GarmentFactory/GarmentFactoryView/nlog.config | 15 ++ 61 files changed, 4194 insertions(+), 81 deletions(-) create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/TextileLogic.cs create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/GarmentFactoryBusinessLogic.csproj create mode 100644 GarmentFactory/GarmentFactoryContracts/BindingModels/ComponentBindingModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BindingModels/TextileBindingModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/ITextileLogic.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/GarmentFactoryContracts.csproj create mode 100644 GarmentFactory/GarmentFactoryContracts/SearchModels/ComponentSearchModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/SearchModels/TextileSearchModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/StoragesContracts/IComponentStorage.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/StoragesContracts/IOrderStorage.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/StoragesContracts/ITextileStorage.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/ViewModels/ComponentViewModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/ViewModels/TextileViewModel.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/Enums/OrderStatus.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/GarmentFactoryDataModels.csproj create mode 100644 GarmentFactory/GarmentFactoryDataModels/IId.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/Models/IComponentModel.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/Models/ITextileModel.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/GarmentFactoryListImplement.csproj create mode 100644 GarmentFactory/GarmentFactoryListImplement/Implements/ComponentStorage.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Implements/TextileStorage.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Models/Component.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Models/Order.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Models/Textile.cs delete mode 100644 GarmentFactory/GarmentFactoryView/Form1.Designer.cs delete mode 100644 GarmentFactory/GarmentFactoryView/Form1.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormComponent.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormComponent.cs rename GarmentFactory/GarmentFactoryView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 GarmentFactory/GarmentFactoryView/FormComponents.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormComponents.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormComponents.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormCreateOrder.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormCreateOrder.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormCreateOrder.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormMain.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormMain.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormMain.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormTextile.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextile.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextile.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormTextileComponent.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextileComponent.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextileComponent.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormTextiles.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextiles.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormTextiles.resx create mode 100644 GarmentFactory/GarmentFactoryView/nlog.config diff --git a/GarmentFactory/GarmentFactory.sln b/GarmentFactory/GarmentFactory.sln index 24f5adf..e752dcb 100644 --- a/GarmentFactory/GarmentFactory.sln +++ b/GarmentFactory/GarmentFactory.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryView", "GarmentFactoryView\GarmentFactoryView.csproj", "{65042CBB-618A-473F-BA40-C698EFD4850E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryBusinessLogic", "GarmentFactoryBusinessLogic\GarmentFactoryBusinessLogic.csproj", "{62F1E4D7-57A6-461E-90A3-92E41AB90207}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryContracts", "GarmentFactoryContracts\GarmentFactoryContracts.csproj", "{35B381E5-7C62-43F4-B1B0-608542B71E73}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryDataModels", "GarmentFactoryDataModels\GarmentFactoryDataModels.csproj", "{40AF2900-9319-4957-AEE3-8FB3738805D4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryListImplement", "GarmentFactoryListImplement\GarmentFactoryListImplement.csproj", "{AA691567-80A9-45EF-9916-C55FA3B53C47}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {65042CBB-618A-473F-BA40-C698EFD4850E}.Debug|Any CPU.Build.0 = Debug|Any CPU {65042CBB-618A-473F-BA40-C698EFD4850E}.Release|Any CPU.ActiveCfg = Release|Any CPU {65042CBB-618A-473F-BA40-C698EFD4850E}.Release|Any CPU.Build.0 = Release|Any CPU + {62F1E4D7-57A6-461E-90A3-92E41AB90207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62F1E4D7-57A6-461E-90A3-92E41AB90207}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62F1E4D7-57A6-461E-90A3-92E41AB90207}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62F1E4D7-57A6-461E-90A3-92E41AB90207}.Release|Any CPU.Build.0 = Release|Any CPU + {35B381E5-7C62-43F4-B1B0-608542B71E73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35B381E5-7C62-43F4-B1B0-608542B71E73}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35B381E5-7C62-43F4-B1B0-608542B71E73}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35B381E5-7C62-43F4-B1B0-608542B71E73}.Release|Any CPU.Build.0 = Release|Any CPU + {40AF2900-9319-4957-AEE3-8FB3738805D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40AF2900-9319-4957-AEE3-8FB3738805D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40AF2900-9319-4957-AEE3-8FB3738805D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40AF2900-9319-4957-AEE3-8FB3738805D4}.Release|Any CPU.Build.0 = Release|Any CPU + {AA691567-80A9-45EF-9916-C55FA3B53C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA691567-80A9-45EF-9916-C55FA3B53C47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA691567-80A9-45EF-9916-C55FA3B53C47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA691567-80A9-45EF-9916-C55FA3B53C47}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..a437971 --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,115 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryBusinessLogic.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/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..ae14b7b --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,135 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.TextileId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.TextileId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. TextileId: {TextileId}. TextileCount: {Count}", model.Id, model.Sum, + model.TextileId, model.Count); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) + { + _logger.LogWarning("Change status operation failed. Order not found"); + return false; + } + if (order.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}", + newStatus, order.Status); + return false; + } + model.TextileId = order.TextileId; + model.Count = order.Count; + model.Sum = order.Sum; + model.DateCreate = order.DateCreate; + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + } +} diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/TextileLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/TextileLogic.cs new file mode 100644 index 0000000..9f8cb82 --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/TextileLogic.cs @@ -0,0 +1,124 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryBusinessLogic.BusinessLogics +{ + public class TextileLogic : ITextileLogic + { + private readonly ILogger _logger; + + private readonly ITextileStorage _textileStorage; + + public TextileLogic(ILogger logger, ITextileStorage textileStorage) + { + _logger = logger; + _textileStorage = textileStorage; + } + + public List? ReadList(TextileSearchModel? model) + { + _logger.LogInformation("ReadList. TextileName: {TextileName}. Id: {Id}", model?.TextileName, model?.Id); + var list = model == null ? _textileStorage.GetFullList() : _textileStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public TextileViewModel? ReadElement(TextileSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. TextileName: {TextileName}. Id: {Id}", model.TextileName, model.Id); + var element = _textileStorage.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(TextileBindingModel model) + { + CheckModel(model); + if (_textileStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(TextileBindingModel model) + { + CheckModel(model); + if (_textileStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(TextileBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_textileStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(TextileBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.TextileName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.TextileName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена ткани должна быть больше 0", nameof(model.Price)); + } + if (model.TextileComponents == null || model.TextileComponents.Count == 0) + { + throw new ArgumentNullException("Изделие должно состоять хотя бы из одного компонента"); + } + _logger.LogInformation("Textile. TextileName: {TextileName}. Price: {Price}. Id: {Id}", model.TextileName, model.Price, model.Id); + var element = _textileStorage.GetElement(new TextileSearchModel + { + TextileName = model.TextileName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/GarmentFactoryBusinessLogic.csproj b/GarmentFactory/GarmentFactoryBusinessLogic/GarmentFactoryBusinessLogic.csproj new file mode 100644 index 0000000..355b58a --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/GarmentFactoryBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/GarmentFactory/GarmentFactoryContracts/BindingModels/ComponentBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..a260453 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryDataModels.Models; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..b0429e9 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryDataModels.Enums; +using GarmentFactoryDataModels.Models; + + +namespace GarmentFactoryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int TextileId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BindingModels/TextileBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/TextileBindingModel.cs new file mode 100644 index 0000000..87037c7 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/TextileBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryDataModels.Models; + +namespace GarmentFactoryContracts.BindingModels +{ + public class TextileBindingModel : ITextileModel + { + public int Id { get; set; } + public string TextileName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary TextileComponents + { + get; + set; + } = new(); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IComponentLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..60838c5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..f735303 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/ITextileLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/ITextileLogic.cs new file mode 100644 index 0000000..5e9156d --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/ITextileLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryContracts.BusinessLogicsContracts +{ + public interface ITextileLogic + { + List? ReadList(TextileSearchModel? model); + TextileViewModel? ReadElement(TextileSearchModel model); + bool Create(TextileBindingModel model); + bool Update(TextileBindingModel model); + bool Delete(TextileBindingModel model); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/GarmentFactoryContracts.csproj b/GarmentFactory/GarmentFactoryContracts/GarmentFactoryContracts.csproj new file mode 100644 index 0000000..179fb3e --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/GarmentFactoryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/ComponentSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..dff273c --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..6debaa3 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/TextileSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/TextileSearchModel.cs new file mode 100644 index 0000000..b5a47bc --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/TextileSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class TextileSearchModel + { + public int? Id { get; set; } + public string? TextileName { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IComponentStorage.cs b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..7d76f34 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IOrderStorage.cs b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..acf854c --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/StoragesContracts/ITextileStorage.cs b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/ITextileStorage.cs new file mode 100644 index 0000000..6b76688 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/ITextileStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + +namespace GarmentFactoryContracts.StoragesContracts +{ + public interface ITextileStorage + { + List GetFullList(); + List GetFilteredList(TextileSearchModel model); + TextileViewModel? GetElement(TextileSearchModel model); + TextileViewModel? Insert(TextileBindingModel model); + TextileViewModel? Update(TextileBindingModel model); + TextileViewModel? Delete(TextileBindingModel model); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/ComponentViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..178eee2 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryDataModels.Models; +using System.ComponentModel; + +namespace GarmentFactoryContracts.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/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..85911a7 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryDataModels.Enums; +using GarmentFactoryDataModels.Models; +using System.ComponentModel; + +namespace GarmentFactoryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int TextileId { get; set; } + [DisplayName("Изделие")] + public string TextileName { 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/GarmentFactory/GarmentFactoryContracts/ViewModels/TextileViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/TextileViewModel.cs new file mode 100644 index 0000000..ca1bee2 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/TextileViewModel.cs @@ -0,0 +1,24 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; + +namespace GarmentFactoryContracts.ViewModels +{ + public class TextileViewModel : ITextileModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string TextileName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary TextileComponents + { + get; + set; + } = new(); + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Enums/OrderStatus.cs b/GarmentFactory/GarmentFactoryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..2cf39bc --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/GarmentFactoryDataModels.csproj b/GarmentFactory/GarmentFactoryDataModels/GarmentFactoryDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/GarmentFactoryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/GarmentFactory/GarmentFactoryDataModels/IId.cs b/GarmentFactory/GarmentFactoryDataModels/IId.cs new file mode 100644 index 0000000..12143e9 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/IComponentModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..66ca2e5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..5f6702b --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using GarmentFactoryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface IOrderModel : IId + { + int TextileId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/ITextileModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/ITextileModel.cs new file mode 100644 index 0000000..95edba3 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Models/ITextileModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface ITextileModel : IId + { + string TextileName { get; } + double Price { get; } + Dictionary TextileComponents { get; } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..2970d16 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using GarmentFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Textiles { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Textiles = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/GarmentFactoryListImplement.csproj b/GarmentFactory/GarmentFactoryListImplement/GarmentFactoryListImplement.csproj new file mode 100644 index 0000000..ea73c98 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/GarmentFactoryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/GarmentFactory/GarmentFactoryListImplement/Implements/ComponentStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..6ed729b --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,109 @@ +using GarmentFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryListImplement.Models; + + +namespace GarmentFactoryListImplement.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/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..a3a544c --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryListImplement.Models; + +namespace GarmentFactoryListImplement.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(AddTextileName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AddTextileName(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return AddTextileName(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 AddTextileName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddTextileName(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 AddTextileName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AddTextileName(OrderViewModel model) + { + var selectedTextile = _source.Textiles.Find(textile => textile.Id == model.TextileId); + if (selectedTextile != null) + { + model.TextileName = selectedTextile.TextileName; + } + return model; + } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Implements/TextileStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/TextileStorage.cs new file mode 100644 index 0000000..85cd6f5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/TextileStorage.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryListImplement.Models; + +namespace GarmentFactoryListImplement.Implements +{ + public class TextileStorage : ITextileStorage + { + private readonly DataListSingleton _source; + + public TextileStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var Textile in _source.Textiles) + { + result.Add(Textile.GetViewModel); + } + return result; + } + + public List GetFilteredList(TextileSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.TextileName)) + { + return result; + } + foreach (var textile in _source.Textiles) + { + if (textile.TextileName.Contains(model.TextileName)) + { + result.Add(textile.GetViewModel); + } + } + return result; + } + + public TextileViewModel? GetElement(TextileSearchModel model) + { + if (string.IsNullOrEmpty(model.TextileName) && !model.Id.HasValue) + { + return null; + } + foreach (var textile in _source.Textiles) + { + if ((!string.IsNullOrEmpty(model.TextileName) && + textile.TextileName == model.TextileName) || + (model.Id.HasValue && textile.Id == model.Id)) + { + return textile.GetViewModel; + } + } + return null; + } + + public TextileViewModel? Insert(TextileBindingModel model) + { + model.Id = 1; + foreach (var textile in _source.Textiles) + { + if (model.Id <= textile.Id) + { + model.Id = textile.Id + 1; + } + } + var newTextile = Textile.Create(model); + if (newTextile == null) + { + return null; + } + _source.Textiles.Add(newTextile); + return newTextile.GetViewModel; + } + + public TextileViewModel? Update(TextileBindingModel model) + { + foreach (var textile in _source.Textiles) + { + if (textile.Id == model.Id) + { + textile.Update(model); + return textile.GetViewModel; + } + } + return null; + } + + public TextileViewModel? Delete(TextileBindingModel model) + { + for (int i = 0; i < _source.Textiles.Count; ++i) + { + if (_source.Textiles[i].Id == model.Id) + { + var element = _source.Textiles[i]; + _source.Textiles.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Component.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Component.cs new file mode 100644 index 0000000..73df62c --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; + +namespace GarmentFactoryListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs new file mode 100644 index 0000000..b2c4857 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs @@ -0,0 +1,68 @@ +using GarmentFactoryDataModels.Models; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int TextileId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + TextileId = model.TextileId, + 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, + TextileId = TextileId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Textile.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Textile.cs new file mode 100644 index 0000000..5b188d4 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Textile.cs @@ -0,0 +1,51 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Models +{ + public class Textile : ITextileModel + { + public int Id { get; private set; } + public string TextileName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary TextileComponents + { + get; + private set; + } = new Dictionary(); + public static Textile? Create(TextileBindingModel? model) + { + if (model == null) + { + return null; + } + return new Textile() + { + Id = model.Id,TextileName = model.TextileName, Price = model.Price, TextileComponents = model.TextileComponents + }; + } + public void Update(TextileBindingModel? model) + { + if (model == null) + { + return; + } + TextileName = model.TextileName; + Price = model.Price; + TextileComponents = model.TextileComponents; + } + public TextileViewModel GetViewModel => new() + { + Id = Id, + TextileName = TextileName, + Price = Price, + TextileComponents = TextileComponents + }; + } +} diff --git a/GarmentFactory/GarmentFactoryView/Form1.Designer.cs b/GarmentFactory/GarmentFactoryView/Form1.Designer.cs deleted file mode 100644 index 5dda7b1..0000000 --- a/GarmentFactory/GarmentFactoryView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace GarmentFactoryView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/GarmentFactory/GarmentFactoryView/Form1.cs b/GarmentFactory/GarmentFactoryView/Form1.cs deleted file mode 100644 index 8377403..0000000 --- a/GarmentFactory/GarmentFactoryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace GarmentFactoryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/GarmentFactory/GarmentFactoryView/FormComponent.Designer.cs b/GarmentFactory/GarmentFactoryView/FormComponent.Designer.cs new file mode 100644 index 0000000..879a21f --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormComponent.Designer.cs @@ -0,0 +1,123 @@ +namespace GarmentFactoryView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название :"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(16, 52); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(52, 20); + labelCost.TabIndex = 1; + labelCost.Text = "Цена :"; + // + // textBoxName + // + textBoxName.Location = new Point(104, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(104, 48); + textBoxCost.Margin = new Padding(5, 4, 5, 4); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(147, 27); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(185, 95); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 95); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(416, 147); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormComponent.cs b/GarmentFactory/GarmentFactoryView/FormComponent.cs new file mode 100644 index 0000000..fbdde46 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormComponent.cs @@ -0,0 +1,93 @@ +using GarmentFactoryContracts.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; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Receiving component"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Component retrieval error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + 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/GarmentFactory/GarmentFactoryView/Form1.resx b/GarmentFactory/GarmentFactoryView/FormComponent.resx similarity index 93% rename from GarmentFactory/GarmentFactoryView/Form1.resx rename to GarmentFactory/GarmentFactoryView/FormComponent.resx index 1af7de1..af32865 100644 --- a/GarmentFactory/GarmentFactoryView/Form1.resx +++ b/GarmentFactory/GarmentFactoryView/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/GarmentFactory/GarmentFactoryView/FormComponents.Designer.cs b/GarmentFactory/GarmentFactoryView/FormComponents.Designer.cs new file mode 100644 index 0000000..d025594 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormComponents.Designer.cs @@ -0,0 +1,123 @@ +namespace GarmentFactoryView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(466, 480); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(491, 21); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(101, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(491, 84); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(101, 36); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonDel + // + buttonDel.Location = new Point(491, 153); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(101, 36); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(491, 223); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(101, 36); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(618, 480); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormComponents.cs b/GarmentFactory/GarmentFactoryView/FormComponents.cs new file mode 100644 index 0000000..feb992d --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormComponents.cs @@ -0,0 +1,121 @@ +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; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + 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 ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + 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 ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormComponents.resx b/GarmentFactory/GarmentFactoryView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormCreateOrder.Designer.cs b/GarmentFactory/GarmentFactoryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..1f9e5b4 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormCreateOrder.Designer.cs @@ -0,0 +1,147 @@ +namespace GarmentFactoryView +{ + 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() + { + labelTextile = new Label(); + labelCount = new Label(); + labelSum = new Label(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + comboBoxTextile = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelTextile + // + labelTextile.AutoSize = true; + labelTextile.Location = new Point(15, 9); + labelTextile.Name = "labelTextile"; + labelTextile.Size = new Size(75, 20); + labelTextile.TabIndex = 0; + labelTextile.Text = "Изделие :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(15, 51); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(15, 92); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(62, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма :"; + // + // textBoxCount + // + textBoxCount.Location = new Point(112, 51); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(293, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.BackColor = SystemColors.Control; + textBoxSum.Location = new Point(112, 92); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(293, 27); + textBoxSum.TabIndex = 5; + // + // comboBoxTextile + // + comboBoxTextile.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTextile.FormattingEnabled = true; + comboBoxTextile.Location = new Point(112, 9); + comboBoxTextile.Name = "comboBoxTextile"; + comboBoxTextile.Size = new Size(293, 28); + comboBoxTextile.TabIndex = 6; + comboBoxTextile.SelectedIndexChanged += ComboBoxTextile_SelectedIndexChanged; + // + // buttonSave + // + buttonSave.Location = new Point(184, 131); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(291, 131); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 181); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxTextile); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelTextile); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelTextile; + private Label labelCount; + private Label labelSum; + private TextBox textBoxCount; + private TextBox textBoxSum; + private ComboBox comboBoxTextile; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormCreateOrder.cs b/GarmentFactory/GarmentFactoryView/FormCreateOrder.cs new file mode 100644 index 0000000..ae897d5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormCreateOrder.cs @@ -0,0 +1,135 @@ +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; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ITextileLogic _logicT; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ITextileLogic +logicT, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicT = logicT; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var textileList = _logicT.ReadList(null); + if (textileList != null) + { + comboBoxTextile.DisplayMember = "TextileName"; + comboBoxTextile.ValueMember = "Id"; + comboBoxTextile.DataSource = textileList; + comboBoxTextile.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при загрузке изделия для заказаr"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxTextile.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxTextile.SelectedValue); + var product = _logicT.ReadElement(new TextileSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + + private void ComboBoxTextile_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void TextBoxCount_TextChanged(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 (comboBoxTextile.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormCreateOrder.resx b/GarmentFactory/GarmentFactoryView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs b/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs new file mode 100644 index 0000000..963267c --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs @@ -0,0 +1,180 @@ +namespace GarmentFactoryView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделиеToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonUpd = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1178, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // изделиеToolStripMenuItem + // + изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; + изделиеToolStripMenuItem.Size = new Size(224, 26); + изделиеToolStripMenuItem.Text = "Изделие"; + изделиеToolStripMenuItem.Click += ИзделиеToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 37); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(944, 427); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(965, 77); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(199, 36); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(965, 149); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(199, 36); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(963, 222); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(199, 36); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(965, 305); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(199, 36); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(965, 384); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(197, 36); + buttonUpd.TabIndex = 6; + buttonUpd.Text = "Обновить список"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1178, 463); + Controls.Add(buttonUpd); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Текстильная фабрика"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделиеToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormMain.cs b/GarmentFactory/GarmentFactoryView/FormMain.cs new file mode 100644 index 0000000..b5d7292 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMain.cs @@ -0,0 +1,159 @@ +using GarmentFactoryContracts.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; +using GarmentFactoryContracts.BindingModels; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + 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["TextileId"].Visible = false; + dataGridView.Columns["TextileName"].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(FormTextiles)); + if (service is FormTextiles form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormMain.resx b/GarmentFactory/GarmentFactoryView/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/GarmentFactory/GarmentFactoryView/FormTextile.Designer.cs b/GarmentFactory/GarmentFactoryView/FormTextile.Designer.cs new file mode 100644 index 0000000..2c0555b --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextile.Designer.cs @@ -0,0 +1,243 @@ +namespace GarmentFactoryView +{ + partial class FormTextile + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelPrice = new Label(); + labelName = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonUpd = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + buttonDel = new Button(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(21, 54); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(90, 20); + labelPrice.TabIndex = 0; + labelPrice.Text = "Стоимость :"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(21, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 1; + labelName.Text = "Название :"; + // + // textBoxName + // + textBoxName.Location = new Point(108, 12); + textBoxName.Name = "textBoxName"; + textBoxName.RightToLeft = RightToLeft.No; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(108, 51); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(169, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonEdit); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Location = new Point(16, 89); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(638, 384); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(3, 23); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RightToLeft = RightToLeft.No; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(474, 358); + dataGridView.TabIndex = 4; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // buttonUpd + // + buttonUpd.Location = new Point(514, 234); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(101, 36); + buttonUpd.TabIndex = 3; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(514, 106); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(101, 36); + buttonEdit.TabIndex = 1; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(514, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(101, 36); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(514, 169); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(101, 36); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(410, 488); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(517, 488); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormTextile + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(670, 536); + Controls.Add(buttonCancel); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(buttonSave); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(labelPrice); + Name = "FormTextile"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Изделие"; + Load += FormTextile_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelPrice; + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextile.cs b/GarmentFactory/GarmentFactoryView/FormTextile.cs new file mode 100644 index 0000000..bc1f955 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextile.cs @@ -0,0 +1,227 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryDataModels.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; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormTextile : Form + { + private readonly ILogger _logger; + private readonly ITextileLogic _logic; + private int? _id; + private Dictionary _textileComponents; + public int Id { set { _id = value; } } + public FormTextile(ILogger logger, ITextileLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _textileComponents = new Dictionary(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_textileComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _textileComponents) + { + 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 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 (_textileComponents == null || _textileComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new TextileBindingModel + { + Id = _id ?? 0, + TextileName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + TextileComponents = _textileComponents + }; + 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 void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTextileComponent)); + if (service is FormTextileComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_textileComponents.ContainsKey(form.Id)) + { + _textileComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _textileComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormTextileComponent)); + if (service is FormTextileComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _textileComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _textileComponents[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); + _textileComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormTextile_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new TextileSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.TextileName; + textBoxPrice.Text = view.Price.ToString(); + _textileComponents = view.TextileComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _textileComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormTextile.resx b/GarmentFactory/GarmentFactoryView/FormTextile.resx new file mode 100644 index 0000000..fcacbcb --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextile.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextileComponent.Designer.cs b/GarmentFactory/GarmentFactoryView/FormTextileComponent.Designer.cs new file mode 100644 index 0000000..a5ac23c --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace GarmentFactoryView +{ + partial class FormTextileComponent + { + /// + /// 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() + { + comboBoxComponent = new ComboBox(); + labelComponent = new Label(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(115, 16); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(285, 28); + comboBoxComponent.TabIndex = 0; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 19); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(95, 20); + labelComponent.TabIndex = 1; + labelComponent.Text = "Компонент :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 64); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество :"; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 61); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(285, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(183, 100); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(290, 100); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormTextileComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(426, 148); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(comboBoxComponent); + Name = "FormTextileComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private Label labelComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextileComponent.cs b/GarmentFactory/GarmentFactoryView/FormTextileComponent.cs new file mode 100644 index 0000000..d511715 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileComponent.cs @@ -0,0 +1,93 @@ +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; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; + +namespace GarmentFactoryView +{ + public partial class FormTextileComponent : 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 FormTextileComponent(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/GarmentFactory/GarmentFactoryView/FormTextileComponent.resx b/GarmentFactory/GarmentFactoryView/FormTextileComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextiles.Designer.cs b/GarmentFactory/GarmentFactoryView/FormTextiles.Designer.cs new file mode 100644 index 0000000..52a7983 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextiles.Designer.cs @@ -0,0 +1,123 @@ +namespace GarmentFactoryView +{ + partial class FormTextiles + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(466, 480); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(494, 19); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(101, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(494, 75); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(103, 36); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonDel + // + buttonDel.Location = new Point(494, 133); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(101, 36); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(494, 191); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(101, 36); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormTextiles + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(618, 480); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormTextiles"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Изделие"; + Load += FormTextile_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextiles.cs b/GarmentFactory/GarmentFactoryView/FormTextiles.cs new file mode 100644 index 0000000..66c4908 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextiles.cs @@ -0,0 +1,114 @@ +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + + +namespace GarmentFactoryView +{ + public partial class FormTextiles : Form + { + private readonly ILogger _logger; + + private readonly ITextileLogic _logic; + + public FormTextiles(ILogger logger, ITextileLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormTextile_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["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["TextileComponents"].Visible = false; + } + _logger.LogInformation("Загрузка изделия"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTextile)); + if (service is FormTextile form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTextile)); + if (service is FormTextile 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 TextileBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormTextiles.resx b/GarmentFactory/GarmentFactoryView/FormTextiles.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextiles.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj b/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj index b57c89e..8417823 100644 --- a/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj +++ b/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/Program.cs b/GarmentFactory/GarmentFactoryView/Program.cs index 6ea88aa..f0ede54 100644 --- a/GarmentFactory/GarmentFactoryView/Program.cs +++ b/GarmentFactory/GarmentFactoryView/Program.cs @@ -1,17 +1,48 @@ +using GarmentFactoryBusinessLogic.BusinessLogics; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; + namespace GarmentFactoryView { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { - // 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/GarmentFactory/GarmentFactoryView/nlog.config b/GarmentFactory/GarmentFactoryView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file