From 28b83f6303ed4b11cc95218ed8b91a38ab04d259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Thu, 4 May 2023 01:22:14 +0400 Subject: [PATCH] First Labs --- Confectionery/Confectionery.sln | 27 ++ .../BusinessLogics/IngredientLogic.cs | 116 +++++++++ .../BusinessLogics/OrderLogic.cs | 127 +++++++++ .../BusinessLogics/SweetsLogic.cs | 114 ++++++++ .../ConfectioneryBusinessLogic.csproj | 17 ++ .../BindingModels/IngredientBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 29 +++ .../BindingModels/SweetsBindingModel.cs | 20 ++ .../IIngredientLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/ISweetsLogic.cs | 20 ++ .../ConfectioneryContracts.csproj | 13 + .../SearchModels/IngredientSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/SweetsSearchModel.cs | 15 ++ .../StoragesContracts/IIngredientStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/ISweetsStorage.cs | 21 ++ .../ViewModels/IngredientViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../ViewModels/SweetsViewModel.cs | 23 ++ .../ConfectioneryDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 21 ++ Confectionery/ConfectioneryDataModels/IId.cs | 13 + .../Models/IIngredientModel.cs | 14 + .../Models/IOrderModel.cs | 24 ++ .../Models/ISweetsModel.cs | 17 ++ .../ConfectioneryListImplement.csproj | 14 + .../DataListSingleton.cs | 31 +++ .../Implements/IngredientStorage.cs | 107 ++++++++ .../Implements/OrderStorage.cs | 105 ++++++++ .../Implements/SweetsStorage.cs | 107 ++++++++ .../Models/Ingredient.cs | 46 ++++ .../Models/Order.cs | 63 +++++ .../Models/Sweets.cs | 54 ++++ .../ConfectioneryView.csproj | 26 ++ .../ConfectioneryView/Form1.Designer.cs | 39 --- Confectionery/ConfectioneryView/Form1.cs | 10 - .../FormCreateOrder.Designer.cs | 149 +++++++++++ .../ConfectioneryView/FormCreateOrder.cs | 125 +++++++++ .../ConfectioneryView/FormCreateOrder.resx | 60 +++++ .../FormIngredient.Designer.cs | 122 +++++++++ .../ConfectioneryView/FormIngredient.cs | 94 +++++++ .../ConfectioneryView/FormIngredient.resx | 60 +++++ .../FormIngredients.Designer.cs | 122 +++++++++ .../ConfectioneryView/FormIngredients.cs | 110 ++++++++ .../ConfectioneryView/FormIngredients.resx | 60 +++++ .../FormListSweets.Designer.cs | 122 +++++++++ .../ConfectioneryView/FormListSweets.cs | 114 ++++++++ .../ConfectioneryView/FormListSweets.resx | 60 +++++ .../ConfectioneryView/FormMain.Designer.cs | 183 +++++++++++++ Confectionery/ConfectioneryView/FormMain.cs | 165 ++++++++++++ Confectionery/ConfectioneryView/FormMain.resx | 60 +++++ .../ConfectioneryView/FormSweets.Designer.cs | 246 ++++++++++++++++++ Confectionery/ConfectioneryView/FormSweets.cs | 209 +++++++++++++++ .../ConfectioneryView/FormSweets.resx | 60 +++++ .../FormSweetsIngredients.Designer.cs | 123 +++++++++ .../FormSweetsIngredients.cs | 94 +++++++ .../FormSweetsIngredients.resx | 60 +++++ Confectionery/ConfectioneryView/Program.cs | 40 ++- .../Properties/Resources.Designer.cs | 63 +++++ .../{Form1.resx => Properties/Resources.resx} | 0 Confectionery/ConfectioneryView/nlog.config | 14 + 63 files changed, 3886 insertions(+), 50 deletions(-) create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/SweetsLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/SweetsBindingModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/ISweetsLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj create mode 100644 Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs create mode 100644 Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs create mode 100644 Confectionery/ConfectioneryContracts/SearchModels/SweetsSearchModel.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/ISweetsStorage.cs create mode 100644 Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs create mode 100644 Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs create mode 100644 Confectionery/ConfectioneryContracts/ViewModels/SweetsViewModel.cs create mode 100644 Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj create mode 100644 Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs create mode 100644 Confectionery/ConfectioneryDataModels/IId.cs create mode 100644 Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs create mode 100644 Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs create mode 100644 Confectionery/ConfectioneryDataModels/Models/ISweetsModel.cs create mode 100644 Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj create mode 100644 Confectionery/ConfectioneryListImplement/DataListSingleton.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/SweetsStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Ingredient.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Order.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Sweets.cs delete mode 100644 Confectionery/ConfectioneryView/Form1.Designer.cs delete mode 100644 Confectionery/ConfectioneryView/Form1.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.resx create mode 100644 Confectionery/ConfectioneryView/FormIngredient.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormIngredient.cs create mode 100644 Confectionery/ConfectioneryView/FormIngredient.resx create mode 100644 Confectionery/ConfectioneryView/FormIngredients.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormIngredients.cs create mode 100644 Confectionery/ConfectioneryView/FormIngredients.resx create mode 100644 Confectionery/ConfectioneryView/FormListSweets.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormListSweets.cs create mode 100644 Confectionery/ConfectioneryView/FormListSweets.resx create mode 100644 Confectionery/ConfectioneryView/FormMain.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormMain.cs create mode 100644 Confectionery/ConfectioneryView/FormMain.resx create mode 100644 Confectionery/ConfectioneryView/FormSweets.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormSweets.cs create mode 100644 Confectionery/ConfectioneryView/FormSweets.resx create mode 100644 Confectionery/ConfectioneryView/FormSweetsIngredients.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormSweetsIngredients.cs create mode 100644 Confectionery/ConfectioneryView/FormSweetsIngredients.resx create mode 100644 Confectionery/ConfectioneryView/Properties/Resources.Designer.cs rename Confectionery/ConfectioneryView/{Form1.resx => Properties/Resources.resx} (100%) create mode 100644 Confectionery/ConfectioneryView/nlog.config diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 743261b..4966c68 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -5,6 +5,17 @@ VisualStudioVersion = 17.3.32922.545 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{9B75FC6A-4403-406F-BD78-70A656A9C38C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{AE5AAF6C-4EA0-45F6-A433-50D1A347DD60}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{138F5333-8A07-47A5-B6FB-5F5170E89D50}" + ProjectSection(ProjectDependencies) = postProject + {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60} = {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{70FA9740-C8FF-48F1-939A-8B6AAB8CB6FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{FF4C1B6D-E988-4CE0-AF41-C4539744B9BE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +26,22 @@ Global {9B75FC6A-4403-406F-BD78-70A656A9C38C}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B75FC6A-4403-406F-BD78-70A656A9C38C}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B75FC6A-4403-406F-BD78-70A656A9C38C}.Release|Any CPU.Build.0 = Release|Any CPU + {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE5AAF6C-4EA0-45F6-A433-50D1A347DD60}.Release|Any CPU.Build.0 = Release|Any CPU + {138F5333-8A07-47A5-B6FB-5F5170E89D50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {138F5333-8A07-47A5-B6FB-5F5170E89D50}.Debug|Any CPU.Build.0 = Debug|Any CPU + {138F5333-8A07-47A5-B6FB-5F5170E89D50}.Release|Any CPU.ActiveCfg = Release|Any CPU + {138F5333-8A07-47A5-B6FB-5F5170E89D50}.Release|Any CPU.Build.0 = Release|Any CPU + {70FA9740-C8FF-48F1-939A-8B6AAB8CB6FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70FA9740-C8FF-48F1-939A-8B6AAB8CB6FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70FA9740-C8FF-48F1-939A-8B6AAB8CB6FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70FA9740-C8FF-48F1-939A-8B6AAB8CB6FD}.Release|Any CPU.Build.0 = Release|Any CPU + {FF4C1B6D-E988-4CE0-AF41-C4539744B9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF4C1B6D-E988-4CE0-AF41-C4539744B9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF4C1B6D-E988-4CE0-AF41-C4539744B9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF4C1B6D-E988-4CE0-AF41-C4539744B9BE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs new file mode 100644 index 0000000..5a7ae0b --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -0,0 +1,116 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class IngredientLogic : IIngredientLogic + { + private readonly ILogger _logger; + private readonly IIngredientStorage _componentStorage; + public IngredientLogic(ILogger logger, IIngredientStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(IngredientSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id} ", model?.IngredientName, 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 IngredientViewModel? ReadElement(IngredientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.IngredientName, 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(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + + public bool Update(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IngredientBindingModel 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(IngredientBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IngredientName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.IngredientName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id} ", model.IngredientName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new IngredientSearchModel + { + IngredientName = model.IngredientName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..b742d8f --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,127 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. 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 CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SweetsId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у сладости", nameof(model.SweetsId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество сладостей в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. SweetsId: { SweetsId}", model.Id, model.Sum, model.SweetsId); + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/SweetsLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/SweetsLogic.cs new file mode 100644 index 0000000..4e2adab --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/SweetsLogic.cs @@ -0,0 +1,114 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class SweetsLogic : ISweetsLogic + { + private readonly ILogger _logger; + private readonly ISweetsStorage _sweetsStorage; + public SweetsLogic(ILogger logger, ISweetsStorage sweetsStorage) + { + _logger = logger; + _sweetsStorage = sweetsStorage; + } + public List? ReadList(SweetsSearchModel? model) + { + _logger.LogInformation("ReadList. SushiName: {SushiName}. Id: {Id}", model?.SweetsName, model?.Id); + var list = model == null ? _sweetsStorage.GetFullList() : + _sweetsStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public SweetsViewModel? ReadElement(SweetsSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SushiName: {SushiName}. Id: {Id}", model.SweetsName, model.Id); + var element = _sweetsStorage.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(SweetsBindingModel model) + { + CheckModel(model); + if (_sweetsStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(SweetsBindingModel model) + { + CheckModel(model); + if (_sweetsStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(SweetsBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_sweetsStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(SweetsBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SweetsName)) + { + throw new ArgumentNullException("Нет названия сладости", nameof(model.SweetsName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена сладости должна быть больше 0", + nameof(model.Price)); + } + _logger.LogInformation("Sweets. SweetsName: {SweetsName}. Cost: {Cost}. Id: {Id}", model.SweetsName, model.Price, model.Id); + var element = _sweetsStorage.GetElement(new SweetsSearchModel + { + SweetsName = model.SweetsName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сладости с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj new file mode 100644 index 0000000..0eae306 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs new file mode 100644 index 0000000..66559fd --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class IngredientBindingModel : IIngredientModel + { + public int Id { get; set; } + + public string IngredientName { get; set; } = string.Empty; + + public double Cost { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..47cd07c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,29 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int SweetsId { get; set; } + + public string SweetsName { get; set; } = string.Empty; + + public int Count { get; set; } + + public double Sum { get; set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + + public int Id { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/SweetsBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/SweetsBindingModel.cs new file mode 100644 index 0000000..1674b41 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/SweetsBindingModel.cs @@ -0,0 +1,20 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class SweetsBindingModel : ISweetsModel + { + public int Id { get; set; } + + public string SweetsName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary SweetsIngredients { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs new file mode 100644 index 0000000..2701f63 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IIngredientLogic + { + List? ReadList(IngredientSearchModel? model); + IngredientViewModel? ReadElement(IngredientSearchModel model); + bool Create(IngredientBindingModel model); + bool Update(IngredientBindingModel model); + bool Delete(IngredientBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..fc1f506 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/ISweetsLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/ISweetsLogic.cs new file mode 100644 index 0000000..aa0ccb0 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/ISweetsLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface ISweetsLogic + { + List? ReadList(SweetsSearchModel? model); + SweetsViewModel? ReadElement(SweetsSearchModel model); + bool Create(SweetsBindingModel model); + bool Update(SweetsBindingModel model); + bool Delete(SweetsBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj new file mode 100644 index 0000000..b0b970c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs new file mode 100644 index 0000000..5d1687f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class IngredientSearchModel + { + public int? Id { get; set; } + + public string? IngredientName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..9393fab --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/SweetsSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/SweetsSearchModel.cs new file mode 100644 index 0000000..c556cc3 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/SweetsSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class SweetsSearchModel + { + public int? Id { get; set; } + + public string? SweetsName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs new file mode 100644 index 0000000..806b214 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IIngredientStorage + { + List GetFullList(); + List GetFilteredList(IngredientSearchModel model); + IngredientViewModel? GetElement(IngredientSearchModel model); + IngredientViewModel? Insert(IngredientBindingModel model); + IngredientViewModel? Update(IngredientBindingModel model); + IngredientViewModel? Delete(IngredientBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..cbdd94f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/ISweetsStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/ISweetsStorage.cs new file mode 100644 index 0000000..f691625 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/ISweetsStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface ISweetsStorage + { + List GetFullList(); + List GetFilteredList(SweetsSearchModel model); + SweetsViewModel? GetElement(SweetsSearchModel model); + SweetsViewModel? Insert(SweetsBindingModel model); + SweetsViewModel? Update(SweetsBindingModel model); + SweetsViewModel? Delete(SweetsBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs new file mode 100644 index 0000000..ab23e1a --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; +using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class IngredientViewModel : IIngredientModel + { + public int Id { get; set; } + + [DisplayName("Название ингредиента")] + public string IngredientName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..e1384fe --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using ConfectioneryDataModels.Models; +using ConfectioneryDataModels.Enums; +using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int SweetsId { get; set; } + [DisplayName("Сладости ")] + public string SweetsName { 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/Confectionery/ConfectioneryContracts/ViewModels/SweetsViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/SweetsViewModel.cs new file mode 100644 index 0000000..39c7a07 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/SweetsViewModel.cs @@ -0,0 +1,23 @@ +using ConfectioneryDataModels.Models; +using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class SweetsViewModel : ISweetsModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string SweetsName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary SweetsIngredients { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..1c95908 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/Confectionery/ConfectioneryDataModels/IId.cs b/Confectionery/ConfectioneryDataModels/IId.cs new file mode 100644 index 0000000..b7d876a --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs new file mode 100644 index 0000000..de483fd --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IIngredientModel : IId + { + string IngredientName { get; } + double Cost { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..9e2e5f3 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs @@ -0,0 +1,24 @@ +using ConfectioneryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IOrderModel : IId + { + int SweetsId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/ISweetsModel.cs b/Confectionery/ConfectioneryDataModels/Models/ISweetsModel.cs new file mode 100644 index 0000000..786e0fc --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/ISweetsModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface ISweetsModel : IId + { + string SweetsName { get; } + + double Price { get; } + + Dictionary SweetsIngredients { get; } + } +} diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..41b6c3e --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..049dce1 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Ingredients { get; set; } + public List Orders { get; set; } + public List ListSweets { get; set; } + private DataListSingleton() + { + Ingredients = new List(); + Orders = new List(); + ListSweets = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs new file mode 100644 index 0000000..956471a --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs @@ -0,0 +1,107 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class IngredientStorage : IIngredientStorage + { + private readonly DataListSingleton _source; + public IngredientStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Ingredients) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(IngredientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.IngredientName)) + { + return result; + } + foreach (var component in _source.Ingredients) + { + if (component.IngredientName.Contains(model.IngredientName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public IngredientViewModel? GetElement(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Ingredients) + { + if ((!string.IsNullOrEmpty(model.IngredientName) && + component.IngredientName == model.IngredientName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public IngredientViewModel? Insert(IngredientBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Ingredients) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newIngredient = Ingredient.Create(model); + if (newIngredient == null) + { + return null; + } + _source.Ingredients.Add(newIngredient); + return newIngredient.GetViewModel; + } + public IngredientViewModel? Update(IngredientBindingModel model) + { + foreach (var component in _source.Ingredients) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public IngredientViewModel? Delete(IngredientBindingModel model) + { + for (int i = 0; i < _source.Ingredients.Count; ++i) + { + if (_source.Ingredients[i].Id == model.Id) + { + var element = _source.Ingredients[i]; + _source.Ingredients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..b48ca4c --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/SweetsStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/SweetsStorage.cs new file mode 100644 index 0000000..d03d234 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/SweetsStorage.cs @@ -0,0 +1,107 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class SweetsStorage : ISweetsStorage + { + private readonly DataListSingleton _source; + public SweetsStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var sweets in _source.ListSweets) + { + result.Add(sweets.GetViewModel); + } + return result; + } + public List GetFilteredList(SweetsSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SweetsName)) + { + return result; + } + foreach (var sweets in _source.ListSweets) + { + if (sweets.SweetsName.Contains(model.SweetsName)) + { + result.Add(sweets.GetViewModel); + } + } + return result; + } + public SweetsViewModel? GetElement(SweetsSearchModel model) + { + if (string.IsNullOrEmpty(model.SweetsName) && !model.Id.HasValue) + { + return null; + } + foreach (var sweets in _source.ListSweets) + { + if ((!string.IsNullOrEmpty(model.SweetsName) && + sweets.SweetsName == model.SweetsName) || + (model.Id.HasValue && sweets.Id == model.Id)) + { + return sweets.GetViewModel; + } + } + return null; + } + public SweetsViewModel? Insert(SweetsBindingModel model) + { + model.Id = 1; + foreach (var sweets in _source.ListSweets) + { + if (model.Id <= sweets.Id) + { + model.Id = sweets.Id + 1; + } + } + var newSweets = Sweets.Create(model); + if (newSweets == null) + { + return null; + } + _source.ListSweets.Add(newSweets); + return newSweets.GetViewModel; + } + public SweetsViewModel? Update(SweetsBindingModel model) + { + foreach (var sweets in _source.ListSweets) + { + if (sweets.Id == model.Id) + { + sweets.Update(model); + return sweets.GetViewModel; + } + } + return null; + } + public SweetsViewModel? Delete(SweetsBindingModel model) + { + for (int i = 0; i < _source.ListSweets.Count; ++i) + { + if (_source.ListSweets[i].Id == model.Id) + { + var element = _source.ListSweets[i]; + _source.ListSweets.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs new file mode 100644 index 0000000..2b2efba --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs @@ -0,0 +1,46 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public void Update(IngredientBindingModel? model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs new file mode 100644 index 0000000..4e0882b --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -0,0 +1,63 @@ +using ConfectioneryDataModels.Models; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Order : IOrderModel + { + public int SweetsId { get; private set; } + public string SweetsName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + SweetsId = model.SweetsId, + SweetsName = model.SweetsName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + SweetsId = SweetsId, + SweetsName = SweetsName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Sweets.cs b/Confectionery/ConfectioneryListImplement/Models/Sweets.cs new file mode 100644 index 0000000..1549303 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Sweets.cs @@ -0,0 +1,54 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Sweets : ISweetsModel + { + public int Id { get; private set; } + public string SweetsName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary SweetsIngredients + { + get; + private set; + } = new Dictionary(); + public static Sweets? Create(SweetsBindingModel? model) + { + if (model == null) + { + return null; + } + return new Sweets() + { + Id = model.Id, + SweetsName = model.SweetsName, + Price = model.Price, + SweetsIngredients = model.SweetsIngredients + }; + } + public void Update(SweetsBindingModel? model) + { + if (model == null) + { + return; + } + SweetsName = model.SweetsName; + Price = model.Price; + SweetsIngredients = model.SweetsIngredients; + } + public SweetsViewModel GetViewModel => new() + { + Id = Id, + SweetsName = SweetsName, + Price = Price, + SweetsIngredients = SweetsIngredients + }; + } +} diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj index b57c89e..1e98e74 100644 --- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -8,4 +8,30 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Form1.Designer.cs b/Confectionery/ConfectioneryView/Form1.Designer.cs deleted file mode 100644 index 4fdee0d..0000000 --- a/Confectionery/ConfectioneryView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ConfectioneryView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Form1.cs b/Confectionery/ConfectioneryView/Form1.cs deleted file mode 100644 index 0d39778..0000000 --- a/Confectionery/ConfectioneryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ConfectioneryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..d86c3eb --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -0,0 +1,149 @@ +namespace ConfectioneryView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxSweets = new System.Windows.Forms.ComboBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(241, 90); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(153, 90); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(93, 63); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(230, 23); + this.textBoxSum.TabIndex = 13; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(93, 36); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 12; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // comboBoxSweets + // + this.comboBoxSweets.FormattingEnabled = true; + this.comboBoxSweets.Location = new System.Drawing.Point(93, 9); + this.comboBoxSweets.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxSweets.Name = "comboBoxSweets"; + this.comboBoxSweets.Size = new System.Drawing.Size(230, 23); + this.comboBoxSweets.TabIndex = 11; + this.comboBoxSweets.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSweets_SelectedIndexChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 63); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 10; + this.labelSum.Text = "Сумма:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 36); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 9; + this.labelCount.Text = "Количество:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 8; + this.labelName.Text = "Сладости:"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(343, 128); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxSweets); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxSum; + private TextBox textBoxCount; + private ComboBox comboBoxSweets; + private Label labelSum; + private Label labelCount; + private Label labelName; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs new file mode 100644 index 0000000..01d0916 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormCreateOrder : Form + { + private readonly Microsoft.Extensions.Logging.ILogger _logger; + private readonly ISweetsLogic _logicS; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ISweetsLogic logicS, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation(" "); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxSweets.DisplayMember = "SweetsName"; + comboBoxSweets.ValueMember = "Id"; + comboBoxSweets.DataSource = list; + comboBoxSweets.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxSweets.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSweets.SelectedValue); + var product = _logicS.ReadElement(new SweetsSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxSweets_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 (comboBoxSweets.SelectedValue == null) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + SweetsId = Convert.ToInt32(comboBoxSweets.SelectedValue), + SweetsName = comboBoxSweets.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.resx b/Confectionery/ConfectioneryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormIngredient.Designer.cs b/Confectionery/ConfectioneryView/FormIngredient.Designer.cs new file mode 100644 index 0000000..4f924d0 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredient.Designer.cs @@ -0,0 +1,122 @@ +namespace ConfectioneryView +{ + partial class FormIngredient + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelBlankName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(200, 73); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(112, 73); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(111, 38); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(183, 23); + this.textBoxCost.TabIndex = 9; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(111, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(329, 23); + this.textBoxName.TabIndex = 8; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 37); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(38, 15); + this.labelPrice.TabIndex = 7; + this.labelPrice.Text = "Цена:"; + // + // labelBlankName + // + this.labelBlankName.AutoSize = true; + this.labelBlankName.Location = new System.Drawing.Point(12, 14); + this.labelBlankName.Name = "labelBlankName"; + this.labelBlankName.Size = new System.Drawing.Size(62, 15); + this.labelBlankName.TabIndex = 6; + this.labelBlankName.Text = "Название:"; + // + // FormIngredient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelBlankName); + this.Name = "FormIngredient"; + this.Text = "Ингредиент"; + this.Load += new System.EventHandler(this.FormIngredient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCost; + private TextBox textBoxName; + private Label labelPrice; + private Label labelBlankName; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormIngredient.cs b/Confectionery/ConfectioneryView/FormIngredient.cs new file mode 100644 index 0000000..57938a8 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredient.cs @@ -0,0 +1,94 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormIngredient : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormIngredient(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIngredient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение ингредиента"); + var view = _logic.ReadElement(new IngredientSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.IngredientName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение ингредиента"); + try + { + var model = new IngredientBindingModel + { + Id = _id ?? 0, + IngredientName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} + diff --git a/Confectionery/ConfectioneryView/FormIngredient.resx b/Confectionery/ConfectioneryView/FormIngredient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormIngredients.Designer.cs b/Confectionery/ConfectioneryView/FormIngredients.Designer.cs new file mode 100644 index 0000000..e72dad3 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredients.Designer.cs @@ -0,0 +1,122 @@ +namespace ConfectioneryView +{ + partial class FormIngredients + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 186); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 9; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 160); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 8; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 134); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 7; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 108); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 348); + this.dataGridView.TabIndex = 5; + // + // FormIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(571, 348); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormIngredients"; + this.Text = "Ингредиенты"; + this.Load += new System.EventHandler(this.FormIngredients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormIngredients.cs b/Confectionery/ConfectioneryView/FormIngredients.cs new file mode 100644 index 0000000..22fb2ad --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredients.cs @@ -0,0 +1,110 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormIngredients : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + public FormIngredients(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIngredients_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["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка ингредиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ингредиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + if (service is FormIngredient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + if (service is FormIngredient form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление ингредиента"); + try + { + if (!_logic.Delete(new IngredientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormIngredients.resx b/Confectionery/ConfectioneryView/FormIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormIngredients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormListSweets.Designer.cs b/Confectionery/ConfectioneryView/FormListSweets.Designer.cs new file mode 100644 index 0000000..238a7aa --- /dev/null +++ b/Confectionery/ConfectioneryView/FormListSweets.Designer.cs @@ -0,0 +1,122 @@ +namespace ConfectioneryView +{ + partial class FormListSweets + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 345); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 183); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 157); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 131); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 105); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormListSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(570, 345); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormListSushi"; + this.Text = "Список сладостей"; + this.Load += new System.EventHandler(this.FormDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormListSweets.cs b/Confectionery/ConfectioneryView/FormListSweets.cs new file mode 100644 index 0000000..5144f02 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormListSweets.cs @@ -0,0 +1,114 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormListSweets : Form + { + private readonly ILogger _logger; + private readonly ISweetsLogic _logic; + public FormListSweets(ILogger logger, ISweetsLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDocuments_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["SweetsName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["SweetsIngredients"].Visible = false; + } + _logger.LogInformation("Загрузка сладостей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки сладостей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSweets)); + if (service is FormSweets 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(FormSweets)); + if (service is FormSweets form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление сладостей"); + try + { + if (!_logic.Delete(new SweetsBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сладостей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormListSweets.resx b/Confectionery/ConfectioneryView/FormListSweets.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormListSweets.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs new file mode 100644 index 0000000..f6ef491 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -0,0 +1,183 @@ +namespace ConfectioneryView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SweetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonSetToFinish = new System.Windows.Forms.Button(); + this.buttonSetToDone = new System.Windows.Forms.Button(); + this.buttonSetToWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(975, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ингредиентыToolStripMenuItem, + this.SweetsToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // ингредиентыToolStripMenuItem + // + this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; + this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); + // + // SweetsToolStripMenuItem + // + this.SweetsToolStripMenuItem.Name = "SweetsToolStripMenuItem"; + this.SweetsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.SweetsToolStripMenuItem.Text = "Сладости"; + this.SweetsToolStripMenuItem.Click += new System.EventHandler(this.SweetsToolStripMenuItem_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(780, 314); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(170, 58); + this.buttonUpdate.TabIndex = 12; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonSetToFinish + // + this.buttonSetToFinish.Location = new System.Drawing.Point(780, 252); + this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToFinish.Name = "buttonSetToFinish"; + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); + this.buttonSetToFinish.TabIndex = 11; + this.buttonSetToFinish.Text = "Заказ выдан"; + this.buttonSetToFinish.UseVisualStyleBackColor = true; + this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonSetToDone + // + this.buttonSetToDone.Location = new System.Drawing.Point(780, 190); + this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToDone.Name = "buttonSetToDone"; + this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); + this.buttonSetToDone.TabIndex = 10; + this.buttonSetToDone.Text = "Заказ готов"; + this.buttonSetToDone.UseVisualStyleBackColor = true; + this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonSetToWork + // + this.buttonSetToWork.Location = new System.Drawing.Point(780, 128); + this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToWork.Name = "buttonSetToWork"; + this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); + this.buttonSetToWork.TabIndex = 9; + this.buttonSetToWork.Text = "Отдать на выполнение"; + this.buttonSetToWork.UseVisualStyleBackColor = true; + this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(780, 66); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); + this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 24); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(755, 426); + this.dataGridView.TabIndex = 7; + this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(975, 450); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonSetToFinish); + this.Controls.Add(this.buttonSetToDone); + this.Controls.Add(this.buttonSetToWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Кондитерская"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ингредиентыToolStripMenuItem; + private ToolStripMenuItem SweetsToolStripMenuItem; + private Button buttonUpdate; + private Button buttonSetToFinish; + private Button buttonSetToDone; + private Button buttonSetToWork; + private Button buttonCreateOrder; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs new file mode 100644 index 0000000..84c8448 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -0,0 +1,165 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using ConfectioneryView; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + 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() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["SweetsId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + if (service is FormIngredients form) + { + form.ShowDialog(); + } + } + private void SweetsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormListSweets)); + if (service is FormListSweets form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + } +} diff --git a/Confectionery/ConfectioneryView/FormMain.resx b/Confectionery/ConfectioneryView/FormMain.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSweets.Designer.cs b/Confectionery/ConfectioneryView/FormSweets.Designer.cs new file mode 100644 index 0000000..9541334 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweets.Designer.cs @@ -0,0 +1,246 @@ +namespace ConfectioneryView +{ + partial class FormSweets + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.groupBoxIngredients = new System.Windows.Forms.GroupBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnIngredientName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxIngredients.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(90, 36); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(138, 23); + this.textBoxPrice.TabIndex = 7; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(90, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 23); + this.textBoxName.TabIndex = 6; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 41); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(70, 15); + this.labelPrice.TabIndex = 5; + this.labelPrice.Text = "Стоимость:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 14); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 4; + this.labelName.Text = "Название:"; + // + // groupBoxIngredients + // + this.groupBoxIngredients.Controls.Add(this.buttonCancel); + this.groupBoxIngredients.Controls.Add(this.buttonSave); + this.groupBoxIngredients.Controls.Add(this.buttonUpdate); + this.groupBoxIngredients.Controls.Add(this.buttonDelete); + this.groupBoxIngredients.Controls.Add(this.buttonEdit); + this.groupBoxIngredients.Controls.Add(this.buttonAdd); + this.groupBoxIngredients.Controls.Add(this.dataGridView); + this.groupBoxIngredients.Dock = System.Windows.Forms.DockStyle.Bottom; + this.groupBoxIngredients.Location = new System.Drawing.Point(0, 70); + this.groupBoxIngredients.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Name = "groupBoxIngredients"; + this.groupBoxIngredients.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Size = new System.Drawing.Size(592, 206); + this.groupBoxIngredients.TabIndex = 8; + this.groupBoxIngredients.TabStop = false; + this.groupBoxIngredients.Text = "Компоненты"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(504, 176); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(79, 22); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(504, 150); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 22); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(504, 98); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(79, 22); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(504, 72); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(79, 22); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(504, 46); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(79, 22); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(504, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(79, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnIngredientName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(493, 182); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // ColumnIngredientName + // + this.ColumnIngredientName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.ColumnIngredientName.HeaderText = "Ингредиент"; + this.ColumnIngredientName.MinimumWidth = 6; + this.ColumnIngredientName.Name = "ColumnIngredientName"; + this.ColumnIngredientName.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.ColumnIngredientName.Width = 312; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // FormSweets + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(592, 276); + this.Controls.Add(this.groupBoxIngredients); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormSushi"; + this.Text = "Сладости"; + this.Load += new System.EventHandler(this.FormSweets_Load); + this.groupBoxIngredients.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label labelPrice; + private Label labelName; + private GroupBox groupBoxIngredients; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnIngredientName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSweets.cs b/Confectionery/ConfectioneryView/FormSweets.cs new file mode 100644 index 0000000..16f57f6 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweets.cs @@ -0,0 +1,209 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormSweets : Form + { + private readonly ILogger _logger; + private readonly ISweetsLogic _logic; + private int? _id; + private Dictionary _sweetsIngredients; + public int Id { set { _id = value; } } + public FormSweets(ILogger logger, ISweetsLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _sweetsIngredients = new Dictionary(); + } + + private void FormSweets_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка сладостей"); + try + { + var view = _logic.ReadElement(new SweetsSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SweetsName; + textBoxPrice.Text = view.Price.ToString(); + _sweetsIngredients = view.SweetsIngredients ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки сладостей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиента сладости"); + try + { + if (_sweetsIngredients != null) + { + dataGridView.Rows.Clear(); + foreach (var sc in _sweetsIngredients) + { + dataGridView.Rows.Add(new object[] { sc.Key, sc.Value.Item1.IngredientName, sc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ингредиента сладости"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSweetsIngredients)); + if (service is FormSweetsIngredients form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); + if (_sweetsIngredients.ContainsKey(form.Id)) + { + _sweetsIngredients[form.Id] = (form.IngredientModel, form.Count); + } + else + { + _sweetsIngredients.Add(form.Id, (form.IngredientModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSweetsIngredients)); + if (service is FormSweetsIngredients form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _sweetsIngredients[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента: { IngredientName} - { Count} ", form.IngredientModel.IngredientName, form.Count); + _sweetsIngredients[form.Id] = (form.IngredientModel, 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("Удаление ингредиента: { IngredientName} - { Count} ", + dataGridView.SelectedRows[0].Cells[1].Value); _sweetsIngredients?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_sweetsIngredients == null || _sweetsIngredients.Count == 0) + { + MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение сладости"); + try + { + var model = new SweetsBindingModel + { + Id = _id ?? 0, + SweetsName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SweetsIngredients = _sweetsIngredients + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сладости"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _sweetsIngredients) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/Confectionery/ConfectioneryView/FormSweets.resx b/Confectionery/ConfectioneryView/FormSweets.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweets.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSweetsIngredients.Designer.cs b/Confectionery/ConfectioneryView/FormSweetsIngredients.Designer.cs new file mode 100644 index 0000000..7d7d18c --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweetsIngredients.Designer.cs @@ -0,0 +1,123 @@ +namespace ConfectioneryView +{ + partial class FormSweetsIngredients + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxIngredient = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelIngredient = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(319, 80); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(80, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(233, 80); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(80, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(116, 43); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(283, 23); + this.textBoxCount.TabIndex = 9; + // + // comboBoxIngredient + // + this.comboBoxIngredient.FormattingEnabled = true; + this.comboBoxIngredient.Location = new System.Drawing.Point(116, 11); + this.comboBoxIngredient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxIngredient.Name = "comboBoxIngredient"; + this.comboBoxIngredient.Size = new System.Drawing.Size(282, 23); + this.comboBoxIngredient.TabIndex = 8; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 46); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 7; + this.labelCount.Text = "Количество:"; + // + // labelIngredient + // + this.labelIngredient.AutoSize = true; + this.labelIngredient.Location = new System.Drawing.Point(10, 14); + this.labelIngredient.Name = "labelIngredient"; + this.labelIngredient.Size = new System.Drawing.Size(75, 15); + this.labelIngredient.TabIndex = 6; + this.labelIngredient.Text = "Ингредиент:"; + // + // FormSushiIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(410, 115); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxIngredient); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelIngredient); + this.Name = "FormSushiIngredients"; + this.Text = "Ингредиент сладостей"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private ComboBox comboBoxIngredient; + private Label labelCount; + private Label labelIngredient; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSweetsIngredients.cs b/Confectionery/ConfectioneryView/FormSweetsIngredients.cs new file mode 100644 index 0000000..6a95fa5 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweetsIngredients.cs @@ -0,0 +1,94 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormSweetsIngredients : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxIngredient.SelectedValue); + } + set + { + comboBoxIngredient.SelectedValue = value; + } + } + public IIngredientModel? IngredientModel + { + 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 FormSweetsIngredients(IIngredientLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxIngredient.DisplayMember = "IngredientName"; + comboBoxIngredient.ValueMember = "Id"; + comboBoxIngredient.DataSource = _list; + comboBoxIngredient.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле 'Количество'", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxIngredient.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(); + } + + private void FormSweetsIngredients_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/Confectionery/ConfectioneryView/FormSweetsIngredients.resx b/Confectionery/ConfectioneryView/FormSweetsIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSweetsIngredients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 8b4cd92..8db041f 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -1,7 +1,18 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace ConfectioneryView { 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 ConfectioneryView // 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/Confectionery/ConfectioneryView/Properties/Resources.Designer.cs b/Confectionery/ConfectioneryView/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1d9498e --- /dev/null +++ b/Confectionery/ConfectioneryView/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ConfectioneryView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConfectioneryView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Confectionery/ConfectioneryView/Form1.resx b/Confectionery/ConfectioneryView/Properties/Resources.resx similarity index 100% rename from Confectionery/ConfectioneryView/Form1.resx rename to Confectionery/ConfectioneryView/Properties/Resources.resx diff --git a/Confectionery/ConfectioneryView/nlog.config b/Confectionery/ConfectioneryView/nlog.config new file mode 100644 index 0000000..1e6a146 --- /dev/null +++ b/Confectionery/ConfectioneryView/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + +