From 4711030502838727f7d60ff7f3a0eaab39ae4b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= <Илья@WIN-RANNDDD> Date: Sat, 10 Feb 2024 13:06:58 +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=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20(=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IceCreamShop/IceCreamShop.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 115 ++++++++ .../BusinessLogics/IceCreamLogic.cs | 119 +++++++++ .../BusinessLogics/OrderLogic.cs | 129 +++++++++ .../IceCreamShopBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 13 + .../BindingModels/IceCreamBindingModel.cs | 19 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../IComponentLogic.cs | 19 ++ .../BusinessLogicsContracts/IIceCreamLogic.cs | 19 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 19 ++ .../IceCreamShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 9 + .../SearchModels/IceCreamSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IIceCreamStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 16 ++ .../ViewModels/IceCreamViewModel.cs | 22 ++ .../ViewModels/OrderViewModel.cs | 32 +++ .../Enums/OrderStatus.cs | 15 ++ IceCreamShop/IceCreamShopDataModels/IId.cs | 7 + .../IceCreamShopDataModels.csproj | 9 + .../Models/IComponentModel.cs | 9 + .../Models/IIceCreamModel.cs | 11 + .../Models/IOrderModel.cs | 19 ++ .../DataListSingleton.cs | 31 +++ .../IceCreamShopListImplement.csproj | 14 + .../Implements/ComponentStorage.cs | 109 ++++++++ .../Implements/IceCreamStorage.cs | 109 ++++++++ .../Implements/OrderStorage.cs | 117 +++++++++ .../Models/Component.cs | 46 ++++ .../Models/IceCream.cs | 55 ++++ .../IceCreamShopListImplement/Models/Order.cs | 63 +++++ .../IceCreamShopView/Form1.Designer.cs | 39 --- IceCreamShop/IceCreamShopView/Form1.cs | 10 - .../FormComponent.Designer.cs | 122 +++++++++ .../IceCreamShopView/FormComponent.cs | 85 ++++++ .../IceCreamShopView/FormComponent.resx | 120 +++++++++ .../IceCreamShopView/FormComponents.cs | 103 ++++++++ .../FormComponents.designer.cs | 127 +++++++++ .../{Form1.resx => FormComponents.resx} | 0 .../FormCreateOrder.Designer.cs | 154 +++++++++++ .../IceCreamShopView/FormCreateOrder.cs | 120 +++++++++ .../IceCreamShopView/FormCreateOrder.resx | 120 +++++++++ IceCreamShop/IceCreamShopView/FormIceCream.cs | 209 +++++++++++++++ .../IceCreamShopView/FormIceCream.designer.cs | 248 ++++++++++++++++++ .../IceCreamShopView/FormIceCream.resx | 120 +++++++++ .../FormIceCreamComponent.Designer.cs | 126 +++++++++ .../IceCreamShopView/FormIceCreamComponent.cs | 70 +++++ .../FormIceCreamComponent.resx | 120 +++++++++ .../FormIceCreams.Designer.cs | 126 +++++++++ .../IceCreamShopView/FormIceCreams.cs | 104 ++++++++ .../IceCreamShopView/FormIceCreams.resx | 120 +++++++++ IceCreamShop/IceCreamShopView/FormMain.cs | 148 +++++++++++ .../IceCreamShopView/FormMain.designer.cs | 192 ++++++++++++++ IceCreamShop/IceCreamShopView/FormMain.resx | 123 +++++++++ .../IceCreamShopView/IceCreamShopView.csproj | 22 ++ IceCreamShop/IceCreamShopView/Program.cs | 40 ++- IceCreamShop/IceCreamShopView/nlog.config | 15 ++ 61 files changed, 4034 insertions(+), 51 deletions(-) create mode 100644 IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/IceCreamLogic.cs create mode 100644 IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 IceCreamShop/IceCreamShopBusinessLogic/IceCreamShopBusinessLogic.csproj create mode 100644 IceCreamShop/IceCreamShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/BindingModels/IceCreamBindingModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IIceCreamLogic.cs create mode 100644 IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 IceCreamShop/IceCreamShopContracts/IceCreamShopContracts.csproj create mode 100644 IceCreamShop/IceCreamShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/SearchModels/IceCreamSearchModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 IceCreamShop/IceCreamShopContracts/StoragesContracts/IIceCreamStorage.cs create mode 100644 IceCreamShop/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 IceCreamShop/IceCreamShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/ViewModels/IceCreamViewModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs create mode 100644 IceCreamShop/IceCreamShopDataModels/Enums/OrderStatus.cs create mode 100644 IceCreamShop/IceCreamShopDataModels/IId.cs create mode 100644 IceCreamShop/IceCreamShopDataModels/IceCreamShopDataModels.csproj create mode 100644 IceCreamShop/IceCreamShopDataModels/Models/IComponentModel.cs create mode 100644 IceCreamShop/IceCreamShopDataModels/Models/IIceCreamModel.cs create mode 100644 IceCreamShop/IceCreamShopDataModels/Models/IOrderModel.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/IceCreamShopListImplement.csproj create mode 100644 IceCreamShop/IceCreamShopListImplement/Implements/ComponentStorage.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/Implements/IceCreamStorage.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/Models/Component.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/Models/IceCream.cs create mode 100644 IceCreamShop/IceCreamShopListImplement/Models/Order.cs delete mode 100644 IceCreamShop/IceCreamShopView/Form1.Designer.cs delete mode 100644 IceCreamShop/IceCreamShopView/Form1.cs create mode 100644 IceCreamShop/IceCreamShopView/FormComponent.Designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormComponent.cs create mode 100644 IceCreamShop/IceCreamShopView/FormComponent.resx create mode 100644 IceCreamShop/IceCreamShopView/FormComponents.cs create mode 100644 IceCreamShop/IceCreamShopView/FormComponents.designer.cs rename IceCreamShop/IceCreamShopView/{Form1.resx => FormComponents.resx} (100%) create mode 100644 IceCreamShop/IceCreamShopView/FormCreateOrder.Designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormCreateOrder.cs create mode 100644 IceCreamShop/IceCreamShopView/FormCreateOrder.resx create mode 100644 IceCreamShop/IceCreamShopView/FormIceCream.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCream.designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCream.resx create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreamComponent.Designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreamComponent.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreamComponent.resx create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreams.Designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreams.cs create mode 100644 IceCreamShop/IceCreamShopView/FormIceCreams.resx create mode 100644 IceCreamShop/IceCreamShopView/FormMain.cs create mode 100644 IceCreamShop/IceCreamShopView/FormMain.designer.cs create mode 100644 IceCreamShop/IceCreamShopView/FormMain.resx create mode 100644 IceCreamShop/IceCreamShopView/nlog.config diff --git a/IceCreamShop/IceCreamShop.sln b/IceCreamShop/IceCreamShop.sln index 5da59d7..d689288 100644 --- a/IceCreamShop/IceCreamShop.sln +++ b/IceCreamShop/IceCreamShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopView", "IceCreamShopView\IceCreamShopView.csproj", "{03715F64-3660-4241-98A6-160D1B363F5D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopView", "IceCreamShopView\IceCreamShopView.csproj", "{03715F64-3660-4241-98A6-160D1B363F5D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopDataModels", "IceCreamShopDataModels\IceCreamShopDataModels.csproj", "{477F5A93-5D0A-4F2B-BE46-0205B11D4F1F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopContracts", "IceCreamShopContracts\IceCreamShopContracts.csproj", "{C8908C5F-7AEB-4899-AAB4-041FEEB9E0C7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopListImplement", "IceCreamShopListImplement\IceCreamShopListImplement.csproj", "{326CDB04-8BD3-4DBB-9EE5-78CFECC21E5E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopBusinessLogic", "IceCreamShopBusinessLogic\IceCreamShopBusinessLogic.csproj", "{392488A9-9B1E-4DDA-95CE-C2FDC954DEE6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {03715F64-3660-4241-98A6-160D1B363F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU {03715F64-3660-4241-98A6-160D1B363F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU {03715F64-3660-4241-98A6-160D1B363F5D}.Release|Any CPU.Build.0 = Release|Any CPU + {477F5A93-5D0A-4F2B-BE46-0205B11D4F1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {477F5A93-5D0A-4F2B-BE46-0205B11D4F1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {477F5A93-5D0A-4F2B-BE46-0205B11D4F1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {477F5A93-5D0A-4F2B-BE46-0205B11D4F1F}.Release|Any CPU.Build.0 = Release|Any CPU + {C8908C5F-7AEB-4899-AAB4-041FEEB9E0C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8908C5F-7AEB-4899-AAB4-041FEEB9E0C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8908C5F-7AEB-4899-AAB4-041FEEB9E0C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8908C5F-7AEB-4899-AAB4-041FEEB9E0C7}.Release|Any CPU.Build.0 = Release|Any CPU + {326CDB04-8BD3-4DBB-9EE5-78CFECC21E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {326CDB04-8BD3-4DBB-9EE5-78CFECC21E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {326CDB04-8BD3-4DBB-9EE5-78CFECC21E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {326CDB04-8BD3-4DBB-9EE5-78CFECC21E5E}.Release|Any CPU.Build.0 = Release|Any CPU + {392488A9-9B1E-4DDA-95CE-C2FDC954DEE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {392488A9-9B1E-4DDA-95CE-C2FDC954DEE6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {392488A9-9B1E-4DDA-95CE-C2FDC954DEE6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {392488A9-9B1E-4DDA-95CE-C2FDC954DEE6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..574f543 --- /dev/null +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,115 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName: {ComponentName}. Id: {Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/IceCreamLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/IceCreamLogic.cs new file mode 100644 index 0000000..2b058c9 --- /dev/null +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/IceCreamLogic.cs @@ -0,0 +1,119 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopBusinessLogic.BusinessLogics +{ + public class IceCreamLogic : IIceCreamLogic + { + private readonly ILogger _logger; + + private readonly IIceCreamStorage _iceCreamStorage; + + public IceCreamLogic(ILogger logger, IIceCreamStorage iceCreamStorage) + { + _logger = logger; + _iceCreamStorage = iceCreamStorage; + } + + public List? ReadList(IceCreamSearchModel? model) + { + _logger.LogInformation("ReadList. IceCreamName: {IceCreamName}. Id: {Id}", model?.IceCreamName, model?.Id); + var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public IceCreamViewModel? ReadElement(IceCreamSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IceCreamName: {IceCreamName}. Id: {Id}", model.IceCreamName, model.Id); + var element = _iceCreamStorage.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(IceCreamBindingModel model) + { + CheckModel(model); + if (_iceCreamStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(IceCreamBindingModel model) + { + CheckModel(model); + if (_iceCreamStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(IceCreamBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_iceCreamStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(IceCreamBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IceCreamName)) + { + throw new ArgumentNullException("Нет названия мороженого", nameof(model.IceCreamName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price)); + } + if (model.IceCreamComponents == null || model.IceCreamComponents.Count == 0) + { + throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); + } + _logger.LogInformation("IceCream. IceCreamName: {IceCreamName}. Price: {Price}. Id: {Id}", model.IceCreamName, model.Price, model.Id); + var element = _iceCreamStorage.GetElement(new IceCreamSearchModel + { + IceCreamName = model.IceCreamName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Мороженое с таким названием уже есть"); + } + } + } +} diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..b8037ea --- /dev/null +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,129 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopBusinessLogic.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.IceCreamId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.IceCreamId)); + } + 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}. IceCreamId: {IceCreamId}. IceCreamCount: {Count}", model.Id, model.Sum, + model.IceCreamId, 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.IceCreamId = order.IceCreamId; + 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/IceCreamShop/IceCreamShopBusinessLogic/IceCreamShopBusinessLogic.csproj b/IceCreamShop/IceCreamShopBusinessLogic/IceCreamShopBusinessLogic.csproj new file mode 100644 index 0000000..dd023a7 --- /dev/null +++ b/IceCreamShop/IceCreamShopBusinessLogic/IceCreamShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/IceCreamShop/IceCreamShopContracts/BindingModels/ComponentBindingModel.cs b/IceCreamShop/IceCreamShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..61c6fdf --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,13 @@ +using IceCreamShopDataModels.Models; + +namespace IceCreamShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + + public string ComponentName { get; set; } = string.Empty; + + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BindingModels/IceCreamBindingModel.cs b/IceCreamShop/IceCreamShopContracts/BindingModels/IceCreamBindingModel.cs new file mode 100644 index 0000000..560801b --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BindingModels/IceCreamBindingModel.cs @@ -0,0 +1,19 @@ +using IceCreamShopDataModels.Models; + +namespace IceCreamShopContracts.BindingModels +{ + public class IceCreamBindingModel : IIceCreamModel + { + public int Id { get; set; } + + public string IceCreamName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary IceCreamComponents + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BindingModels/OrderBindingModel.cs b/IceCreamShop/IceCreamShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..2b0c0c1 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using IceCreamShopDataModels.Enums; +using IceCreamShopDataModels.Models; + +namespace IceCreamShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + + public int IceCreamId { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..56c830e --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,19 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + + ComponentViewModel? ReadElement(ComponentSearchModel model); + + bool Create(ComponentBindingModel model); + + bool Update(ComponentBindingModel model); + + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IIceCreamLogic.cs b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IIceCreamLogic.cs new file mode 100644 index 0000000..c9b329f --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IIceCreamLogic.cs @@ -0,0 +1,19 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.BusinessLogicsContracts +{ + public interface IIceCreamLogic + { + List? ReadList(IceCreamSearchModel? model); + + IceCreamViewModel? ReadElement(IceCreamSearchModel model); + + bool Create(IceCreamBindingModel model); + + bool Update(IceCreamBindingModel model); + + bool Delete(IceCreamBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..3f8ec1e --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,19 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + + bool CreateOrder(OrderBindingModel model); + + bool TakeOrderInWork(OrderBindingModel model); + + bool FinishOrder(OrderBindingModel model); + + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/IceCreamShopContracts.csproj b/IceCreamShop/IceCreamShopContracts/IceCreamShopContracts.csproj new file mode 100644 index 0000000..347c056 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/IceCreamShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/IceCreamShop/IceCreamShopContracts/SearchModels/ComponentSearchModel.cs b/IceCreamShop/IceCreamShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..39181da --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace IceCreamShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/SearchModels/IceCreamSearchModel.cs b/IceCreamShop/IceCreamShopContracts/SearchModels/IceCreamSearchModel.cs new file mode 100644 index 0000000..7d05d83 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/SearchModels/IceCreamSearchModel.cs @@ -0,0 +1,9 @@ +namespace IceCreamShopContracts.SearchModels +{ + public class IceCreamSearchModel + { + public int? Id { get; set; } + + public string? IceCreamName { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/SearchModels/OrderSearchModel.cs b/IceCreamShop/IceCreamShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..0e77cbe --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace IceCreamShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/StoragesContracts/IComponentStorage.cs b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..f3cca96 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + + List GetFilteredList(ComponentSearchModel model); + + ComponentViewModel? GetElement(ComponentSearchModel model); + + ComponentViewModel? Insert(ComponentBindingModel model); + + ComponentViewModel? Update(ComponentBindingModel model); + + ComponentViewModel? Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/StoragesContracts/IIceCreamStorage.cs b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IIceCreamStorage.cs new file mode 100644 index 0000000..f32dedc --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IIceCreamStorage.cs @@ -0,0 +1,21 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.StoragesContracts +{ + public interface IIceCreamStorage + { + List GetFullList(); + + List GetFilteredList(IceCreamSearchModel model); + + IceCreamViewModel? GetElement(IceCreamSearchModel model); + + IceCreamViewModel? Insert(IceCreamBindingModel model); + + IceCreamViewModel? Update(IceCreamBindingModel model); + + IceCreamViewModel? Delete(IceCreamBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..3d02a24 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; + +namespace IceCreamShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + + List GetFilteredList(OrderSearchModel model); + + OrderViewModel? GetElement(OrderSearchModel model); + + OrderViewModel? Insert(OrderBindingModel model); + + OrderViewModel? Update(OrderBindingModel model); + + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/ComponentViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..d2cce00 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,16 @@ +using IceCreamShopDataModels.Models; +using System.ComponentModel; + +namespace IceCreamShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/IceCreamViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/IceCreamViewModel.cs new file mode 100644 index 0000000..e983448 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/IceCreamViewModel.cs @@ -0,0 +1,22 @@ +using IceCreamShopDataModels.Models; +using System.ComponentModel; + +namespace IceCreamShopContracts.ViewModels +{ + public class IceCreamViewModel : IIceCreamModel + { + public int Id { get; set; } + + [DisplayName("Название мороженого")] + public string IceCreamName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary IceCreamComponents + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..3739b65 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,32 @@ +using IceCreamShopDataModels.Enums; +using IceCreamShopDataModels.Models; +using System.ComponentModel; + +namespace IceCreamShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int IceCreamId { get; set; } + + [DisplayName("Мороженое")] + public string IceCreamName { 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/IceCreamShop/IceCreamShopDataModels/Enums/OrderStatus.cs b/IceCreamShop/IceCreamShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..c1a6e80 --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,15 @@ +namespace IceCreamShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopDataModels/IId.cs b/IceCreamShop/IceCreamShopDataModels/IId.cs new file mode 100644 index 0000000..3984bc3 --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace IceCreamShopDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopDataModels/IceCreamShopDataModels.csproj b/IceCreamShop/IceCreamShopDataModels/IceCreamShopDataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/IceCreamShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/IceCreamShop/IceCreamShopDataModels/Models/IComponentModel.cs b/IceCreamShop/IceCreamShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..94eeab2 --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,9 @@ +namespace IceCreamShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopDataModels/Models/IIceCreamModel.cs b/IceCreamShop/IceCreamShopDataModels/Models/IIceCreamModel.cs new file mode 100644 index 0000000..785b42e --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/Models/IIceCreamModel.cs @@ -0,0 +1,11 @@ +namespace IceCreamShopDataModels.Models +{ + public interface IIceCreamModel : IId + { + string IceCreamName { get; } + + double Price { get; } + + Dictionary IceCreamComponents { get; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopDataModels/Models/IOrderModel.cs b/IceCreamShop/IceCreamShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..1495071 --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using IceCreamShopDataModels.Enums; + +namespace IceCreamShopDataModels.Models +{ + public interface IOrderModel : IId + { + int IceCreamId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs b/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..e3cac9e --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using IceCreamShopListImplement.Models; + +namespace IceCreamShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + + public List Components { get; set; } + + public List Orders { get; set; } + + public List IceCreams { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + IceCreams = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/IceCreamShopListImplement.csproj b/IceCreamShop/IceCreamShopListImplement/IceCreamShopListImplement.csproj new file mode 100644 index 0000000..0689277 --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/IceCreamShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/ComponentStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..4b1fce3 --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,109 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopListImplement.Models; + +namespace IceCreamShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/IceCreamStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/IceCreamStorage.cs new file mode 100644 index 0000000..f30e905 --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Implements/IceCreamStorage.cs @@ -0,0 +1,109 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopListImplement.Models; + +namespace IceCreamShopListImplement.Implements +{ + public class IceCreamStorage : IIceCreamStorage + { + private readonly DataListSingleton _source; + + public IceCreamStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var iceCream in _source.IceCreams) + { + result.Add(iceCream.GetViewModel); + } + return result; + } + + public List GetFilteredList(IceCreamSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.IceCreamName)) + { + return result; + } + foreach (var iceCream in _source.IceCreams) + { + if (iceCream.IceCreamName.Contains(model.IceCreamName)) + { + result.Add(iceCream.GetViewModel); + } + } + return result; + } + + public IceCreamViewModel? GetElement(IceCreamSearchModel model) + { + if (string.IsNullOrEmpty(model.IceCreamName) && !model.Id.HasValue) + { + return null; + } + foreach (var iceCream in _source.IceCreams) + { + if ((!string.IsNullOrEmpty(model.IceCreamName) && + iceCream.IceCreamName == model.IceCreamName) || + (model.Id.HasValue && iceCream.Id == model.Id)) + { + return iceCream.GetViewModel; + } + } + return null; + } + + public IceCreamViewModel? Insert(IceCreamBindingModel model) + { + model.Id = 1; + foreach (var iceCream in _source.IceCreams) + { + if (model.Id <= iceCream.Id) + { + model.Id = iceCream.Id + 1; + } + } + var newIceCream = IceCream.Create(model); + if (newIceCream == null) + { + return null; + } + _source.IceCreams.Add(newIceCream); + return newIceCream.GetViewModel; + } + + public IceCreamViewModel? Update(IceCreamBindingModel model) + { + foreach (var iceCream in _source.IceCreams) + { + if (iceCream.Id == model.Id) + { + iceCream.Update(model); + return iceCream.GetViewModel; + } + } + return null; + } + + public IceCreamViewModel? Delete(IceCreamBindingModel model) + { + for (int i = 0; i < _source.IceCreams.Count; ++i) + { + if (_source.IceCreams[i].Id == model.Id) + { + var element = _source.IceCreams[i]; + _source.IceCreams.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..10ef37e --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,117 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopListImplement.Models; + +namespace IceCreamShopListImplement.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(AddIceCreamName(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(AddIceCreamName(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 AddIceCreamName(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 AddIceCreamName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddIceCreamName(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 AddIceCreamName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AddIceCreamName(OrderViewModel model) + { + var selectedIceCream = _source.IceCreams.Find(iceCream => iceCream.Id == model.IceCreamId); + if (selectedIceCream != null) + { + model.IceCreamName = selectedIceCream.IceCreamName; + } + return model; + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Models/Component.cs b/IceCreamShop/IceCreamShopListImplement/Models/Component.cs new file mode 100644 index 0000000..1e2aa0d --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Models; + +namespace IceCreamShopListImplement.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 + }; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Models/IceCream.cs b/IceCreamShop/IceCreamShopListImplement/Models/IceCream.cs new file mode 100644 index 0000000..3ab643a --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Models/IceCream.cs @@ -0,0 +1,55 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Models; + +namespace IceCreamShopListImplement.Models +{ + public class IceCream : IIceCreamModel + { + public int Id { get; private set; } + + public string IceCreamName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary IceCreamComponents + { + get; + private set; + } = new Dictionary(); + + public static IceCream? Create(IceCreamBindingModel? model) + { + if (model == null) + { + return null; + } + return new IceCream() + { + Id = model.Id, + IceCreamName = model.IceCreamName, + Price = model.Price, + IceCreamComponents = model.IceCreamComponents + }; + } + + public void Update(IceCreamBindingModel? model) + { + if (model == null) + { + return; + } + IceCreamName = model.IceCreamName; + Price = model.Price; + IceCreamComponents = model.IceCreamComponents; + } + + public IceCreamViewModel GetViewModel => new() + { + Id = Id, + IceCreamName = IceCreamName, + Price = Price, + IceCreamComponents = IceCreamComponents + }; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Models/Order.cs b/IceCreamShop/IceCreamShopListImplement/Models/Order.cs new file mode 100644 index 0000000..cfc3fde --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Models/Order.cs @@ -0,0 +1,63 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Models; +using IceCreamShopDataModels.Enums; + +namespace IceCreamShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int IceCreamId { 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, + IceCreamId = model.IceCreamId, + 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, + IceCreamId = IceCreamId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/Form1.Designer.cs b/IceCreamShop/IceCreamShopView/Form1.Designer.cs deleted file mode 100644 index bce5219..0000000 --- a/IceCreamShop/IceCreamShopView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace IceCreamShopView -{ - 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/IceCreamShop/IceCreamShopView/Form1.cs b/IceCreamShop/IceCreamShopView/Form1.cs deleted file mode 100644 index 3e81c41..0000000 --- a/IceCreamShop/IceCreamShopView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace IceCreamShopView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/IceCreamShop/IceCreamShopView/FormComponent.Designer.cs b/IceCreamShop/IceCreamShopView/FormComponent.Designer.cs new file mode 100644 index 0000000..b15d0b3 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormComponent.Designer.cs @@ -0,0 +1,122 @@ +namespace IceCreamShopView +{ + 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(14, 10); + labelName.Name = "labelName"; + labelName.Size = new Size(65, 15); + labelName.TabIndex = 0; + labelName.Text = "Название :"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(14, 39); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(41, 15); + labelCost.TabIndex = 1; + labelCost.Text = "Цена :"; + // + // textBoxName + // + textBoxName.Location = new Point(91, 7); + textBoxName.Margin = new Padding(4, 3, 4, 3); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(252, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(91, 36); + textBoxCost.Margin = new Padding(4, 3, 4, 3); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(129, 23); + textBoxCost.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(162, 71); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(260, 71); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(364, 110); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент"; + 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/IceCreamShop/IceCreamShopView/FormComponent.cs b/IceCreamShop/IceCreamShopView/FormComponent.cs new file mode 100644 index 0000000..84b9db4 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormComponent.cs @@ -0,0 +1,85 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Receiving component"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Component retrieval error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving component"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Component saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormComponent.resx b/IceCreamShop/IceCreamShopView/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormComponent.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/IceCreamShop/IceCreamShopView/FormComponents.cs b/IceCreamShop/IceCreamShopView/FormComponents.cs new file mode 100644 index 0000000..4d91b67 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormComponents.cs @@ -0,0 +1,103 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Components loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Components loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of component"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Component deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormComponents.designer.cs b/IceCreamShop/IceCreamShopView/FormComponents.designer.cs new file mode 100644 index 0000000..8072482 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormComponents.designer.cs @@ -0,0 +1,127 @@ +namespace IceCreamShopView +{ + 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() + { + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 0; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormComponents"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/Form1.resx b/IceCreamShop/IceCreamShopView/FormComponents.resx similarity index 100% rename from IceCreamShop/IceCreamShopView/Form1.resx rename to IceCreamShop/IceCreamShopView/FormComponents.resx diff --git a/IceCreamShop/IceCreamShopView/FormCreateOrder.Designer.cs b/IceCreamShop/IceCreamShopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..b534cbf --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormCreateOrder.Designer.cs @@ -0,0 +1,154 @@ +namespace IceCreamShopView +{ + 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() + { + labelIceCream = new Label(); + comboBoxIceCream = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + labelSum = new Label(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelIceCream + // + labelIceCream.AutoSize = true; + labelIceCream.Location = new Point(14, 10); + labelIceCream.Margin = new Padding(4, 0, 4, 0); + labelIceCream.Name = "labelIceCream"; + labelIceCream.Size = new Size(80, 15); + labelIceCream.TabIndex = 1; + labelIceCream.Text = "Мороженое :"; + // + // comboBoxIceCream + // + comboBoxIceCream.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxIceCream.FormattingEnabled = true; + comboBoxIceCream.Location = new Point(102, 7); + comboBoxIceCream.Margin = new Padding(4, 3, 4, 3); + comboBoxIceCream.Name = "comboBoxIceCream"; + comboBoxIceCream.Size = new Size(252, 23); + comboBoxIceCream.TabIndex = 2; + comboBoxIceCream.SelectedIndexChanged += ComboBoxIceCream_SelectedIndexChanged; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(14, 42); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 3; + labelCount.Text = "Количество :"; + // + // textBoxCount + // + textBoxCount.Location = new Point(102, 38); + textBoxCount.Margin = new Padding(4, 3, 4, 3); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(252, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(14, 72); + labelSum.Margin = new Padding(4, 0, 4, 0); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(51, 15); + labelSum.TabIndex = 5; + labelSum.Text = "Сумма :"; + // + // textBoxSum + // + textBoxSum.Location = new Point(102, 68); + textBoxSum.Margin = new Padding(4, 3, 4, 3); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(252, 23); + textBoxSum.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(161, 98); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(255, 98); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(371, 136); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(labelSum); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxIceCream); + Controls.Add(labelIceCream); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelIceCream; + private ComboBox comboBoxIceCream; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSum; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormCreateOrder.cs b/IceCreamShop/IceCreamShopView/FormCreateOrder.cs new file mode 100644 index 0000000..f93a15b --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormCreateOrder.cs @@ -0,0 +1,120 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using System.Windows.Forms; + +namespace IceCreamShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IIceCreamLogic _logicIC; + + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IIceCreamLogic logicIC, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicIC = logicIC; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Loading ice cream for order"); + try + { + var iceCreamList = _logicIC.ReadList(null); + if (iceCreamList != null) + { + comboBoxIceCream.DisplayMember = "IceCreamName"; + comboBoxIceCream.ValueMember = "Id"; + comboBoxIceCream.DataSource = iceCreamList; + comboBoxIceCream.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading ice cream for order"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxIceCream.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxIceCream.SelectedValue); + var product = _logicIC.ReadElement(new IceCreamSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Calculation of order sum"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Calculation of order sum error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxIceCream_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxIceCream.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Order creation"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + IceCreamId = Convert.ToInt32(comboBoxIceCream.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, "Order creation error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/IceCreamShop/IceCreamShopView/FormCreateOrder.resx b/IceCreamShop/IceCreamShopView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/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/IceCreamShop/IceCreamShopView/FormIceCream.cs b/IceCreamShop/IceCreamShopView/FormIceCream.cs new file mode 100644 index 0000000..577a672 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCream.cs @@ -0,0 +1,209 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + public partial class FormIceCream : Form + { + private readonly ILogger _logger; + + private readonly IIceCreamLogic _logic; + + private int? _id; + + private Dictionary _iceCreamComponents; + + public int Id { set { _id = value; } } + + public FormIceCream(ILogger logger, IIceCreamLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _iceCreamComponents = new Dictionary(); + } + + private void FormIceCream_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Ice cream loading"); + try + { + var view = _logic.ReadElement(new IceCreamSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.IceCreamName; + textBoxPrice.Text = view.Price.ToString(); + _iceCreamComponents = view.IceCreamComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice cream loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Ice cream components loading"); + try + { + if (_iceCreamComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var iceCreamC in _iceCreamComponents) + { + dataGridView.Rows.Add(new object[] { iceCreamC.Key, iceCreamC.Value.Item1.ComponentName, iceCreamC.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice cream components loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIceCreamComponent)); + if (service is FormIceCreamComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_iceCreamComponents.ContainsKey(form.Id)) + { + _iceCreamComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _iceCreamComponents.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(FormIceCreamComponent)); + if (service is FormIceCreamComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _iceCreamComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _iceCreamComponents[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("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value, + dataGridView.SelectedRows[0].Cells[2].Value); + _iceCreamComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_iceCreamComponents == null || _iceCreamComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Ice cream saving"); + try + { + var model = new IceCreamBindingModel + { + Id = _id ?? 0, + IceCreamName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + IceCreamComponents = _iceCreamComponents + }; + 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, "Ice cream saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _iceCreamComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormIceCream.designer.cs b/IceCreamShop/IceCreamShopView/FormIceCream.designer.cs new file mode 100644 index 0000000..f64b858 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCream.designer.cs @@ -0,0 +1,248 @@ +namespace IceCreamShopView +{ + partial class FormIceCream + { + /// + /// 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() + { + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxName = new TextBox(); + labelName = new Label(); + textBoxPrice = new TextBox(); + labelPrice = new Label(); + groupBoxComponents = new GroupBox(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(455, 362); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(360, 362); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxName + // + textBoxName.Location = new Point(92, 7); + textBoxName.Margin = new Padding(4, 3, 4, 3); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(252, 23); + textBoxName.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(14, 10); + labelName.Margin = new Padding(4, 0, 4, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(65, 15); + labelName.TabIndex = 0; + labelName.Text = "Название :"; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(92, 37); + textBoxPrice.Margin = new Padding(4, 3, 4, 3); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(147, 23); + textBoxPrice.TabIndex = 3; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(14, 40); + labelPrice.Margin = new Padding(4, 0, 4, 0); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(73, 15); + labelPrice.TabIndex = 2; + labelPrice.Text = "Стоимость :"; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonEdit); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(14, 67); + groupBoxComponents.Margin = new Padding(4, 3, 4, 3); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(4, 3, 4, 3); + groupBoxComponents.Size = new Size(558, 288); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // buttonUpd + // + buttonUpd.Location = new Point(441, 171); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(441, 123); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(441, 76); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(441, 32); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(4, 19); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 266); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormIceCream + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(586, 402); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(labelPrice); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(4, 3, 4, 3); + Name = "FormIceCream"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Мороженое"; + Load += FormIceCream_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxName; + private Label labelName; + private TextBox textBoxPrice; + private Label labelPrice; + private GroupBox groupBoxComponents; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormIceCream.resx b/IceCreamShop/IceCreamShopView/FormIceCream.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCream.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/IceCreamShop/IceCreamShopView/FormIceCreamComponent.Designer.cs b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.Designer.cs new file mode 100644 index 0000000..ebd375c --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace IceCreamShopView +{ + partial class FormIceCreamComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(14, 13); + labelComponent.Margin = new Padding(4, 0, 4, 0); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(75, 15); + labelComponent.TabIndex = 1; + labelComponent.Text = "Компонент :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(14, 48); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 3; + labelCount.Text = "Количество :"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(102, 10); + comboBoxComponent.Margin = new Padding(4, 3, 4, 3); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(252, 23); + comboBoxComponent.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(102, 44); + textBoxCount.Margin = new Padding(4, 3, 4, 3); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(252, 23); + textBoxCount.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(160, 75); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(254, 75); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormIceCreamComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(373, 111); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormIceCreamComponent"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компонент мороженого"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormIceCreamComponent.cs b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.cs new file mode 100644 index 0000000..518dee2 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.cs @@ -0,0 +1,70 @@ +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Models; + +namespace IceCreamShopView +{ + public partial class FormIceCreamComponent : 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 FormIceCreamComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormIceCreamComponent.resx b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreamComponent.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/IceCreamShop/IceCreamShopView/FormIceCreams.Designer.cs b/IceCreamShop/IceCreamShopView/FormIceCreams.Designer.cs new file mode 100644 index 0000000..9f9988c --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreams.Designer.cs @@ -0,0 +1,126 @@ +namespace IceCreamShopView +{ + partial class FormIceCreams + { + /// + /// 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = 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.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 1; + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 8; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 6; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormIceCreams + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormIceCreams"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Мороженые"; + Load += FormIceCreams_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormIceCreams.cs b/IceCreamShop/IceCreamShopView/FormIceCreams.cs new file mode 100644 index 0000000..22f3f38 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreams.cs @@ -0,0 +1,104 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + public partial class FormIceCreams : Form + { + private readonly ILogger _logger; + + private readonly IIceCreamLogic _logic; + + public FormIceCreams(ILogger logger, IIceCreamLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIceCreams_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["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["IceCreamComponents"].Visible = false; + } + _logger.LogInformation("Ice creams loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIceCream)); + if (service is FormIceCream 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(FormIceCream)); + if (service is FormIceCream form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of ice cream"); + try + { + if (!_logic.Delete(new IceCreamBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice cream deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/IceCreamShop/IceCreamShopView/FormIceCreams.resx b/IceCreamShop/IceCreamShopView/FormIceCreams.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormIceCreams.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/IceCreamShop/IceCreamShopView/FormMain.cs b/IceCreamShop/IceCreamShopView/FormMain.cs new file mode 100644 index 0000000..a50d1ef --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormMain.cs @@ -0,0 +1,148 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + 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["IceCreamId"].Visible = false; + dataGridView.Columns["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Orders loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Orders loading error"); + 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(FormIceCreams)); + if (service is FormIceCreams 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("Order №{id}. Status changes to 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error taking an order to work"); + 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("Order №{id}. Status changes to 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Order readiness marking error"); + 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("Order №{id}. Status changes to 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Order №{id} issued", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Order issue marking error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/FormMain.designer.cs b/IceCreamShop/IceCreamShopView/FormMain.designer.cs new file mode 100644 index 0000000..7757958 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/FormMain.designer.cs @@ -0,0 +1,192 @@ +namespace IceCreamShopView +{ + partial class FormMain + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + мороженоеToolStripMenuItem = new ToolStripMenuItem(); + buttonIssuedOrder = new Button(); + buttonOrderReady = new Button(); + buttonTakeOrderInWork = new Button(); + buttonCreateOrder = new Button(); + dataGridView = new DataGridView(); + buttonUpd = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(7, 2, 0, 2); + menuStrip.Size = new Size(1031, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, мороженоеToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // мороженоеToolStripMenuItem + // + мороженоеToolStripMenuItem.Name = "мороженоеToolStripMenuItem"; + мороженоеToolStripMenuItem.Size = new Size(180, 22); + мороженоеToolStripMenuItem.Text = "Мороженое"; + мороженоеToolStripMenuItem.Click += МороженоеToolStripMenuItem_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(844, 231); + buttonIssuedOrder.Margin = new Padding(4, 3, 4, 3); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(174, 27); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(844, 171); + buttonOrderReady.Margin = new Padding(4, 3, 4, 3); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(174, 27); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(844, 117); + buttonTakeOrderInWork.Margin = new Padding(4, 3, 4, 3); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(174, 27); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(844, 58); + buttonCreateOrder.Margin = new Padding(4, 3, 4, 3); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(174, 27); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_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, 28); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(826, 320); + dataGridView.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(844, 290); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(174, 27); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Обновить список"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1031, 347); + Controls.Add(buttonUpd); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(4, 3, 4, 3); + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Лавка с мороженым"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem справочникиToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem компонентыToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem мороженоеToolStripMenuItem; + private System.Windows.Forms.Button buttonIssuedOrder; + private System.Windows.Forms.Button buttonOrderReady; + private System.Windows.Forms.Button buttonTakeOrderInWork; + private System.Windows.Forms.Button buttonCreateOrder; + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonUpd; + } +} + diff --git a/IceCreamShop/IceCreamShopView/FormMain.resx b/IceCreamShop/IceCreamShopView/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/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/IceCreamShop/IceCreamShopView/IceCreamShopView.csproj b/IceCreamShop/IceCreamShopView/IceCreamShopView.csproj index b57c89e..f8a99bd 100644 --- a/IceCreamShop/IceCreamShopView/IceCreamShopView.csproj +++ b/IceCreamShop/IceCreamShopView/IceCreamShopView.csproj @@ -8,4 +8,26 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopView/Program.cs b/IceCreamShop/IceCreamShopView/Program.cs index fd5e1a1..d811e5a 100644 --- a/IceCreamShop/IceCreamShopView/Program.cs +++ b/IceCreamShop/IceCreamShopView/Program.cs @@ -1,7 +1,18 @@ +using IceCreamShopBusinessLogic.BusinessLogics; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace IceCreamShopView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +22,34 @@ namespace IceCreamShopView // 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/IceCreamShop/IceCreamShopView/nlog.config b/IceCreamShop/IceCreamShopView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/IceCreamShop/IceCreamShopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file