From be8a50bdaadc9fb954b9187580ffafe66c7c955b Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 28 Feb 2024 12:12:35 +0400 Subject: [PATCH 01/13] lets do some magic of git --- SushiBar/SushiBarView/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 0d12b88..62a8d49 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -10,7 +10,7 @@ using NLog.Extensions.Logging; namespace SushiBarView -{ +{ internal static class Program { private static ServiceProvider? _serviceProvider; From 87bcb9c15ed263af53830ec662f3b648e5f841d9 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 28 Feb 2024 12:17:42 +0400 Subject: [PATCH 02/13] shit --- SushiBar/SushiBar/Program.cs | 17 -- SushiBar/SushiBar/SushiBar.csproj | 11 - SushiBar/SushiBarBusinessLogic/App.config | 6 - .../SushiBarBusinessLogic/ComponentLogic.cs | 111 -------- .../SushiBarBusinessLogic.csproj | 48 ---- .../SushiBarBusinessLogic_/ComponentLogic.cs | 117 -------- SushiBar/SushiBarBusinessLogic_/OrderLogic.cs | 125 --------- SushiBar/SushiBarBusinessLogic_/SushiLogic.cs | 117 -------- .../BindingModels/ComponentBindingModel.cs | 16 -- .../BindingModels/OrderBindingModel.cs | 21 -- .../BindingModels/SushiBindingModel.cs | 22 -- .../IComponentLogic.cs | 20 -- .../BusinessLogicsContracts/IOrderLogic.cs | 20 -- .../BusinessLogicsContracts/ISushiLogic.cs | 21 -- .../SearchModels/ComponentSearchModel.cs | 14 - .../SearchModels/OrderSearchModel.cs | 13 - .../SearchModels/SushiSearchModel.cs | 14 - .../StoragesContracts/IComponentStorage.cs | 21 -- .../StoragesContracts/IOrderStorage.cs | 22 -- .../StoragesContracts/ISushiStorage.cs | 22 -- .../ViewModels/ComponentViewModel.cs | 21 -- .../ViewModels/OrderViewModel.cs | 37 --- .../ViewModels/SushiViewModel.cs | 25 -- .../Enums/OrderStatus.cs | 17 ++ .../SushiBarDataModels — копия/IId.cs | 7 + .../Models/IComponentModel.cs | 15 ++ .../Models/IOrderModel.cs | 19 ++ .../Models/ISushiModel.cs | 15 ++ .../SushiBarDataModels.csproj | 9 + .../DataFileSingleton.cs | 58 ++++ .../Implements/ComponentStorage.cs | 86 ++++++ .../Implements/OrderStorage.cs | 94 +++++++ .../Implements/SushiStorage.cs | 86 ++++++ .../Models/Component.cs | 70 +++++ .../Models/Order.cs | 92 +++++++ .../Models/Sushi.cs | 86 ++++++ .../SushiBarFileImplement.csproj} | 1 + SushiBar/SushiBarListImplement/App.config | 6 - .../SushiBarListImplement.csproj | 55 ---- .../DataListSingleton.cs | 4 +- .../Implements}/ComponentStorage.cs | 4 +- .../Implements/OrderStorage.cs | 125 +++++++++ .../Implements/SushiStorage.cs | 113 ++++++++ .../Models}/Component.cs | 5 + .../Models/Order.cs | 62 +++++ .../Models}/Sushi.cs | 29 +- .../SushiBarListImplement.csproj} | 7 +- .../SushiBarView/FormComponent.Designer.cs | 118 -------- SushiBar/SushiBarView/FormComponent.cs | 88 ------ SushiBar/SushiBarView/FormComponent.resx | 60 ----- .../SushiBarView/FormComponents.Designer.cs | 115 -------- SushiBar/SushiBarView/FormComponents.cs | 123 --------- SushiBar/SushiBarView/FormComponents.resx | 60 ----- .../SushiBarView/FormCreateOrder.Designer.cs | 145 ---------- SushiBar/SushiBarView/FormCreateOrder.cs | 136 ---------- SushiBar/SushiBarView/FormCreateOrder.resx | 60 ----- SushiBar/SushiBarView/FormMain.Designer.cs | 175 ------------ SushiBar/SushiBarView/FormMain.cs | 171 ------------ SushiBar/SushiBarView/FormMain.resx | 63 ----- SushiBar/SushiBarView/FormSushi.Designer.cs | 198 -------------- SushiBar/SushiBarView/FormSushi.cs | 252 ------------------ SushiBar/SushiBarView/FormSushi.resx | 60 ----- .../FormSushiComponent.Designer.cs | 119 --------- SushiBar/SushiBarView/FormSushiComponent.cs | 99 ------- SushiBar/SushiBarView/FormSushiComponent.resx | 60 ----- SushiBar/SushiBarView/FormSushis.Designer.cs | 115 -------- SushiBar/SushiBarView/FormSushis.cs | 121 --------- SushiBar/SushiBarView/FormSushis.resx | 60 ----- SushiBar/SushiBarView/Program.cs | 52 ---- SushiBar/SushiBarView/SushiBarView.csproj | 35 --- SushiBar/SushiBarView/nlog.config | 15 -- 71 files changed, 982 insertions(+), 3444 deletions(-) delete mode 100644 SushiBar/SushiBar/Program.cs delete mode 100644 SushiBar/SushiBar/SushiBar.csproj delete mode 100644 SushiBar/SushiBarBusinessLogic/App.config delete mode 100644 SushiBar/SushiBarBusinessLogic/ComponentLogic.cs delete mode 100644 SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj delete mode 100644 SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs delete mode 100644 SushiBar/SushiBarBusinessLogic_/OrderLogic.cs delete mode 100644 SushiBar/SushiBarBusinessLogic_/SushiLogic.cs delete mode 100644 SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs delete mode 100644 SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs delete mode 100644 SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs delete mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs delete mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs delete mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs delete mode 100644 SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs delete mode 100644 SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs delete mode 100644 SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs delete mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs delete mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs delete mode 100644 SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs delete mode 100644 SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs delete mode 100644 SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs delete mode 100644 SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs create mode 100644 SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs create mode 100644 SushiBar/SushiBarDataModels — копия/IId.cs create mode 100644 SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs create mode 100644 SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs create mode 100644 SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs create mode 100644 SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj create mode 100644 SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Component.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Order.cs create mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs rename SushiBar/{SushiBarContracts/SushiBarContracts.csproj => SushiBarFileImplement — копия/SushiBarFileImplement.csproj} (79%) delete mode 100644 SushiBar/SushiBarListImplement/App.config delete mode 100644 SushiBar/SushiBarListImplement/SushiBarListImplement.csproj rename SushiBar/{SushiBarListImplement => SushiBarListImplement_ — копия}/DataListSingleton.cs (88%) rename SushiBar/{SushiBarListImplement => SushiBarListImplement_ — копия/Implements}/ComponentStorage.cs (98%) create mode 100644 SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs create mode 100644 SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs rename SushiBar/{SushiBarListImplement => SushiBarListImplement_ — копия/Models}/Component.cs (87%) create mode 100644 SushiBar/SushiBarListImplement_ — копия/Models/Order.cs rename SushiBar/{SushiBarListImplement => SushiBarListImplement_ — копия/Models}/Sushi.cs (50%) rename SushiBar/{SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj => SushiBarListImplement_ — копия/SushiBarListImplement.csproj} (64%) delete mode 100644 SushiBar/SushiBarView/FormComponent.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormComponent.cs delete mode 100644 SushiBar/SushiBarView/FormComponent.resx delete mode 100644 SushiBar/SushiBarView/FormComponents.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormComponents.cs delete mode 100644 SushiBar/SushiBarView/FormComponents.resx delete mode 100644 SushiBar/SushiBarView/FormCreateOrder.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormCreateOrder.cs delete mode 100644 SushiBar/SushiBarView/FormCreateOrder.resx delete mode 100644 SushiBar/SushiBarView/FormMain.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormMain.cs delete mode 100644 SushiBar/SushiBarView/FormMain.resx delete mode 100644 SushiBar/SushiBarView/FormSushi.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormSushi.cs delete mode 100644 SushiBar/SushiBarView/FormSushi.resx delete mode 100644 SushiBar/SushiBarView/FormSushiComponent.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormSushiComponent.cs delete mode 100644 SushiBar/SushiBarView/FormSushiComponent.resx delete mode 100644 SushiBar/SushiBarView/FormSushis.Designer.cs delete mode 100644 SushiBar/SushiBarView/FormSushis.cs delete mode 100644 SushiBar/SushiBarView/FormSushis.resx delete mode 100644 SushiBar/SushiBarView/Program.cs delete mode 100644 SushiBar/SushiBarView/SushiBarView.csproj delete mode 100644 SushiBar/SushiBarView/nlog.config diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs deleted file mode 100644 index 9e07955..0000000 --- a/SushiBar/SushiBar/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace SushiBar -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(); - } - } -} \ No newline at end of file diff --git a/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj deleted file mode 100644 index b57c89e..0000000 --- a/SushiBar/SushiBar/SushiBar.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/App.config b/SushiBar/SushiBarBusinessLogic/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/SushiBar/SushiBarBusinessLogic/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs deleted file mode 100644 index f4885e5..0000000 --- a/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarBusinessLogic.BusinessLogics -{ - public class ComponentLogic - private readonly ILogger _logger; - private readonly IComponentStorage _componentStorage; - public ComponentLogic(ILogger logger, IComponentStorage - componentStorage) - { - _logger = logger; - _componentStorage = componentStorage; - } - public List? ReadList(ComponentSearchModel? model) - { - _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); - var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ComponentViewModel? ReadElement(ComponentSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); - var element = _componentStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - public bool Create(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ComponentBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_componentStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(ComponentBindingModel model, bool withParams = - true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ComponentName)) - { - throw new ArgumentNullException("Нет названия компонента", - nameof(model.ComponentName)); - } - if (model.Cost <= 0) - { - throw new ArgumentNullException("Цена компонента должна быть - больше 0", nameof(model.Cost)); - } - _logger.LogInformation("Component. ComponentName:{ComponentName}. - Cost:{ Cost}. Id: { Id} - ", model.ComponentName, model.Cost, model.Id); - var element = _componentStorage.GetElement(new ComponentSearchModel - { - ComponentName = model.ComponentName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Компонент с таким названием - уже есть"); - } - } -} diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj deleted file mode 100644 index 166199b..0000000 --- a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - - Debug - AnyCPU - {E9064087-924C-4E00-A9EA-8E922CF49D11} - Exe - SushiBarBusinessLogic - SushiBarBusinessLogic - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - {993e0787-3ad5-4743-8997-c828cd0cdc10} - SushiBarContracts - - - - - - - \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs deleted file mode 100644 index 46d0d91..0000000 --- a/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs +++ /dev/null @@ -1,117 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarBusinessLogic.BusinessLogics -{ - public class ComponentLogic : IComponentLogic - { - - private readonly ILogger _logger; - private readonly IComponentStorage _componentStorage; - public ComponentLogic(ILogger logger, IComponentStorage - componentStorage) - { - _logger = logger; - _componentStorage = componentStorage; - } - public List? ReadList(ComponentSearchModel? model) - { - _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); - var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ComponentViewModel? ReadElement(ComponentSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); - var element = _componentStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - public bool Create(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ComponentBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_componentStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(ComponentBindingModel model, bool withParams = - true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ComponentName)) - { - throw new ArgumentNullException("Нет названия компонента", - nameof(model.ComponentName)); - } - if (model.Cost <= 0) - { - throw new ArgumentNullException("Цена компонента должна больше 0", nameof(model.Cost)); - } - _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id} ", model.ComponentName, model.Cost, model.Id); - var element = _componentStorage.GetElement(new ComponentSearchModel - { - ComponentName = model.ComponentName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Компонент с таким названием уже есть"); - } - } - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs deleted file mode 100644 index ac3e5f0..0000000 --- a/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs +++ /dev/null @@ -1,125 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarBusinessLogic.BusinessLogics -{ - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. 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.Неизвестен) - return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполняется); - } - - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Готов); - } - - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}", - model.SushiId, model.Count, model.Sum, model.Id); - } - - private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } - model.DateCreate = element.DateCreate; - model.SushiId = element.SushiId; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - if (requiredStatus - model.Status == 1) - { - model.Status = requiredStatus; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); - throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); - } - } -} diff --git a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs deleted file mode 100644 index fefe4a4..0000000 --- a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs +++ /dev/null @@ -1,117 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BusinessLogicsContracts; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; - -namespace SushiBarBusinessLogic.BusinessLogics -{ - public class SushiLogic :ISushiLogic - { - private readonly ILogger _logger; - private readonly ISushiStorage _SushiStorage; - public SushiLogic(ILogger logger, ISushiStorage SushiStorage) - { - _logger = logger; - _SushiStorage = SushiStorage; - } - public List? ReadList(SushiSearchModel? model) - { - _logger.LogInformation("ReadList. SushiName:{SushiName}.Id:{ Id}", model?.SushiName, model?.Id); - var list = model == null ? _SushiStorage.GetFullList() : _SushiStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public SushiViewModel? ReadElement(SushiSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. SushiName:{SushiName}.Id:{ Id}", model.SushiName, model.Id); - var element = _SushiStorage.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(SushiBindingModel model) - { - CheckModel(model); - if (_SushiStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(SushiBindingModel model) - { - CheckModel(model); - if (_SushiStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(SushiBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_SushiStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(SushiBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.SushiName)) - { - throw new ArgumentNullException("Нет названия пиццы", nameof(model.SushiName)); - } - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); - } - if (model.SushiComponents == null || model.SushiComponents.Count == 0) - { - throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.SushiComponents)); - } - _logger.LogInformation("Sushi. SushiName:{SushiName}.Price:{Price}.Id: { Id}", model.SushiName, model.Price, model.Id); - var element = _SushiStorage.GetElement(new SushiSearchModel - { - SushiName = model.SushiName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Пицца с таким названием уже есть"); - } - } - } -} diff --git a/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs deleted file mode 100644 index 206930c..0000000 --- a/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SushiBarDataModels.Models; - -namespace SushiBarContracts.BindingModels -{ - public class ComponentBindingModel : IComponentModel - { - public int Id { get; set; } - public string ComponentName { get; set; } = string.Empty; - public double Cost { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs deleted file mode 100644 index ee30e84..0000000 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using SushiBarDataModels.Enums; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.BindingModels -{ - public class OrderBindingModel : IOrderModel - { - public int Id { get; set; } - public int SushiId { get; set; } - public int Count { get; set; } - public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs deleted file mode 100644 index ce67161..0000000 --- a/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SushiBarDataModels.Models; - -namespace SushiBarContracts.BindingModels -{ - public class SushiBindingModel : ISushiModel - { - public int Id { get; set; } - public string SushiName { get; set; } = string.Empty; - public double Price { get; set; } - public Dictionary SushiComponents - { - get; - set; - } = new(); - - } -} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs deleted file mode 100644 index 5c2b515..0000000 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.BusinessLogicsContracts -{ - public interface IComponentLogic - { - List? ReadList(ComponentSearchModel? model); - ComponentViewModel? ReadElement(ComponentSearchModel model); - bool Create(ComponentBindingModel model); - bool Update(ComponentBindingModel model); - bool Delete(ComponentBindingModel model); - } -} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs deleted file mode 100644 index b90fb79..0000000 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.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/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs deleted file mode 100644 index 32c732b..0000000 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs +++ /dev/null @@ -1,21 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.BusinessLogicsContracts -{ - public interface ISushiLogic - { - List? ReadList(SushiSearchModel? model); - SushiViewModel? ReadElement(SushiSearchModel model); - bool Create(SushiBindingModel model); - bool Update(SushiBindingModel model); - bool Delete(SushiBindingModel model); - } - -} diff --git a/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs deleted file mode 100644 index a69687d..0000000 --- a/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.SearchModels -{ - public class ComponentSearchModel - { - public int? Id { get; set; } - public string? ComponentName { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs deleted file mode 100644 index 98630db..0000000 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.SearchModels -{ - public class OrderSearchModel - { - public int? Id { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs deleted file mode 100644 index 95d2732..0000000 --- a/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.SearchModels -{ - public class SushiSearchModel - { - public int? Id { get; set; } - public string? SushiName { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs deleted file mode 100644 index a58deb5..0000000 --- a/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.StoragesContracts -{ - public interface IComponentStorage - { - List GetFullList(); - List GetFilteredList(ComponentSearchModel model); - ComponentViewModel? GetElement(ComponentSearchModel model); - ComponentViewModel? Insert(ComponentBindingModel model); - ComponentViewModel? Update(ComponentBindingModel model); - ComponentViewModel? Delete(ComponentBindingModel model); - } -} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs deleted file mode 100644 index 5d310e8..0000000 --- a/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.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/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs deleted file mode 100644 index 3682ff7..0000000 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; - -namespace SushiBarContracts.StoragesContracts -{ - public interface ISushiStorage - { - List GetFullList(); - List GetFilteredList(SushiSearchModel model); - SushiViewModel? GetElement(SushiSearchModel model); - SushiViewModel? Insert(SushiBindingModel model); - SushiViewModel? Update(SushiBindingModel model); - SushiViewModel? Delete(SushiBindingModel model); - } - -} diff --git a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs deleted file mode 100644 index 5b924c1..0000000 --- a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.ViewModels -{ - public class ComponentViewModel : IComponentModel - { - public int Id { get; set; } - - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - - [DisplayName("Цена")] - public double Cost { get; set; } - } -} diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs deleted file mode 100644 index 36203b3..0000000 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -using SushiBarDataModels.Enums; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.ViewModels -{ - public class OrderViewModel : IOrderModel - { - [DisplayName("Номер")] - public int Id { get; set; } - - public int SushiId { get; set; } - - [DisplayName("Изделие")] - public string SushiName { 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/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs deleted file mode 100644 index 8f9608c..0000000 --- a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarContracts.ViewModels -{ - public class SushiViewModel : ISushiModel - { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string SushiName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary SushiComponents - { - get; - set; - } = new(); - - } -} diff --git a/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs new file mode 100644 index 0000000..c1b6d91 --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/SushiBar/SushiBarDataModels — копия/IId.cs b/SushiBar/SushiBarDataModels — копия/IId.cs new file mode 100644 index 0000000..91a1366 --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/IId.cs @@ -0,0 +1,7 @@ +namespace SushiBarDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs b/SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs new file mode 100644 index 0000000..b82c233 --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + + } +} diff --git a/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs new file mode 100644 index 0000000..02ca513 --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using SushiBarDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IOrderModel : IId + { + int SushiId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs b/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs new file mode 100644 index 0000000..a6c7e0c --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface ISushiModel : IId + { + string SushiName { get; } + double Price { get; } + Dictionary SushiComponents { get; } + } +} diff --git a/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj b/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs new file mode 100644 index 0000000..26bfc23 --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs @@ -0,0 +1,58 @@ +using SushiBarFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string SushiFileName = "Sushi.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Sushis { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs new file mode 100644 index 0000000..c413598 --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs @@ -0,0 +1,86 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs new file mode 100644 index 0000000..1664507 --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs @@ -0,0 +1,94 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList(); + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachSushiName(x.GetViewModel)).ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return AttachSushiName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AttachSushiName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AttachSushiName(order.GetViewModel); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order != null) + { + source.Orders.Remove(order); + source.SaveOrders(); + return AttachSushiName(order.GetViewModel); + } + return null; + } + + private OrderViewModel? AttachSushiName(OrderViewModel? model) + { + if (model == null) + { + return null; + } + var sushi = source.Sushis.FirstOrDefault(x => x.Id == model.SushiId); + if (sushi != null) + { + model.SushiName = sushi.SushiName; + } + return model; + } + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs new file mode 100644 index 0000000..ac04014 --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs @@ -0,0 +1,86 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement.Implements +{ + public class SushiStorage : ISushiStorage + { + private readonly DataFileSingleton source; + + public SushiStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Sushis.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName)) + { + return new(); + } + return source.Sushis.Where(x => x.SushiName.Contains(model.SushiName)).Select(x => x.GetViewModel).ToList(); + } + + public SushiViewModel? GetElement(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) + { + return null; + } + return source.Sushis.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.SushiName) && x.SushiName == model.SushiName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public SushiViewModel? Insert(SushiBindingModel model) + { + model.Id = source.Sushis.Count > 0 ? source.Sushis.Max(x => x.Id) + 1 : 1; + var newSushi = Sushi.Create(model); + if (newSushi == null) + { + return null; + } + source.Sushis.Add(newSushi); + source.SaveSushis(); + return newSushi.GetViewModel; + } + + public SushiViewModel? Update(SushiBindingModel model) + { + var Sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id); + if (Sushi == null) + { + return null; + } + Sushi.Update(model); + source.SaveSushis(); + return Sushi.GetViewModel; + } + + public SushiViewModel? Delete(SushiBindingModel model) + { + var Sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id); + if (Sushi != null) + { + source.Sushis.Remove(Sushi); + source.SaveSushis(); + return Sushi.GetViewModel; + } + return null; + } + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Component.cs b/SushiBar/SushiBarFileImplement — копия/Models/Component.cs new file mode 100644 index 0000000..05caf5e --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Models/Component.cs @@ -0,0 +1,70 @@ + +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Order.cs b/SushiBar/SushiBarFileImplement — копия/Models/Order.cs new file mode 100644 index 0000000..a8a207d --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Models/Order.cs @@ -0,0 +1,92 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + internal class Order : IOrderModel + { + public int Id { get; private set; } + public int SushiId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + SushiId = model.SushiId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + string dateImplement = element.Element("DateImplement")!.Value; + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) + }; + + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + SushiId = SushiId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("SushiId", SushiId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs b/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs new file mode 100644 index 0000000..8396f75 --- /dev/null +++ b/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs @@ -0,0 +1,86 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Sushi : ISushiModel + { + public int Id { get; private set; } + public string SushiName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _SushiComponents = null; + public Dictionary SushiComponents + { + get + { + if (_SushiComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _SushiComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + } + return _SushiComponents; + } + } + public static Sushi? Create(SushiBindingModel model) + { + if (model == null) + { + return null; + } + return new Sushi() + { + Id = model.Id, + SushiName = model.SushiName, + Price = model.Price, + Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Sushi? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Sushi() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + SushiName = element.Element("SushiName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("SushiComponents")!.Elements("SushiComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(SushiBindingModel model) + { + if (model == null) + { + return; + } + SushiName = model.SushiName; + Price = model.Price; + Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _SushiComponents = null; + } + public SushiViewModel GetViewModel => new() + { + Id = Id, + SushiName = SushiName, + Price = Price, + SushiComponents = SushiComponents + }; + public XElement GetXElement => new("Sushi", + new XAttribute("Id", Id), + new XElement("SushiName", SushiName), + new XElement("Price", Price.ToString()), + new XElement("SushiComponents", Components.Select( + x => new XElement("SushiComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj similarity index 79% rename from SushiBar/SushiBarContracts/SushiBarContracts.csproj rename to SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj index a25f2c8..ec020c5 100644 --- a/SushiBar/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj @@ -7,6 +7,7 @@ + diff --git a/SushiBar/SushiBarListImplement/App.config b/SushiBar/SushiBarListImplement/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/SushiBar/SushiBarListImplement/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj deleted file mode 100644 index bbf9d38..0000000 --- a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj +++ /dev/null @@ -1,55 +0,0 @@ - - - - - Debug - AnyCPU - {1BBC3A4B-BF06-4EBF-AA20-863B369E234E} - Exe - SushiBarListImplement - SushiBarListImplement - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - {993e0787-3ad5-4743-8997-c828cd0cdc10} - SushiBarContracts - - - {76043de7-71bc-41e8-b4c0-ecfaddfbf55f} - SushiBarDataModels - - - - - - - - - - \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs similarity index 88% rename from SushiBar/SushiBarListImplement/DataListSingleton.cs rename to SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs index f0f9a1b..6eabe76 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs @@ -12,12 +12,12 @@ namespace SushiBarListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Sushis { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Sushis = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/ComponentStorage.cs b/SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs similarity index 98% rename from SushiBar/SushiBarListImplement/ComponentStorage.cs rename to SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs index e06268f..9ce66c4 100644 --- a/SushiBar/SushiBarListImplement/ComponentStorage.cs +++ b/SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs @@ -11,7 +11,7 @@ using SushiBarListImplement.Models; namespace SushiBarListImplement.Implements { - internal class ComponentStorage : IComponentStorage + public class ComponentStorage : IComponentStorage { private readonly DataListSingleton _source; public ComponentStorage() @@ -107,4 +107,4 @@ namespace SushiBarListImplement.Implements } } -} + diff --git a/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs new file mode 100644 index 0000000..957b9fa --- /dev/null +++ b/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs @@ -0,0 +1,125 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.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(AttachSushiName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachSushiName(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 AttachSushiName(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 AttachSushiName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachSushiName(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 AttachSushiName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachSushiName(OrderViewModel model) + { + foreach (var sushi in _source.Sushis) + { + if (sushi.Id == model.SushiId) + { + model.SushiName = sushi.SushiName; + return model; + } + } + return model; + } + } +} diff --git a/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs new file mode 100644 index 0000000..005e5c7 --- /dev/null +++ b/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs @@ -0,0 +1,113 @@ +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Implements +{ + public class SushiStorage : ISushiStorage + { + private readonly DataListSingleton _source; + + public SushiStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var Sushis in _source.Sushis) + { + result.Add(Sushis.GetViewModel); + } + return result; + } + + public List GetFilteredList(SushiSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SushiName)) + { + return result; + } + foreach (var Sushis in _source.Sushis) + { + if (Sushis.SushiName.Contains(model.SushiName)) + { + result.Add(Sushis.GetViewModel); + } + } + return result; + } + + public SushiViewModel? GetElement(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) + { + return null; + } + foreach (var sushis in _source.Sushis) + { + if ((!string.IsNullOrEmpty(model.SushiName) && sushis.SushiName == model.SushiName) || + (model.Id.HasValue && sushis.Id == model.Id)) + { + return sushis.GetViewModel; + } + } + return null; + } + + public SushiViewModel? Insert(SushiBindingModel model) + { + model.Id = 1; + foreach (var sushis in _source.Sushis) + { + if (model.Id <= sushis.Id) + { + model.Id = sushis.Id + 1; + } + } + var newSushis = Sushi.Create(model); + if (newSushis == null) + { + return null; + } + _source.Sushis.Add(newSushis); + return newSushis.GetViewModel; + } + + public SushiViewModel? Update(SushiBindingModel model) + { + foreach (var sushis in _source.Sushis) + { + if (sushis.Id == model.Id) + { + sushis.Update(model); + return sushis.GetViewModel; + } + } + return null; + } + + public SushiViewModel? Delete(SushiBindingModel model) + { + for (int i = 0; i < _source.Sushis.Count; ++i) + { + if (_source.Sushis[i].Id == model.Id) + { + var element = _source.Sushis[i]; + _source.Sushis.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Component.cs b/SushiBar/SushiBarListImplement_ — копия/Models/Component.cs similarity index 87% rename from SushiBar/SushiBarListImplement/Component.cs rename to SushiBar/SushiBarListImplement_ — копия/Models/Component.cs index 453d89c..ecebaf6 100644 --- a/SushiBar/SushiBarListImplement/Component.cs +++ b/SushiBar/SushiBarListImplement_ — копия/Models/Component.cs @@ -3,6 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using SushiBarContracts; +using SushiBarDataModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; namespace SushiBarListImplement.Models { diff --git a/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs b/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs new file mode 100644 index 0000000..f1d69d4 --- /dev/null +++ b/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs @@ -0,0 +1,62 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int SushiId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + SushiId = model.SushiId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + SushiId = SushiId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/SushiBar/SushiBarListImplement/Sushi.cs b/SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs similarity index 50% rename from SushiBar/SushiBarListImplement/Sushi.cs rename to SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs index 133090b..6f6bce2 100644 --- a/SushiBar/SushiBarListImplement/Sushi.cs +++ b/SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs @@ -3,49 +3,52 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; namespace SushiBarListImplement.Models { - internal class Sushi : IProductModel + public class Sushi : ISushiModel { public int Id { get; private set; } - public string ProductName { get; private set; } = string.Empty; + public string SushiName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary ProductComponents + public Dictionary SushiComponents { get; private set; } = new Dictionary(); - public static Product? Create(ProductBindingModel? model) + public static Sushi? Create(SushiBindingModel? model) { if (model == null) { return null; } - return new Product() + return new Sushi() { Id = model.Id, - ProductName = model.ProductName, + SushiName = model.SushiName, Price = model.Price, - ProductComponents = model.ProductComponents + SushiComponents = model.SushiComponents }; } - public void Update(ProductBindingModel? model) + public void Update(SushiBindingModel? model) { if (model == null) { return; } - ProductName = model.ProductName; + SushiName = model.SushiName; Price = model.Price; - ProductComponents = model.ProductComponents; + SushiComponents = model.SushiComponents; } - public ProductViewModel GetViewModel => new() + public SushiViewModel GetViewModel => new() { Id = Id, - ProductName = ProductName, + SushiName = SushiName, Price = Price, - ProductComponents = ProductComponents + SushiComponents = SushiComponents }; } diff --git a/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj similarity index 64% rename from SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj rename to SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj index 8d13c8d..ec020c5 100644 --- a/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj +++ b/SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,12 +6,9 @@ enable - - - - + diff --git a/SushiBar/SushiBarView/FormComponent.Designer.cs b/SushiBar/SushiBarView/FormComponent.Designer.cs deleted file mode 100644 index e12b999..0000000 --- a/SushiBar/SushiBarView/FormComponent.Designer.cs +++ /dev/null @@ -1,118 +0,0 @@ -namespace SushiBarView -{ - partial class FormComponent - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.ButtonSave = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.labelName = new System.Windows.Forms.Label(); - this.labelCost = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxCost = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(174, 99); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(87, 26); - this.ButtonSave.TabIndex = 0; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(267, 99); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(87, 26); - this.ButtonCancel.TabIndex = 1; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - // - // labelName - // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(12, 24); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(59, 15); - this.labelName.TabIndex = 2; - this.labelName.Text = "Название"; - // - // labelCost - // - this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(12, 65); - this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(35, 15); - this.labelCost.TabIndex = 3; - this.labelCost.Text = "Цена"; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(83, 21); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(262, 23); - this.textBoxName.TabIndex = 4; - // - // textBoxCost - // - this.textBoxCost.Location = new System.Drawing.Point(83, 57); - this.textBoxCost.Name = "textBoxCost"; - this.textBoxCost.Size = new System.Drawing.Size(262, 23); - this.textBoxCost.TabIndex = 5; - // - // FormComponent - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(354, 131); - this.Controls.Add(this.textBoxCost); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelCost); - this.Controls.Add(this.labelName); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Name = "FormComponent"; - this.Text = "Компонент"; - this.Load += new System.EventHandler(this.FormComponent_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private Button ButtonSave; - private Button ButtonCancel; - private Label labelName; - private Label labelCost; - private TextBox textBoxName; - private TextBox textBoxCost; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.cs b/SushiBar/SushiBarView/FormComponent.cs deleted file mode 100644 index dfacef0..0000000 --- a/SushiBar/SushiBarView/FormComponent.cs +++ /dev/null @@ -1,88 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; - - -namespace SushiBarView -{ - public partial class FormComponent : Form - { - private readonly ILogger _logger; - private readonly IComponentLogic _logic; - private int? _id; - public int Id { set { _id = value; } } - public FormComponent(ILogger logger, IComponentLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show(" ", "", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation(" "); - try - { - var model = new ComponentBindingModel - { - Id = _id ?? 0, - ComponentName = textBoxName.Text, - Cost = Convert.ToDouble(textBoxCost.Text) - }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); - if (!operationResult) - { - throw new Exception(" . ."); - } - MessageBox.Show(" ", "", - MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - - } - - private void FormComponent_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - try - { - _logger.LogInformation(" "); - var view = _logic.ReadElement(new ComponentSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.ComponentName; - textBoxCost.Text = view.Cost.ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.resx b/SushiBar/SushiBarView/FormComponent.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormComponent.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponents.Designer.cs b/SushiBar/SushiBarView/FormComponents.Designer.cs deleted file mode 100644 index 27db7a7..0000000 --- a/SushiBar/SushiBarView/FormComponents.Designer.cs +++ /dev/null @@ -1,115 +0,0 @@ -namespace SushiBarView -{ - partial class FormComponents - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.ButtonUpd = new System.Windows.Forms.Button(); - this.ButtonDel = new System.Windows.Forms.Button(); - this.ButtonAdd = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // ButtonUpd - // - this.ButtonUpd.Location = new System.Drawing.Point(499, 74); - this.ButtonUpd.Name = "ButtonUpd"; - this.ButtonUpd.Size = new System.Drawing.Size(112, 35); - this.ButtonUpd.TabIndex = 0; - this.ButtonUpd.Text = "Изменить"; - this.ButtonUpd.UseVisualStyleBackColor = true; - this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // ButtonDel - // - this.ButtonDel.Location = new System.Drawing.Point(499, 126); - this.ButtonDel.Name = "ButtonDel"; - this.ButtonDel.Size = new System.Drawing.Size(112, 35); - this.ButtonDel.TabIndex = 1; - this.ButtonDel.Text = "Удалить"; - this.ButtonDel.UseVisualStyleBackColor = true; - this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // ButtonAdd - // - this.ButtonAdd.Location = new System.Drawing.Point(499, 23); - this.ButtonAdd.Name = "ButtonAdd"; - this.ButtonAdd.Size = new System.Drawing.Size(112, 35); - this.ButtonAdd.TabIndex = 2; - this.ButtonAdd.Text = "Добавить"; - this.ButtonAdd.UseVisualStyleBackColor = true; - this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // ButtonRef - // - this.ButtonRef.Location = new System.Drawing.Point(499, 177); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(112, 35); - this.ButtonRef.TabIndex = 3; - this.ButtonRef.Text = "Обновить"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 12); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(454, 365); - this.dataGridView.TabIndex = 4; - // - // FormComponents - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(623, 389); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonAdd); - this.Controls.Add(this.ButtonDel); - this.Controls.Add(this.ButtonUpd); - this.Name = "FormComponents"; - this.Text = "FormComponents"; - this.Load += new System.EventHandler(this.FormComponents_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private Button ButtonUpd; - private Button ButtonDel; - private Button ButtonAdd; - private Button ButtonRef; - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponents.cs b/SushiBar/SushiBarView/FormComponents.cs deleted file mode 100644 index 704c8e0..0000000 --- a/SushiBar/SushiBarView/FormComponents.cs +++ /dev/null @@ -1,123 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace SushiBarView -{ - public partial class FormComponents : Form - { - public FormComponents() - { - InitializeComponent(); - } - private readonly ILogger _logger; - private readonly IComponentLogic _logic; - public FormComponents(ILogger logger, IComponentLogic - logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - - private void FormComponents_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); - try - { - if (!_logic.Delete(new ComponentBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - - } -} diff --git a/SushiBar/SushiBarView/FormComponents.resx b/SushiBar/SushiBarView/FormComponents.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormComponents.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateOrder.Designer.cs b/SushiBar/SushiBarView/FormCreateOrder.Designer.cs deleted file mode 100644 index fe9c140..0000000 --- a/SushiBar/SushiBarView/FormCreateOrder.Designer.cs +++ /dev/null @@ -1,145 +0,0 @@ -namespace SushiBarView -{ - 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.textBoxCount = new System.Windows.Forms.TextBox(); - this.labelCost = new System.Windows.Forms.Label(); - this.labelName = new System.Windows.Forms.Label(); - this.textBoxSum = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.comboBoxSushi = new System.Windows.Forms.ComboBox(); - this.SuspendLayout(); - // - // textBoxCount - // - this.textBoxCount.Location = new System.Drawing.Point(83, 42); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(262, 23); - this.textBoxCount.TabIndex = 9; - this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCost_TextChanged); - // - // labelCost - // - this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(5, 45); - this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(72, 15); - this.labelCost.TabIndex = 7; - this.labelCost.Text = "Количество"; - this.labelCost.Click += new System.EventHandler(this.labelCost_Click); - // - // labelName - // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(5, 12); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(53, 15); - this.labelName.TabIndex = 6; - this.labelName.Text = "Изделие"; - // - // textBoxSum - // - this.textBoxSum.Location = new System.Drawing.Point(83, 80); - this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.Size = new System.Drawing.Size(262, 23); - this.textBoxSum.TabIndex = 11; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(5, 83); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(45, 15); - this.label1.TabIndex = 10; - this.label1.Text = "Сумма"; - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(258, 120); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(87, 26); - this.ButtonCancel.TabIndex = 13; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(165, 120); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(87, 26); - this.ButtonSave.TabIndex = 12; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // comboBoxSushi - // - this.comboBoxSushi.FormattingEnabled = true; - this.comboBoxSushi.Location = new System.Drawing.Point(83, 9); - this.comboBoxSushi.Name = "comboBoxSushi"; - this.comboBoxSushi.Size = new System.Drawing.Size(262, 23); - this.comboBoxSushi.TabIndex = 14; - this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); - // - // FormCreateOrder - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(354, 158); - this.Controls.Add(this.comboBoxSushi); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.label1); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.labelCost); - this.Controls.Add(this.labelName); - this.Name = "FormCreateOrder"; - this.Text = "FormCreateOrder"; - this.Load += new System.EventHandler(this.FormCreateOrder_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private TextBox textBoxCount; - private Label labelCost; - private Label labelName; - private TextBox textBoxSum; - private Label label1; - private Button ButtonCancel; - private Button ButtonSave; - private ComboBox comboBoxSushi; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateOrder.cs b/SushiBar/SushiBarView/FormCreateOrder.cs deleted file mode 100644 index fd23448..0000000 --- a/SushiBar/SushiBarView/FormCreateOrder.cs +++ /dev/null @@ -1,136 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using System; -using System.Collections; -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 SushiBarView -{ - public partial class FormCreateOrder : Form - { - private readonly ILogger _logger; - private readonly ISushiLogic _logicP; - private readonly IOrderLogic _logicO; - private List? _list; - public FormCreateOrder() - { - InitializeComponent(); - } - public FormCreateOrder(ILogger logger, ISushiLogic logicP, IOrderLogic logicO) - { - InitializeComponent(); - _logger = logger; - _logicP = logicP; - _logicO = logicO; - } - private void FormCreateOrder_Load(object sender, EventArgs e) - { - _logger.LogInformation("Загрузка изделий для заказа"); - _list = _logicP.ReadList(null); - if (_list != null) - { - comboBoxSushi.DisplayMember = "SushiName"; - comboBoxSushi.ValueMember = "Id"; - comboBoxSushi.DataSource = _list; - comboBoxSushi.SelectedItem = null; - _logger.LogInformation("Загрузка суши для заказа"); - } - } - private void labelCost_Click(object sender, EventArgs e) - { - - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxCount.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxSushi.SelectedValue == null) - { - MessageBox.Show("Выберите изделие", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Создание заказа"); - try - { - var operationResult = _logicO.CreateOrder(new OrderBindingModel - { - SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), - Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) - }); - if (!operationResult) - { - throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void CalcSum() - { - if (comboBoxSushi.SelectedValue != null && - !string.IsNullOrEmpty(textBoxCount.Text)) - { - try - { - int id = Convert.ToInt32(comboBoxSushi.SelectedValue); - var sushi = _logicP.ReadElement(new SushiSearchModel - { - Id - = id - }); - int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), - 2).ToString(); - _logger.LogInformation("Расчет суммы заказа"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка расчета суммы заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - CalcSum(); - } - - private void textBoxCost_TextChanged(object sender, EventArgs e) - { - CalcSum(); - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/SushiBar/SushiBarView/FormCreateOrder.resx b/SushiBar/SushiBarView/FormCreateOrder.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormCreateOrder.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs deleted file mode 100644 index 0c2348d..0000000 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ /dev/null @@ -1,175 +0,0 @@ -namespace SushiBarView -{ - 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.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // ButtonCreateOrder - // - this.ButtonCreateOrder.Location = new System.Drawing.Point(676, 37); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonCreateOrder.TabIndex = 0; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // ButtonOrderReady - // - this.ButtonOrderReady.Location = new System.Drawing.Point(676, 180); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(217, 29); - this.ButtonOrderReady.TabIndex = 1; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // ButtonRef - // - this.ButtonRef.Location = new System.Drawing.Point(676, 323); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(217, 29); - this.ButtonRef.TabIndex = 2; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // ButtonIssuedOrder - // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(676, 256); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonIssuedOrder.TabIndex = 3; - this.ButtonIssuedOrder.Text = "Заказ выполнен"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // ButtonTakeOrderInWork - // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(676, 109); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(217, 29); - this.ButtonTakeOrderInWork.TabIndex = 4; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // menuStrip - // - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(922, 24); - this.menuStrip.TabIndex = 5; - this.menuStrip.Text = "menuStrip1"; - // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItemToolStripMenuItem, - this.sushiToolStripMenuItemToolStripMenuItem}); - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItem1.Text = "Справочники"; - // - // componentsToolStripMenuItemToolStripMenuItem - // - this.componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; - this.componentsToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; - this.componentsToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); - // - // sushiToolStripMenuItemToolStripMenuItem - // - this.sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; - this.sushiToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; - this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(647, 344); - this.dataGridView.TabIndex = 6; - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(922, 383); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "FormMain"; - 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 Button ButtonCreateOrder; - private Button ButtonOrderReady; - private Button ButtonRef; - private Button ButtonIssuedOrder; - private Button ButtonTakeOrderInWork; - private MenuStrip menuStrip; - private ToolStripMenuItem toolStripMenuItem1; - private ToolStripMenuItem componentsToolStripMenuItemToolStripMenuItem; - private ToolStripMenuItem sushiToolStripMenuItemToolStripMenuItem; - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs deleted file mode 100644 index 0ca85b9..0000000 --- a/SushiBar/SushiBarView/FormMain.cs +++ /dev/null @@ -1,171 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace SushiBarView -{ - public partial class FormMain : Form - { - public FormMain() - { - InitializeComponent(); - } - - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - - 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["SushiId"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void componentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void sushiToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSushis)); - if (service is FormSushis form) - { - form.ShowDialog(); - } - } - - 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(); - } - - } -} diff --git a/SushiBar/SushiBarView/FormMain.resx b/SushiBar/SushiBarView/FormMain.resx deleted file mode 100644 index 81a9e3d..0000000 --- a/SushiBar/SushiBarView/FormMain.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushi.Designer.cs b/SushiBar/SushiBarView/FormSushi.Designer.cs deleted file mode 100644 index 3f53aec..0000000 --- a/SushiBar/SushiBarView/FormSushi.Designer.cs +++ /dev/null @@ -1,198 +0,0 @@ -namespace SushiBarView -{ - partial class FormSushi - { - /// - /// 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.labelCost = new System.Windows.Forms.Label(); - this.labelName = new System.Windows.Forms.Label(); - this.panel1 = new System.Windows.Forms.Panel(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonAdd = new System.Windows.Forms.Button(); - this.ButtonDel = new System.Windows.Forms.Button(); - this.ButtonUpd = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // textBoxPrice - // - this.textBoxPrice.Location = new System.Drawing.Point(84, 48); - this.textBoxPrice.Name = "textBoxPrice"; - this.textBoxPrice.Size = new System.Drawing.Size(262, 23); - this.textBoxPrice.TabIndex = 9; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(84, 12); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(262, 23); - this.textBoxName.TabIndex = 8; - // - // labelCost - // - this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(13, 56); - this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(35, 15); - this.labelCost.TabIndex = 7; - this.labelCost.Text = "Цена"; - // - // labelName - // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(13, 15); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(59, 15); - this.labelName.TabIndex = 6; - this.labelName.Text = "Название"; - // - // panel1 - // - this.panel1.Controls.Add(this.dataGridView); - this.panel1.Controls.Add(this.ButtonRef); - this.panel1.Controls.Add(this.ButtonAdd); - this.panel1.Controls.Add(this.ButtonDel); - this.panel1.Controls.Add(this.ButtonUpd); - this.panel1.Location = new System.Drawing.Point(13, 100); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(725, 282); - this.panel1.TabIndex = 10; - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(18, 13); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(566, 255); - this.dataGridView.TabIndex = 8; - // - // ButtonRef - // - this.ButtonRef.Location = new System.Drawing.Point(598, 198); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(112, 35); - this.ButtonRef.TabIndex = 7; - this.ButtonRef.Text = "Обновить"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // ButtonAdd - // - this.ButtonAdd.Location = new System.Drawing.Point(598, 44); - this.ButtonAdd.Name = "ButtonAdd"; - this.ButtonAdd.Size = new System.Drawing.Size(112, 35); - this.ButtonAdd.TabIndex = 6; - this.ButtonAdd.Text = "Добавить"; - this.ButtonAdd.UseVisualStyleBackColor = true; - this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // ButtonDel - // - this.ButtonDel.Location = new System.Drawing.Point(598, 147); - this.ButtonDel.Name = "ButtonDel"; - this.ButtonDel.Size = new System.Drawing.Size(112, 35); - this.ButtonDel.TabIndex = 5; - this.ButtonDel.Text = "Удалить"; - this.ButtonDel.UseVisualStyleBackColor = true; - this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // ButtonUpd - // - this.ButtonUpd.Location = new System.Drawing.Point(598, 95); - this.ButtonUpd.Name = "ButtonUpd"; - this.ButtonUpd.Size = new System.Drawing.Size(112, 35); - this.ButtonUpd.TabIndex = 4; - this.ButtonUpd.Text = "Изменить"; - this.ButtonUpd.UseVisualStyleBackColor = true; - this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(651, 412); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(87, 26); - this.ButtonCancel.TabIndex = 12; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(558, 412); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(87, 26); - this.ButtonSave.TabIndex = 11; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // FormSushi - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(750, 450); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Controls.Add(this.panel1); - this.Controls.Add(this.textBoxPrice); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelCost); - this.Controls.Add(this.labelName); - this.Name = "FormSushi"; - this.Text = "FormSushi"; - this.Load += new System.EventHandler(this.FormSushi_Load); - this.panel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private TextBox textBoxPrice; - private TextBox textBoxName; - private Label labelCost; - private Label labelName; - private Panel panel1; - private Button ButtonRef; - private Button ButtonAdd; - private Button ButtonDel; - private Button ButtonUpd; - private DataGridView dataGridView; - private Button ButtonCancel; - private Button ButtonSave; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushi.cs b/SushiBar/SushiBarView/FormSushi.cs deleted file mode 100644 index b265edb..0000000 --- a/SushiBar/SushiBarView/FormSushi.cs +++ /dev/null @@ -1,252 +0,0 @@ -using Microsoft.Extensions.Logging; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.SearchModels; - - -namespace SushiBarView -{ - public partial class FormSushi : Form - { - private readonly ILogger _logger; - private readonly ISushiLogic _logic; - private int? _id; - private Dictionary _sushiComponents; - public int Id { set { _id = value; } } - - public FormSushi() - { - InitializeComponent(); - } - public FormSushi(ILogger logger, ISushiLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _sushiComponents = new Dictionary(); - } - - private void FormSushi_Load(object sender, EventArgs e) - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.AllowUserToAddRows = false; - DataGridViewTextBoxColumn Id = new DataGridViewTextBoxColumn(); - DataGridViewTextBoxColumn Component = new DataGridViewTextBoxColumn(); - DataGridViewTextBoxColumn Number = new DataGridViewTextBoxColumn(); - Component.HeaderText = "Количество"; - Number.HeaderText = "Компонент"; - Number.Name = "Number"; - Id.Name = "Id"; - dataGridView.Columns.Add(Id); - dataGridView.Columns.Add(Number); - dataGridView.Columns.Add(Component); - dataGridView.Columns["Id"].Visible = false; - - dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - if (_id.HasValue) - { - _logger.LogInformation("Загрузка суши"); - try - { - var view = _logic.ReadElement(new SushiSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.SushiName; - textBoxPrice.Text = view.Price.ToString(); - _sushiComponents = view.SushiComponents ?? new - Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка компонент изделия"); - try - { - if (_sushiComponents != null) - { - dataGridView.Rows.Clear(); - foreach (var pc in _sushiComponents) - { - dataGridView.Rows.Add(new object[] { pc.Key, -pc.Value.Item1.ComponentName, pc.Value.Item2 }); - } - textBoxPrice.Text = CalcPrice().ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); - if (service is FormSushiComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - if (_sushiComponents.ContainsKey(form.Id)) - { - _sushiComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _sushiComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); - } - } - } - - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); - if (service is FormSushiComponent form) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _sushiComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - _sushiComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } - - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - try - { - _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _sushiComponents?.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 (_sushiComponents == null || _sushiComponents.Count == 0) - { - MessageBox.Show("Заполните компоненты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение изделия"); - try - { - var model = new SushiBindingModel - { - Id = _id ?? 0, - SushiName = textBoxName.Text, - Price = Convert.ToDouble(textBoxPrice.Text), - SushiComponents = _sushiComponents - }; - 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 _sushiComponents) - { - price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); - } - return Math.Round(price * 1.1, 2); - } - } -} diff --git a/SushiBar/SushiBarView/FormSushi.resx b/SushiBar/SushiBarView/FormSushi.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormSushi.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushiComponent.Designer.cs b/SushiBar/SushiBarView/FormSushiComponent.Designer.cs deleted file mode 100644 index 17b2956..0000000 --- a/SushiBar/SushiBarView/FormSushiComponent.Designer.cs +++ /dev/null @@ -1,119 +0,0 @@ -namespace SushiBarView -{ - partial class FormSushiComponent - { - /// - /// 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.textBoxCount = new System.Windows.Forms.TextBox(); - this.labelCost = new System.Windows.Forms.Label(); - this.labelName = new System.Windows.Forms.Label(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.comboBoxComponent = new System.Windows.Forms.ComboBox(); - this.SuspendLayout(); - // - // textBoxCount - // - this.textBoxCount.Location = new System.Drawing.Point(87, 54); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(262, 23); - this.textBoxCount.TabIndex = 11; - // - // labelCost - // - this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(12, 57); - this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(72, 15); - this.labelCost.TabIndex = 9; - this.labelCost.Text = "Количество"; - // - // labelName - // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(12, 24); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(69, 15); - this.labelName.TabIndex = 8; - this.labelName.Text = "Компонент"; - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(271, 96); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(87, 26); - this.ButtonCancel.TabIndex = 7; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(178, 96); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(87, 26); - this.ButtonSave.TabIndex = 6; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // comboBoxComponent - // - this.comboBoxComponent.FormattingEnabled = true; - this.comboBoxComponent.Location = new System.Drawing.Point(87, 21); - this.comboBoxComponent.Name = "comboBoxComponent"; - this.comboBoxComponent.Size = new System.Drawing.Size(262, 23); - this.comboBoxComponent.TabIndex = 12; - // - // FormSushiComponent - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(375, 141); - this.Controls.Add(this.comboBoxComponent); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.labelCost); - this.Controls.Add(this.labelName); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Name = "FormSushiComponent"; - this.Text = "FormSushiComponent"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private TextBox textBoxCount; - private Label labelCost; - private Label labelName; - private Button ButtonCancel; - private Button ButtonSave; - private ComboBox comboBoxComponent; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushiComponent.cs b/SushiBar/SushiBarView/FormSushiComponent.cs deleted file mode 100644 index a7a020a..0000000 --- a/SushiBar/SushiBarView/FormSushiComponent.cs +++ /dev/null @@ -1,99 +0,0 @@ -using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.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 SushiBarView -{ - public partial class FormSushiComponent : Form - { - private readonly List? _list; - public int Id - { - get - { - return - Convert.ToInt32(comboBoxComponent.SelectedValue); - } - set - { - comboBoxComponent.SelectedValue = value; - } - } - - public IComponentModel? ComponentModel - { - get - { - if (_list == null) - { - return null; - } - foreach (var elem in _list) - { - if (elem.Id == Id) - { - return elem; - } - } - return null; - } - } - - public int Count - { - get { return Convert.ToInt32(textBoxCount.Text); } - set - { textBoxCount.Text = value.ToString(); } - } - public FormSushiComponent(IComponentLogic logic) - { - InitializeComponent(); - _list = logic.ReadList(null); - if (_list != null) - { - comboBoxComponent.DisplayMember = "ComponentName"; - comboBoxComponent.ValueMember = "Id"; - comboBoxComponent.DataSource = _list; - comboBoxComponent.SelectedItem = null; - } - } - public FormSushiComponent() - { - InitializeComponent(); - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxCount.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxComponent.SelectedValue == null) - { - MessageBox.Show("Выберите компонент", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - DialogResult = DialogResult.OK; - Close(); - - } - } -} diff --git a/SushiBar/SushiBarView/FormSushiComponent.resx b/SushiBar/SushiBarView/FormSushiComponent.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormSushiComponent.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushis.Designer.cs b/SushiBar/SushiBarView/FormSushis.Designer.cs deleted file mode 100644 index 4cc40f2..0000000 --- a/SushiBar/SushiBarView/FormSushis.Designer.cs +++ /dev/null @@ -1,115 +0,0 @@ -namespace SushiBarView -{ - partial class FormSushis - { - /// - /// 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.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonAdd = new System.Windows.Forms.Button(); - this.ButtonDel = new System.Windows.Forms.Button(); - this.ButtonUpd = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 12); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(454, 365); - this.dataGridView.TabIndex = 9; - // - // ButtonRef - // - this.ButtonRef.Location = new System.Drawing.Point(499, 177); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(112, 35); - this.ButtonRef.TabIndex = 8; - this.ButtonRef.Text = "Обновить"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // ButtonAdd - // - this.ButtonAdd.Location = new System.Drawing.Point(499, 23); - this.ButtonAdd.Name = "ButtonAdd"; - this.ButtonAdd.Size = new System.Drawing.Size(112, 35); - this.ButtonAdd.TabIndex = 7; - this.ButtonAdd.Text = "Добавить"; - this.ButtonAdd.UseVisualStyleBackColor = true; - this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // ButtonDel - // - this.ButtonDel.Location = new System.Drawing.Point(499, 126); - this.ButtonDel.Name = "ButtonDel"; - this.ButtonDel.Size = new System.Drawing.Size(112, 35); - this.ButtonDel.TabIndex = 6; - this.ButtonDel.Text = "Удалить"; - this.ButtonDel.UseVisualStyleBackColor = true; - this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // ButtonUpd - // - this.ButtonUpd.Location = new System.Drawing.Point(499, 74); - this.ButtonUpd.Name = "ButtonUpd"; - this.ButtonUpd.Size = new System.Drawing.Size(112, 35); - this.ButtonUpd.TabIndex = 5; - this.ButtonUpd.Text = "Изменить"; - this.ButtonUpd.UseVisualStyleBackColor = true; - this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // FormSushis - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(637, 390); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonAdd); - this.Controls.Add(this.ButtonDel); - this.Controls.Add(this.ButtonUpd); - this.Name = "FormSushis"; - this.Text = "FormSushis"; - this.Load += new System.EventHandler(this.FormSushi_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private DataGridView dataGridView; - private Button ButtonRef; - private Button ButtonAdd; - private Button ButtonDel; - private Button ButtonUpd; - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushis.cs b/SushiBar/SushiBarView/FormSushis.cs deleted file mode 100644 index d5933eb..0000000 --- a/SushiBar/SushiBarView/FormSushis.cs +++ /dev/null @@ -1,121 +0,0 @@ -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; -using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; - -namespace SushiBarView -{ - public partial class FormSushis : Form - { - public FormSushis() - { - InitializeComponent(); - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); - if (service is FormSushi form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private readonly ILogger _logger; - private readonly ISushiLogic _logic; - - public FormSushis(ILogger logger, ISushiLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - - private void FormSushi_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["SushiComponents"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка суши"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки суши"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); - if (service is FormSushi 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 SushiBindingModel - { - 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/SushiBar/SushiBarView/FormSushis.resx b/SushiBar/SushiBarView/FormSushis.resx deleted file mode 100644 index f298a7b..0000000 --- a/SushiBar/SushiBarView/FormSushis.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs deleted file mode 100644 index 62a8d49..0000000 --- a/SushiBar/SushiBarView/Program.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using SushiBarContracts.BusinessLogicsContracts; -using System; -using SushiBarBusinessLogic.BusinessLogics; -using SushiBarFileImplement.Implements; -using SushiBarContracts.StoragesContracts; -using SushiBarView; -using NLog.Extensions.Logging; - - -namespace SushiBarView -{ - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - ApplicationConfiguration.Initialize(); - 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/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj deleted file mode 100644 index 574ede4..0000000 --- a/SushiBar/SushiBarView/SushiBarView.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - - - - - - - Always - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SushiBar/SushiBarView/nlog.config b/SushiBar/SushiBarView/nlog.config deleted file mode 100644 index 609afe6..0000000 --- a/SushiBar/SushiBarView/nlog.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file From c7d0d9f471746735c575f291196765d774cb316e Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 28 Feb 2024 12:24:48 +0400 Subject: [PATCH 03/13] aaaaaa --- SushiBar/SushiBar/Program.cs | 17 ++ SushiBar/SushiBar/SushiBar.csproj | 11 + SushiBar/SushiBarBusinessLogic/App.config | 6 + .../SushiBarBusinessLogic/ComponentLogic.cs | 111 ++++++++ .../SushiBarBusinessLogic.csproj | 48 ++++ .../SushiBarBusinessLogic_/ComponentLogic.cs | 117 ++++++++ SushiBar/SushiBarBusinessLogic_/OrderLogic.cs | 125 +++++++++ SushiBar/SushiBarBusinessLogic_/ShopLogic.cs | 160 +++++++++++ .../SushiBarBusinessLogic.csproj} | 7 +- SushiBar/SushiBarBusinessLogic_/SushiLogic.cs | 117 ++++++++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../BindingModels/ShopBindingModel.cs | 19 ++ .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BindingModels/SushiBindingModel.cs | 22 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/IShopLogic.cs | 21 ++ .../BusinessLogicsContracts/ISushiLogic.cs | 21 ++ .../SearchModels/ComponentSearchModel.cs | 14 + .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/ShopSearchModel.cs | 14 + .../SearchModels/SushiSearchModel.cs | 14 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 22 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../StoragesContracts/ISushiStorage.cs | 22 ++ .../SushiBarContracts.csproj} | 1 - .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 37 +++ .../ViewModels/ShopViewModel.cs | 22 ++ .../ViewModels/SushiViewModel.cs | 25 ++ .../Enums/OrderStatus.cs | 17 -- .../SushiBarDataModels — копия/IId.cs | 7 - .../Models/IOrderModel.cs | 19 -- .../Models/ISushiModel.cs | 15 -- .../SushiBarDataModels.csproj | 9 - .../SushiBarDataModels/Models/IShopModel.cs | 16 ++ .../Models/ISupplyModel.cs} | 8 +- .../DataFileSingleton.cs | 58 ---- .../Implements/ComponentStorage.cs | 86 ------ .../Implements/OrderStorage.cs | 94 ------- .../Implements/SushiStorage.cs | 86 ------ .../Models/Component.cs | 70 ----- .../Models/Order.cs | 92 ------- .../Models/Sushi.cs | 86 ------ SushiBar/SushiBarListImplement/App.config | 6 + .../Component.cs | 5 - .../ComponentStorage.cs | 4 +- .../DataListSingleton.cs | 4 +- .../Models => SushiBarListImplement}/Sushi.cs | 29 +- .../SushiBarListImplement.csproj | 55 ++++ .../Implements/OrderStorage.cs | 125 --------- .../Implements/SushiStorage.cs | 113 -------- .../Models/Order.cs | 62 ----- .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 113 ++++++++ .../SushiBarListImplement_/Models/Shop.cs | 59 ++++ .../SushiBarView/FormComponent.Designer.cs | 118 ++++++++ SushiBar/SushiBarView/FormComponent.cs | 88 ++++++ SushiBar/SushiBarView/FormComponent.resx | 60 +++++ .../SushiBarView/FormComponents.Designer.cs | 115 ++++++++ SushiBar/SushiBarView/FormComponents.cs | 123 +++++++++ SushiBar/SushiBarView/FormComponents.resx | 60 +++++ .../SushiBarView/FormCreateOrder.Designer.cs | 145 ++++++++++ SushiBar/SushiBarView/FormCreateOrder.cs | 136 ++++++++++ SushiBar/SushiBarView/FormCreateOrder.resx | 60 +++++ .../SushiBarView/FormCreateSupply.Designer.cs | 149 +++++++++++ SushiBar/SushiBarView/FormCreateSupply.cs | 99 +++++++ SushiBar/SushiBarView/FormCreateSupply.resx | 60 +++++ SushiBar/SushiBarView/FormMain.Designer.cs | 195 ++++++++++++++ SushiBar/SushiBarView/FormMain.cs | 189 +++++++++++++ SushiBar/SushiBarView/FormMain.resx | 63 +++++ SushiBar/SushiBarView/FormShop.Designer.cs | 201 ++++++++++++++ SushiBar/SushiBarView/FormShop.cs | 128 +++++++++ SushiBar/SushiBarView/FormShop.resx | 60 +++++ SushiBar/SushiBarView/FormShops.Designer.cs | 138 ++++++++++ SushiBar/SushiBarView/FormShops.cs | 116 ++++++++ SushiBar/SushiBarView/FormShops.resx | 60 +++++ SushiBar/SushiBarView/FormSushi.Designer.cs | 198 ++++++++++++++ SushiBar/SushiBarView/FormSushi.cs | 252 ++++++++++++++++++ SushiBar/SushiBarView/FormSushi.resx | 60 +++++ .../FormSushiComponent.Designer.cs | 119 +++++++++ SushiBar/SushiBarView/FormSushiComponent.cs | 99 +++++++ SushiBar/SushiBarView/FormSushiComponent.resx | 60 +++++ SushiBar/SushiBarView/FormSushis.Designer.cs | 115 ++++++++ SushiBar/SushiBarView/FormSushis.cs | 121 +++++++++ SushiBar/SushiBarView/FormSushis.resx | 60 +++++ SushiBar/SushiBarView/Program.cs | 58 ++++ SushiBar/SushiBarView/SushiBarView.csproj | 34 +++ SushiBar/SushiBarView/nlog.config | 15 ++ 91 files changed, 4965 insertions(+), 971 deletions(-) create mode 100644 SushiBar/SushiBar/Program.cs create mode 100644 SushiBar/SushiBar/SushiBar.csproj create mode 100644 SushiBar/SushiBarBusinessLogic/App.config create mode 100644 SushiBar/SushiBarBusinessLogic/ComponentLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj create mode 100644 SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/OrderLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/ShopLogic.cs rename SushiBar/{SushiBarFileImplement — копия/SushiBarFileImplement.csproj => SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj} (64%) create mode 100644 SushiBar/SushiBarBusinessLogic_/SushiLogic.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs rename SushiBar/{SushiBarListImplement_ — копия/SushiBarListImplement.csproj => SushiBarContracts/SushiBarContracts.csproj} (79%) create mode 100644 SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs delete mode 100644 SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs delete mode 100644 SushiBar/SushiBarDataModels — копия/IId.cs delete mode 100644 SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs delete mode 100644 SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs delete mode 100644 SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj create mode 100644 SushiBar/SushiBarDataModels/Models/IShopModel.cs rename SushiBar/{SushiBarDataModels — копия/Models/IComponentModel.cs => SushiBarDataModels/Models/ISupplyModel.cs} (57%) delete mode 100644 SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Component.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Order.cs delete mode 100644 SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs create mode 100644 SushiBar/SushiBarListImplement/App.config rename SushiBar/{SushiBarListImplement_ — копия/Models => SushiBarListImplement}/Component.cs (87%) rename SushiBar/{SushiBarListImplement_ — копия/Implements => SushiBarListImplement}/ComponentStorage.cs (98%) rename SushiBar/{SushiBarListImplement_ — копия => SushiBarListImplement}/DataListSingleton.cs (88%) rename SushiBar/{SushiBarListImplement_ — копия/Models => SushiBarListImplement}/Sushi.cs (50%) create mode 100644 SushiBar/SushiBarListImplement/SushiBarListImplement.csproj delete mode 100644 SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs delete mode 100644 SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs delete mode 100644 SushiBar/SushiBarListImplement_ — копия/Models/Order.cs create mode 100644 SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs create mode 100644 SushiBar/SushiBarListImplement_/Models/Shop.cs create mode 100644 SushiBar/SushiBarView/FormComponent.Designer.cs create mode 100644 SushiBar/SushiBarView/FormComponent.cs create mode 100644 SushiBar/SushiBarView/FormComponent.resx create mode 100644 SushiBar/SushiBarView/FormComponents.Designer.cs create mode 100644 SushiBar/SushiBarView/FormComponents.cs create mode 100644 SushiBar/SushiBarView/FormComponents.resx create mode 100644 SushiBar/SushiBarView/FormCreateOrder.Designer.cs create mode 100644 SushiBar/SushiBarView/FormCreateOrder.cs create mode 100644 SushiBar/SushiBarView/FormCreateOrder.resx create mode 100644 SushiBar/SushiBarView/FormCreateSupply.Designer.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.resx create mode 100644 SushiBar/SushiBarView/FormMain.Designer.cs create mode 100644 SushiBar/SushiBarView/FormMain.cs create mode 100644 SushiBar/SushiBarView/FormMain.resx create mode 100644 SushiBar/SushiBarView/FormShop.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShop.cs create mode 100644 SushiBar/SushiBarView/FormShop.resx create mode 100644 SushiBar/SushiBarView/FormShops.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShops.cs create mode 100644 SushiBar/SushiBarView/FormShops.resx create mode 100644 SushiBar/SushiBarView/FormSushi.Designer.cs create mode 100644 SushiBar/SushiBarView/FormSushi.cs create mode 100644 SushiBar/SushiBarView/FormSushi.resx create mode 100644 SushiBar/SushiBarView/FormSushiComponent.Designer.cs create mode 100644 SushiBar/SushiBarView/FormSushiComponent.cs create mode 100644 SushiBar/SushiBarView/FormSushiComponent.resx create mode 100644 SushiBar/SushiBarView/FormSushis.Designer.cs create mode 100644 SushiBar/SushiBarView/FormSushis.cs create mode 100644 SushiBar/SushiBarView/FormSushis.resx create mode 100644 SushiBar/SushiBarView/Program.cs create mode 100644 SushiBar/SushiBarView/SushiBarView.csproj create mode 100644 SushiBar/SushiBarView/nlog.config diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs new file mode 100644 index 0000000..9e07955 --- /dev/null +++ b/SushiBar/SushiBar/Program.cs @@ -0,0 +1,17 @@ +namespace SushiBar +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/SushiBar/SushiBar/SushiBar.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/App.config b/SushiBar/SushiBarBusinessLogic/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..f4885e5 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/ComponentLogic.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ComponentLogic + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть + больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. + Cost:{ Cost}. Id: { Id} + ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием + уже есть"); + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj new file mode 100644 index 0000000..166199b --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -0,0 +1,48 @@ + + + + + Debug + AnyCPU + {E9064087-924C-4E00-A9EA-8E922CF49D11} + Exe + SushiBarBusinessLogic + SushiBarBusinessLogic + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + {993e0787-3ad5-4743-8997-c828cd0cdc10} + SushiBarContracts + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs new file mode 100644 index 0000000..46d0d91 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id} ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs new file mode 100644 index 0000000..ac3e5f0 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.SushiId, model.Count, model.Sum, model.Id); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + model.DateCreate = element.DateCreate; + model.SushiId = element.SushiId; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (requiredStatus - model.Status == 1) + { + model.Status = requiredStatus; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs new file mode 100644 index 0000000..645b4e2 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs @@ -0,0 +1,160 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly ISushiStorage _sushiStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, ISushiStorage sushiStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _sushiStorage = sushiStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.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(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopSushis.ContainsKey(model.SushiId)) + { + var oldValue = shop.ShopSushis[model.SushiId]; + oldValue.Item2 += model.Count; + shop.ShopSushis[model.SushiId] = oldValue; + } + else + { + var sushi = _sushiStorage.GetElement(new SushiSearchModel + { + Id = model.SushiId + }); + if (sushi == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.SushiId} не найденн"); + } + shop.ShopSushis.Add(model.SushiId, (sushi, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj b/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj similarity index 64% rename from SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj rename to SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj index ec020c5..8d13c8d 100644 --- a/SushiBar/SushiBarFileImplement — копия/SushiBarFileImplement.csproj +++ b/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,9 +6,12 @@ enable + + + + - diff --git a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs new file mode 100644 index 0000000..fefe4a4 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class SushiLogic :ISushiLogic + { + private readonly ILogger _logger; + private readonly ISushiStorage _SushiStorage; + public SushiLogic(ILogger logger, ISushiStorage SushiStorage) + { + _logger = logger; + _SushiStorage = SushiStorage; + } + public List? ReadList(SushiSearchModel? model) + { + _logger.LogInformation("ReadList. SushiName:{SushiName}.Id:{ Id}", model?.SushiName, model?.Id); + var list = model == null ? _SushiStorage.GetFullList() : _SushiStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public SushiViewModel? ReadElement(SushiSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SushiName:{SushiName}.Id:{ Id}", model.SushiName, model.Id); + var element = _SushiStorage.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(SushiBindingModel model) + { + CheckModel(model); + if (_SushiStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(SushiBindingModel model) + { + CheckModel(model); + if (_SushiStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(SushiBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_SushiStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(SushiBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SushiName)) + { + throw new ArgumentNullException("Нет названия пиццы", nameof(model.SushiName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); + } + if (model.SushiComponents == null || model.SushiComponents.Count == 0) + { + throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.SushiComponents)); + } + _logger.LogInformation("Sushi. SushiName:{SushiName}.Price:{Price}.Id: { Id}", model.SushiName, model.Price, model.Id); + var element = _SushiStorage.GetElement(new SushiSearchModel + { + SushiName = model.SushiName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пицца с таким названием уже есть"); + } + } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..206930c --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..ee30e84 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int SushiId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..6ac3b93 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..4143488 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int SushiId { get; set; } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs new file mode 100644 index 0000000..ce67161 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SushiBindingModel : ISushiModel + { + public int Id { get; set; } + public string SushiName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary SushiComponents + { + get; + set; + } = new(); + + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..5c2b515 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..b90fb79 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..8bec166 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs new file mode 100644 index 0000000..32c732b --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface ISushiLogic + { + List? ReadList(SushiSearchModel? model); + SushiViewModel? ReadElement(SushiSearchModel model); + bool Create(SushiBindingModel model); + bool Update(SushiBindingModel model); + bool Delete(SushiBindingModel model); + } + +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..a69687d --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..98630db --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..8ab0e48 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs new file mode 100644 index 0000000..95d2732 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class SushiSearchModel + { + public int? Id { get; set; } + public string? SushiName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..a58deb5 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..5d310e8 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..f3eda9d --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs new file mode 100644 index 0000000..3682ff7 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface ISushiStorage + { + List GetFullList(); + List GetFilteredList(SushiSearchModel model); + SushiViewModel? GetElement(SushiSearchModel model); + SushiViewModel? Insert(SushiBindingModel model); + SushiViewModel? Update(SushiBindingModel model); + SushiViewModel? Delete(SushiBindingModel model); + } + +} diff --git a/SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj similarity index 79% rename from SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj rename to SushiBar/SushiBarContracts/SushiBarContracts.csproj index ec020c5..a25f2c8 100644 --- a/SushiBar/SushiBarListImplement_ — копия/SushiBarListImplement.csproj +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -7,7 +7,6 @@ - diff --git a/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..5b924c1 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..36203b3 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int SushiId { get; set; } + + [DisplayName("Изделие")] + public string SushiName { 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/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..c09f97a --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.ViewModels +{ + public class ShopViewModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs new file mode 100644 index 0000000..8f9608c --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -0,0 +1,25 @@ +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class SushiViewModel : ISushiModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string SushiName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary SushiComponents + { + get; + set; + } = new(); + + } +} diff --git a/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs deleted file mode 100644 index c1b6d91..0000000 --- a/SushiBar/SushiBarDataModels — копия/Enums/OrderStatus.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarDataModels.Enums -{ - public enum OrderStatus - { - Неизвестен = -1, - Принят = 0, - Выполняется = 1, - Готов = 2, - Выдан = 3 - } -} diff --git a/SushiBar/SushiBarDataModels — копия/IId.cs b/SushiBar/SushiBarDataModels — копия/IId.cs deleted file mode 100644 index 91a1366..0000000 --- a/SushiBar/SushiBarDataModels — копия/IId.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SushiBarDataModels -{ - public interface IId - { - int Id { get; } - } -} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs deleted file mode 100644 index 02ca513..0000000 --- a/SushiBar/SushiBarDataModels — копия/Models/IOrderModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using SushiBarDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarDataModels.Models -{ - public interface IOrderModel : IId - { - int SushiId { get; } - int Count { get; } - double Sum { get; } - OrderStatus Status { get; } - DateTime DateCreate { get; } - DateTime? DateImplement { get; } - } -} diff --git a/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs b/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs deleted file mode 100644 index a6c7e0c..0000000 --- a/SushiBar/SushiBarDataModels — копия/Models/ISushiModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarDataModels.Models -{ - public interface ISushiModel : IId - { - string SushiName { get; } - double Price { get; } - Dictionary SushiComponents { get; } - } -} diff --git a/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj b/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj deleted file mode 100644 index 132c02c..0000000 --- a/SushiBar/SushiBarDataModels — копия/SushiBarDataModels.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/SushiBar/SushiBarDataModels/Models/IShopModel.cs b/SushiBar/SushiBarDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..df7cf9c --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopSushis { get; } + } +} diff --git a/SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs b/SushiBar/SushiBarDataModels/Models/ISupplyModel.cs similarity index 57% rename from SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs rename to SushiBar/SushiBarDataModels/Models/ISupplyModel.cs index b82c233..d8b8348 100644 --- a/SushiBar/SushiBarDataModels — копия/Models/IComponentModel.cs +++ b/SushiBar/SushiBarDataModels/Models/ISupplyModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace SushiBarDataModels.Models { - public interface IComponentModel : IId + public interface ISupplyModel { - string ComponentName { get; } - double Cost { get; } - + int ShopId { get; } + int SushiId { get; } + int Count { get; } } } diff --git a/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs deleted file mode 100644 index 26bfc23..0000000 --- a/SushiBar/SushiBarFileImplement — копия/DataFileSingleton.cs +++ /dev/null @@ -1,58 +0,0 @@ -using SushiBarFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace SushiBarFileImplement -{ - internal class DataFileSingleton - { - private static DataFileSingleton? instance; - private readonly string ComponentFileName = "Component.xml"; - private readonly string OrderFileName = "Order.xml"; - private readonly string SushiFileName = "Sushi.xml"; - public List Components { get; private set; } - public List Orders { get; private set; } - public List Sushis { get; private set; } - - public static DataFileSingleton GetInstance() - { - if (instance == null) - { - instance = new DataFileSingleton(); - } - return instance; - } - - public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); - public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - - private DataFileSingleton() - { - Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; - Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } - - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) - { - if (File.Exists(filename)) - { - return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); - } - return new List(); - } - - private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) - { - if (data != null) - { - new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); - } - } - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs deleted file mode 100644 index c413598..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Implements/ComponentStorage.cs +++ /dev/null @@ -1,86 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarFileImplement.Implements -{ - public class ComponentStorage : IComponentStorage - { - private readonly DataFileSingleton source; - - public ComponentStorage() - { - source = DataFileSingleton.GetInstance(); - } - - public List GetFullList() - { - return source.Components.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(ComponentSearchModel model) - { - if (string.IsNullOrEmpty(model.ComponentName)) - { - return new(); - } - return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); - } - - public ComponentViewModel? GetElement(ComponentSearchModel model) - { - if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) - { - return null; - } - return source.Components.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public ComponentViewModel? Insert(ComponentBindingModel model) - { - model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; - var newComponent = Component.Create(model); - if (newComponent == null) - { - return null; - } - source.Components.Add(newComponent); - source.SaveComponents(); - return newComponent.GetViewModel; - } - - public ComponentViewModel? Update(ComponentBindingModel model) - { - var component = source.Components.FirstOrDefault(x => x.Id == model.Id); - if (component == null) - { - return null; - } - component.Update(model); - source.SaveComponents(); - return component.GetViewModel; - } - - public ComponentViewModel? Delete(ComponentBindingModel model) - { - var element = source.Components.FirstOrDefault(x => x.Id == model.Id); - if (element != null) - { - source.Components.Remove(element); - source.SaveComponents(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs deleted file mode 100644 index 1664507..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Implements/OrderStorage.cs +++ /dev/null @@ -1,94 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarFileImplement.Implements -{ - public class OrderStorage : IOrderStorage - { - private readonly DataFileSingleton source; - - public OrderStorage() - { - source = DataFileSingleton.GetInstance(); - } - - public List GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList(); - - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachSushiName(x.GetViewModel)).ToList(); - } - - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return AttachSushiName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); - } - - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - source.Orders.Add(newOrder); - source.SaveOrders(); - return AttachSushiName(newOrder.GetViewModel); - } - - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return AttachSushiName(order.GetViewModel); - } - - public OrderViewModel? Delete(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order != null) - { - source.Orders.Remove(order); - source.SaveOrders(); - return AttachSushiName(order.GetViewModel); - } - return null; - } - - private OrderViewModel? AttachSushiName(OrderViewModel? model) - { - if (model == null) - { - return null; - } - var sushi = source.Sushis.FirstOrDefault(x => x.Id == model.SushiId); - if (sushi != null) - { - model.SushiName = sushi.SushiName; - } - return model; - } - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs deleted file mode 100644 index ac04014..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Implements/SushiStorage.cs +++ /dev/null @@ -1,86 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarFileImplement.Implements -{ - public class SushiStorage : ISushiStorage - { - private readonly DataFileSingleton source; - - public SushiStorage() - { - source = DataFileSingleton.GetInstance(); - } - - public List GetFullList() - { - return source.Sushis.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(SushiSearchModel model) - { - if (string.IsNullOrEmpty(model.SushiName)) - { - return new(); - } - return source.Sushis.Where(x => x.SushiName.Contains(model.SushiName)).Select(x => x.GetViewModel).ToList(); - } - - public SushiViewModel? GetElement(SushiSearchModel model) - { - if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) - { - return null; - } - return source.Sushis.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.SushiName) && x.SushiName == model.SushiName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public SushiViewModel? Insert(SushiBindingModel model) - { - model.Id = source.Sushis.Count > 0 ? source.Sushis.Max(x => x.Id) + 1 : 1; - var newSushi = Sushi.Create(model); - if (newSushi == null) - { - return null; - } - source.Sushis.Add(newSushi); - source.SaveSushis(); - return newSushi.GetViewModel; - } - - public SushiViewModel? Update(SushiBindingModel model) - { - var Sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id); - if (Sushi == null) - { - return null; - } - Sushi.Update(model); - source.SaveSushis(); - return Sushi.GetViewModel; - } - - public SushiViewModel? Delete(SushiBindingModel model) - { - var Sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id); - if (Sushi != null) - { - source.Sushis.Remove(Sushi); - source.SaveSushis(); - return Sushi.GetViewModel; - } - return null; - } - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Component.cs b/SushiBar/SushiBarFileImplement — копия/Models/Component.cs deleted file mode 100644 index 05caf5e..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Models/Component.cs +++ /dev/null @@ -1,70 +0,0 @@ - -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace SushiBarFileImplement.Models -{ - internal class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } - - public static Component? Create(ComponentBindingModel model) - { - if (model == null) - { - return null; - } - return new Component() - { - Id = model.Id, - ComponentName = model.ComponentName, - Cost = model.Cost - }; - } - - public static Component? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Component() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ComponentName = element.Element("ComponentName")!.Value, - Cost = Convert.ToDouble(element.Element("Cost")!.Value) - }; - } - - public void Update(ComponentBindingModel model) - { - if (model == null) - { - return; - } - ComponentName = model.ComponentName; - Cost = model.Cost; - } - - public ComponentViewModel GetViewModel => new() - { - Id = Id, - ComponentName = ComponentName, - Cost = Cost - }; - - public XElement GetXElement => new("Component", - new XAttribute("Id", Id), - new XElement("ComponentName", ComponentName), - new XElement("Cost", Cost.ToString())); - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Order.cs b/SushiBar/SushiBarFileImplement — копия/Models/Order.cs deleted file mode 100644 index a8a207d..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Models/Order.cs +++ /dev/null @@ -1,92 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Enums; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace SushiBarFileImplement.Models -{ - internal class Order : IOrderModel - { - public int Id { get; private set; } - public int SushiId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } - - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - SushiId = model.SushiId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } - - public static Order? Create(XElement element) - { - if (element == null) - { - return null; - } - string dateImplement = element.Element("DateImplement")!.Value; - return new Order() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), - DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) - }; - - } - - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; - } - - public OrderViewModel GetViewModel => new() - { - Id = Id, - SushiId = SushiId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; - - public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("SushiId", SushiId.ToString()), - new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString())); - } -} diff --git a/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs b/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs deleted file mode 100644 index 8396f75..0000000 --- a/SushiBar/SushiBarFileImplement — копия/Models/Sushi.cs +++ /dev/null @@ -1,86 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace SushiBarFileImplement.Models -{ - public class Sushi : ISushiModel - { - public int Id { get; private set; } - public string SushiName { get; private set; } = string.Empty; - public double Price { get; private set; } - public Dictionary Components { get; private set; } = new(); - private Dictionary? _SushiComponents = null; - public Dictionary SushiComponents - { - get - { - if (_SushiComponents == null) - { - var source = DataFileSingleton.GetInstance(); - _SushiComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); - } - return _SushiComponents; - } - } - public static Sushi? Create(SushiBindingModel model) - { - if (model == null) - { - return null; - } - return new Sushi() - { - Id = model.Id, - SushiName = model.SushiName, - Price = model.Price, - Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2) - }; - } - public static Sushi? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Sushi() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - SushiName = element.Element("SushiName")!.Value, - Price = Convert.ToDouble(element.Element("Price")!.Value), - Components = element.Element("SushiComponents")!.Elements("SushiComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), - x => Convert.ToInt32(x.Element("Value")?.Value)) - }; - } - public void Update(SushiBindingModel model) - { - if (model == null) - { - return; - } - SushiName = model.SushiName; - Price = model.Price; - Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2); - _SushiComponents = null; - } - public SushiViewModel GetViewModel => new() - { - Id = Id, - SushiName = SushiName, - Price = Price, - SushiComponents = SushiComponents - }; - public XElement GetXElement => new("Sushi", - new XAttribute("Id", Id), - new XElement("SushiName", SushiName), - new XElement("Price", Price.ToString()), - new XElement("SushiComponents", Components.Select( - x => new XElement("SushiComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); - } -} diff --git a/SushiBar/SushiBarListImplement/App.config b/SushiBar/SushiBarListImplement/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/SushiBar/SushiBarListImplement/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement_ — копия/Models/Component.cs b/SushiBar/SushiBarListImplement/Component.cs similarity index 87% rename from SushiBar/SushiBarListImplement_ — копия/Models/Component.cs rename to SushiBar/SushiBarListImplement/Component.cs index ecebaf6..453d89c 100644 --- a/SushiBar/SushiBarListImplement_ — копия/Models/Component.cs +++ b/SushiBar/SushiBarListImplement/Component.cs @@ -3,11 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using SushiBarContracts; -using SushiBarDataModels; -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; namespace SushiBarListImplement.Models { diff --git a/SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs b/SushiBar/SushiBarListImplement/ComponentStorage.cs similarity index 98% rename from SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs rename to SushiBar/SushiBarListImplement/ComponentStorage.cs index 9ce66c4..e06268f 100644 --- a/SushiBar/SushiBarListImplement_ — копия/Implements/ComponentStorage.cs +++ b/SushiBar/SushiBarListImplement/ComponentStorage.cs @@ -11,7 +11,7 @@ using SushiBarListImplement.Models; namespace SushiBarListImplement.Implements { - public class ComponentStorage : IComponentStorage + internal class ComponentStorage : IComponentStorage { private readonly DataListSingleton _source; public ComponentStorage() @@ -107,4 +107,4 @@ namespace SushiBarListImplement.Implements } } - +} diff --git a/SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs similarity index 88% rename from SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs rename to SushiBar/SushiBarListImplement/DataListSingleton.cs index 6eabe76..f0f9a1b 100644 --- a/SushiBar/SushiBarListImplement_ — копия/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -12,12 +12,12 @@ namespace SushiBarListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Sushis { get; set; } + public List Products { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Sushis = new List(); + Products = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs b/SushiBar/SushiBarListImplement/Sushi.cs similarity index 50% rename from SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs rename to SushiBar/SushiBarListImplement/Sushi.cs index 6f6bce2..133090b 100644 --- a/SushiBar/SushiBarListImplement_ — копия/Models/Sushi.cs +++ b/SushiBar/SushiBarListImplement/Sushi.cs @@ -3,52 +3,49 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; namespace SushiBarListImplement.Models { - public class Sushi : ISushiModel + internal class Sushi : IProductModel { public int Id { get; private set; } - public string SushiName { get; private set; } = string.Empty; + public string ProductName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary SushiComponents + public Dictionary ProductComponents { get; private set; } = new Dictionary(); - public static Sushi? Create(SushiBindingModel? model) + public static Product? Create(ProductBindingModel? model) { if (model == null) { return null; } - return new Sushi() + return new Product() { Id = model.Id, - SushiName = model.SushiName, + ProductName = model.ProductName, Price = model.Price, - SushiComponents = model.SushiComponents + ProductComponents = model.ProductComponents }; } - public void Update(SushiBindingModel? model) + public void Update(ProductBindingModel? model) { if (model == null) { return; } - SushiName = model.SushiName; + ProductName = model.ProductName; Price = model.Price; - SushiComponents = model.SushiComponents; + ProductComponents = model.ProductComponents; } - public SushiViewModel GetViewModel => new() + public ProductViewModel GetViewModel => new() { Id = Id, - SushiName = SushiName, + ProductName = ProductName, Price = Price, - SushiComponents = SushiComponents + ProductComponents = ProductComponents }; } diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj new file mode 100644 index 0000000..bbf9d38 --- /dev/null +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {1BBC3A4B-BF06-4EBF-AA20-863B369E234E} + Exe + SushiBarListImplement + SushiBarListImplement + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + {993e0787-3ad5-4743-8997-c828cd0cdc10} + SushiBarContracts + + + {76043de7-71bc-41e8-b4c0-ecfaddfbf55f} + SushiBarDataModels + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs deleted file mode 100644 index 957b9fa..0000000 --- a/SushiBar/SushiBarListImplement_ — копия/Implements/OrderStorage.cs +++ /dev/null @@ -1,125 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarListImplement.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(AttachSushiName(order.GetViewModel)); - } - return result; - } - - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - if (model == null || !model.Id.HasValue) - { - return result; - } - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - result.Add(AttachSushiName(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 AttachSushiName(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 AttachSushiName(newOrder.GetViewModel); - } - - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.Update(model); - return AttachSushiName(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 AttachSushiName(element.GetViewModel); - } - } - return null; - } - - private OrderViewModel AttachSushiName(OrderViewModel model) - { - foreach (var sushi in _source.Sushis) - { - if (sushi.Id == model.SushiId) - { - model.SushiName = sushi.SushiName; - return model; - } - } - return model; - } - } -} diff --git a/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs deleted file mode 100644 index 005e5c7..0000000 --- a/SushiBar/SushiBarListImplement_ — копия/Implements/SushiStorage.cs +++ /dev/null @@ -1,113 +0,0 @@ -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; -using SushiBarListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarListImplement.Implements -{ - public class SushiStorage : ISushiStorage - { - private readonly DataListSingleton _source; - - public SushiStorage() - { - _source = DataListSingleton.GetInstance(); - } - - public List GetFullList() - { - var result = new List(); - foreach (var Sushis in _source.Sushis) - { - result.Add(Sushis.GetViewModel); - } - return result; - } - - public List GetFilteredList(SushiSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.SushiName)) - { - return result; - } - foreach (var Sushis in _source.Sushis) - { - if (Sushis.SushiName.Contains(model.SushiName)) - { - result.Add(Sushis.GetViewModel); - } - } - return result; - } - - public SushiViewModel? GetElement(SushiSearchModel model) - { - if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) - { - return null; - } - foreach (var sushis in _source.Sushis) - { - if ((!string.IsNullOrEmpty(model.SushiName) && sushis.SushiName == model.SushiName) || - (model.Id.HasValue && sushis.Id == model.Id)) - { - return sushis.GetViewModel; - } - } - return null; - } - - public SushiViewModel? Insert(SushiBindingModel model) - { - model.Id = 1; - foreach (var sushis in _source.Sushis) - { - if (model.Id <= sushis.Id) - { - model.Id = sushis.Id + 1; - } - } - var newSushis = Sushi.Create(model); - if (newSushis == null) - { - return null; - } - _source.Sushis.Add(newSushis); - return newSushis.GetViewModel; - } - - public SushiViewModel? Update(SushiBindingModel model) - { - foreach (var sushis in _source.Sushis) - { - if (sushis.Id == model.Id) - { - sushis.Update(model); - return sushis.GetViewModel; - } - } - return null; - } - - public SushiViewModel? Delete(SushiBindingModel model) - { - for (int i = 0; i < _source.Sushis.Count; ++i) - { - if (_source.Sushis[i].Id == model.Id) - { - var element = _source.Sushis[i]; - _source.Sushis.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - } -} diff --git a/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs b/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs deleted file mode 100644 index f1d69d4..0000000 --- a/SushiBar/SushiBarListImplement_ — копия/Models/Order.cs +++ /dev/null @@ -1,62 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.ViewModels; -using SushiBarDataModels.Enums; -using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarListImplement.Models -{ - public class Order : IOrderModel - { - public int Id { get; private set; } - public int SushiId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } - - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - SushiId = model.SushiId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } - - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; - } - - public OrderViewModel GetViewModel => new() - { - Id = Id, - SushiId = SushiId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; - } -} diff --git a/SushiBar/SushiBarListImplement_/DataListSingleton.cs b/SushiBar/SushiBarListImplement_/DataListSingleton.cs index 6eabe76..7893d08 100644 --- a/SushiBar/SushiBarListImplement_/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement_/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs new file mode 100644 index 0000000..446bd8a --- /dev/null +++ b/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs @@ -0,0 +1,113 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarListImplement_/Models/Shop.cs b/SushiBar/SushiBarListImplement_/Models/Shop.cs new file mode 100644 index 0000000..0c7501d --- /dev/null +++ b/SushiBar/SushiBarListImplement_/Models/Shop.cs @@ -0,0 +1,59 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarDataModels.Enums; + +namespace SushiBarListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopSushis { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSushis = ShopSushis + }; + } +} diff --git a/SushiBar/SushiBarView/FormComponent.Designer.cs b/SushiBar/SushiBarView/FormComponent.Designer.cs new file mode 100644 index 0000000..e12b999 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace SushiBarView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(174, 99); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(87, 26); + this.ButtonSave.TabIndex = 0; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(267, 99); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(87, 26); + this.ButtonCancel.TabIndex = 1; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 24); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 65); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(83, 21); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(262, 23); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(83, 57); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(262, 23); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(354, 131); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.cs b/SushiBar/SushiBarView/FormComponent.cs new file mode 100644 index 0000000..dfacef0 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + + +namespace SushiBarView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.resx b/SushiBar/SushiBarView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponents.Designer.cs b/SushiBar/SushiBarView/FormComponents.Designer.cs new file mode 100644 index 0000000..27db7a7 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace SushiBarView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(499, 74); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(112, 35); + this.ButtonUpd.TabIndex = 0; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(499, 126); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(112, 35); + this.ButtonDel.TabIndex = 1; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(499, 23); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(112, 35); + this.ButtonAdd.TabIndex = 2; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(499, 177); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(112, 35); + this.ButtonRef.TabIndex = 3; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(454, 365); + this.dataGridView.TabIndex = 4; + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(623, 389); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Name = "FormComponents"; + this.Text = "FormComponents"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonAdd; + private Button ButtonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponents.cs b/SushiBar/SushiBarView/FormComponents.cs new file mode 100644 index 0000000..704c8e0 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponents.cs @@ -0,0 +1,123 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormComponents : Form + { + public FormComponents() + { + InitializeComponent(); + } + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/SushiBar/SushiBarView/FormComponents.resx b/SushiBar/SushiBarView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateOrder.Designer.cs b/SushiBar/SushiBarView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..fe9c140 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace SushiBarView +{ + 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.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(83, 42); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(262, 23); + this.textBoxCount.TabIndex = 9; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCost_TextChanged); + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(5, 45); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(72, 15); + this.labelCost.TabIndex = 7; + this.labelCost.Text = "Количество"; + this.labelCost.Click += new System.EventHandler(this.labelCost_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(5, 12); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(53, 15); + this.labelName.TabIndex = 6; + this.labelName.Text = "Изделие"; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(83, 80); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(262, 23); + this.textBoxSum.TabIndex = 11; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(5, 83); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 15); + this.label1.TabIndex = 10; + this.label1.Text = "Сумма"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(258, 120); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(87, 26); + this.ButtonCancel.TabIndex = 13; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(165, 120); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(87, 26); + this.ButtonSave.TabIndex = 12; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(83, 9); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(262, 23); + this.comboBoxSushi.TabIndex = 14; + this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(354, 158); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "FormCreateOrder"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxCount; + private Label labelCost; + private Label labelName; + private TextBox textBoxSum; + private Label label1; + private Button ButtonCancel; + private Button ButtonSave; + private ComboBox comboBoxSushi; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateOrder.cs b/SushiBar/SushiBarView/FormCreateOrder.cs new file mode 100644 index 0000000..fd23448 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateOrder.cs @@ -0,0 +1,136 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections; +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 SushiBarView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IOrderLogic _logicO; + private List? _list; + public FormCreateOrder() + { + InitializeComponent(); + } + public FormCreateOrder(ILogger logger, ISushiLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _list; + comboBoxSushi.SelectedItem = null; + _logger.LogInformation("Загрузка суши для заказа"); + } + } + private void labelCost_Click(object sender, EventArgs e) + { + + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxSushi.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSushi.SelectedValue); + var sushi = _logicP.ReadElement(new SushiSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBoxCost_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBarView/FormCreateOrder.resx b/SushiBar/SushiBarView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/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/SushiBar/SushiBarView/FormCreateSupply.Designer.cs b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..6f3c091 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs @@ -0,0 +1,149 @@ +namespace SushiBarView +{ + partial class FormCreateSupply + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.labelSushi = new System.Windows.Forms.Label(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(101, 9); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(302, 23); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(10, 11); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(60, 15); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(10, 37); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(59, 15); + this.labelSushi.TabIndex = 2; + this.labelSushi.Text = "Изделие: "; + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(101, 34); + this.comboBoxSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(302, 23); + this.comboBoxSushi.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 62); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(78, 15); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(101, 60); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(302, 23); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(262, 85); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(102, 29); + 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(147, 85); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(102, 29); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(412, 123); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelSushi); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelSushi; + private ComboBox comboBoxSushi; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.cs b/SushiBar/SushiBarView/FormCreateSupply.cs new file mode 100644 index 0000000..6dfeba4 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SushiBarView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _sushiList = new List(); + + public FormCreateSupply(ILogger logger, ISushiLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _sushiList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_sushiList != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _sushiList; + comboBoxSushi.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBarView/FormCreateSupply.resx b/SushiBar/SushiBarView/FormCreateSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.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/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs new file mode 100644 index 0000000..1999a78 --- /dev/null +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -0,0 +1,195 @@ +namespace SushiBarView +{ + 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.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Location = new System.Drawing.Point(676, 37); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(217, 29); + this.ButtonCreateOrder.TabIndex = 0; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Location = new System.Drawing.Point(676, 180); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(217, 29); + this.ButtonOrderReady.TabIndex = 1; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(676, 323); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(217, 29); + this.ButtonRef.TabIndex = 2; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Location = new System.Drawing.Point(676, 256); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(217, 29); + this.ButtonIssuedOrder.TabIndex = 3; + this.ButtonIssuedOrder.Text = "Заказ выполнен"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(676, 109); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(217, 29); + this.ButtonTakeOrderInWork.TabIndex = 4; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.пополнениеМагазинаToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(922, 24); + this.menuStrip.TabIndex = 5; + this.menuStrip.Text = "menuStrip1"; + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItemToolStripMenuItem, + this.sushiToolStripMenuItemToolStripMenuItem, + this.shopsToolStripMenuItemToolStripMenuItem}); + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); + this.toolStripMenuItem1.Text = "Справочники"; + // + // componentsToolStripMenuItemToolStripMenuItem + // + this.componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; + this.componentsToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + // + // sushiToolStripMenuItemToolStripMenuItem + // + this.sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; + this.sushiToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; + this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); + // + // shopsToolStripMenuItemToolStripMenuItem + // + this.shopsToolStripMenuItemToolStripMenuItem.Name = "shopsToolStripMenuItemToolStripMenuItem"; + this.shopsToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.shopsToolStripMenuItemToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); + // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(143, 20); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.transactionToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(647, 344); + this.dataGridView.TabIndex = 6; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(922, 383); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "FormMain"; + 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 Button ButtonCreateOrder; + private Button ButtonOrderReady; + private Button ButtonRef; + private Button ButtonIssuedOrder; + private Button ButtonTakeOrderInWork; + private MenuStrip menuStrip; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem componentsToolStripMenuItemToolStripMenuItem; + private ToolStripMenuItem sushiToolStripMenuItemToolStripMenuItem; + private DataGridView dataGridView; + private ToolStripMenuItem shopsToolStripMenuItemToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs new file mode 100644 index 0000000..0c83f6d --- /dev/null +++ b/SushiBar/SushiBarView/FormMain.cs @@ -0,0 +1,189 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + 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["SushiId"].Visible = false; + dataGridView.Columns["SushiName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void sushiToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushis)); + if (service is FormSushis form) + { + form.ShowDialog(); + } + } + + 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 shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + + } +} diff --git a/SushiBar/SushiBarView/FormMain.resx b/SushiBar/SushiBarView/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/SushiBar/SushiBarView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.Designer.cs b/SushiBar/SushiBarView/FormShop.Designer.cs new file mode 100644 index 0000000..5cf4b69 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.Designer.cs @@ -0,0 +1,201 @@ +namespace SushiBarView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.labelAdress = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimeOpen = new System.Windows.Forms.DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 11); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(65, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(89, 9); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(242, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(89, 44); + this.textBoxAdress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(374, 23); + this.textBoxAdress.TabIndex = 3; + // + // labelAdress + // + this.labelAdress.AutoSize = true; + this.labelAdress.Location = new System.Drawing.Point(10, 46); + this.labelAdress.Name = "labelAdress"; + this.labelAdress.Size = new System.Drawing.Size(46, 15); + this.labelAdress.TabIndex = 2; + this.labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(395, 343); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(114, 33); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(276, 343); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(114, 33); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.SushiName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(10, 108); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(498, 230); + this.dataGridView.TabIndex = 7; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // SushiName + // + this.SushiName.HeaderText = "Суши"; + this.SushiName.MinimumWidth = 6; + this.SushiName.Name = "SushiName"; + this.SushiName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(10, 77); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(87, 15); + this.label1.TabIndex = 8; + this.label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + this.dateTimeOpen.Location = new System.Drawing.Point(112, 77); + this.dateTimeOpen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dateTimeOpen.Name = "dateTimeOpen"; + this.dateTimeOpen.Size = new System.Drawing.Size(351, 23); + this.dateTimeOpen.TabIndex = 9; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(519, 385); + this.Controls.Add(this.dateTimeOpen); + this.Controls.Add(this.label1); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.labelAdress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn SushiName; + private DataGridViewTextBoxColumn Count; + private Label label1; + private DateTimePicker dateTimeOpen; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.cs b/SushiBar/SushiBarView/FormShop.cs new file mode 100644 index 0000000..79ea3cb --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.cs @@ -0,0 +1,128 @@ +using SushiBarDataModels.Models; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.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 SushiBarView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopSushis; + private DateTime? _openingDate = null; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopSushis = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + _ShopSushis = view.ShopSushis ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopSushis != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopSushis) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.Value + }; + 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/SushiBar/SushiBarView/FormShop.resx b/SushiBar/SushiBarView/FormShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.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/SushiBar/SushiBarView/FormShops.Designer.cs b/SushiBar/SushiBarView/FormShops.Designer.cs new file mode 100644 index 0000000..f668a5f --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.Designer.cs @@ -0,0 +1,138 @@ +namespace SushiBarView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(27, 154); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(27, 106); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(27, 57); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 2; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.cs b/SushiBar/SushiBarView/FormShops.cs new file mode 100644 index 0000000..7e899d2 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_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["ShopSushis"].Visible = false; + dataGridView.Columns["ShopName"].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(FormShop)); + if (service is FormShop 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(FormShop)); + if (service is FormShop 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 ShopBindingModel + { + 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/SushiBar/SushiBarView/FormShops.resx b/SushiBar/SushiBarView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.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/SushiBar/SushiBarView/FormSushi.Designer.cs b/SushiBar/SushiBarView/FormSushi.Designer.cs new file mode 100644 index 0000000..3f53aec --- /dev/null +++ b/SushiBar/SushiBarView/FormSushi.Designer.cs @@ -0,0 +1,198 @@ +namespace SushiBarView +{ + partial class FormSushi + { + /// + /// 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.labelCost = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(84, 48); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(262, 23); + this.textBoxPrice.TabIndex = 9; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(84, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(262, 23); + this.textBoxName.TabIndex = 8; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(13, 56); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 7; + this.labelCost.Text = "Цена"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(13, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 6; + this.labelName.Text = "Название"; + // + // panel1 + // + this.panel1.Controls.Add(this.dataGridView); + this.panel1.Controls.Add(this.ButtonRef); + this.panel1.Controls.Add(this.ButtonAdd); + this.panel1.Controls.Add(this.ButtonDel); + this.panel1.Controls.Add(this.ButtonUpd); + this.panel1.Location = new System.Drawing.Point(13, 100); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(725, 282); + this.panel1.TabIndex = 10; + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(18, 13); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(566, 255); + this.dataGridView.TabIndex = 8; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(598, 198); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(112, 35); + this.ButtonRef.TabIndex = 7; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(598, 44); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(112, 35); + this.ButtonAdd.TabIndex = 6; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(598, 147); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(112, 35); + this.ButtonDel.TabIndex = 5; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(598, 95); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(112, 35); + this.ButtonUpd.TabIndex = 4; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(651, 412); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(87, 26); + this.ButtonCancel.TabIndex = 12; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(558, 412); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(87, 26); + this.ButtonSave.TabIndex = 11; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(750, 450); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.panel1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormSushi"; + this.Text = "FormSushi"; + this.Load += new System.EventHandler(this.FormSushi_Load); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label labelCost; + private Label labelName; + private Panel panel1; + private Button ButtonRef; + private Button ButtonAdd; + private Button ButtonDel; + private Button ButtonUpd; + private DataGridView dataGridView; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushi.cs b/SushiBar/SushiBarView/FormSushi.cs new file mode 100644 index 0000000..b265edb --- /dev/null +++ b/SushiBar/SushiBarView/FormSushi.cs @@ -0,0 +1,252 @@ +using Microsoft.Extensions.Logging; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + + +namespace SushiBarView +{ + public partial class FormSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + private int? _id; + private Dictionary _sushiComponents; + public int Id { set { _id = value; } } + + public FormSushi() + { + InitializeComponent(); + } + public FormSushi(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _sushiComponents = new Dictionary(); + } + + private void FormSushi_Load(object sender, EventArgs e) + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AllowUserToAddRows = false; + DataGridViewTextBoxColumn Id = new DataGridViewTextBoxColumn(); + DataGridViewTextBoxColumn Component = new DataGridViewTextBoxColumn(); + DataGridViewTextBoxColumn Number = new DataGridViewTextBoxColumn(); + Component.HeaderText = "Количество"; + Number.HeaderText = "Компонент"; + Number.Name = "Number"; + Id.Name = "Id"; + dataGridView.Columns.Add(Id); + dataGridView.Columns.Add(Number); + dataGridView.Columns.Add(Component); + dataGridView.Columns["Id"].Visible = false; + + dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + if (_id.HasValue) + { + _logger.LogInformation("Загрузка суши"); + try + { + var view = _logic.ReadElement(new SushiSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SushiName; + textBoxPrice.Text = view.Price.ToString(); + _sushiComponents = view.SushiComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_sushiComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _sushiComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, +pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + if (service is FormSushiComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_sushiComponents.ContainsKey(form.Id)) + { + _sushiComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _sushiComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + if (service is FormSushiComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _sushiComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _sushiComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _sushiComponents?.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 (_sushiComponents == null || _sushiComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new SushiBindingModel + { + Id = _id ?? 0, + SushiName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SushiComponents = _sushiComponents + }; + 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 _sushiComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/SushiBar/SushiBarView/FormSushi.resx b/SushiBar/SushiBarView/FormSushi.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormSushi.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/SushiBar/SushiBarView/FormSushiComponent.Designer.cs b/SushiBar/SushiBarView/FormSushiComponent.Designer.cs new file mode 100644 index 0000000..17b2956 --- /dev/null +++ b/SushiBar/SushiBarView/FormSushiComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace SushiBarView +{ + partial class FormSushiComponent + { + /// + /// 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.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(87, 54); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(262, 23); + this.textBoxCount.TabIndex = 11; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 57); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(72, 15); + this.labelCost.TabIndex = 9; + this.labelCost.Text = "Количество"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 24); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(69, 15); + this.labelName.TabIndex = 8; + this.labelName.Text = "Компонент"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(271, 96); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(87, 26); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(178, 96); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(87, 26); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(87, 21); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(262, 23); + this.comboBoxComponent.TabIndex = 12; + // + // FormSushiComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 141); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Name = "FormSushiComponent"; + this.Text = "FormSushiComponent"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxCount; + private Label labelCost; + private Label labelName; + private Button ButtonCancel; + private Button ButtonSave; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushiComponent.cs b/SushiBar/SushiBarView/FormSushiComponent.cs new file mode 100644 index 0000000..a7a020a --- /dev/null +++ b/SushiBar/SushiBarView/FormSushiComponent.cs @@ -0,0 +1,99 @@ +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.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 SushiBarView +{ + public partial class FormSushiComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return + Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormSushiComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + public FormSushiComponent() + { + InitializeComponent(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + } +} diff --git a/SushiBar/SushiBarView/FormSushiComponent.resx b/SushiBar/SushiBarView/FormSushiComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormSushiComponent.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/SushiBar/SushiBarView/FormSushis.Designer.cs b/SushiBar/SushiBarView/FormSushis.Designer.cs new file mode 100644 index 0000000..4cc40f2 --- /dev/null +++ b/SushiBar/SushiBarView/FormSushis.Designer.cs @@ -0,0 +1,115 @@ +namespace SushiBarView +{ + partial class FormSushis + { + /// + /// 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.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(454, 365); + this.dataGridView.TabIndex = 9; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(499, 177); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(112, 35); + this.ButtonRef.TabIndex = 8; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(499, 23); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(112, 35); + this.ButtonAdd.TabIndex = 7; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(499, 126); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(112, 35); + this.ButtonDel.TabIndex = 6; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(499, 74); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(112, 35); + this.ButtonUpd.TabIndex = 5; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormSushis + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(637, 390); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Name = "FormSushis"; + this.Text = "FormSushis"; + this.Load += new System.EventHandler(this.FormSushi_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonRef; + private Button ButtonAdd; + private Button ButtonDel; + private Button ButtonUpd; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushis.cs b/SushiBar/SushiBarView/FormSushis.cs new file mode 100644 index 0000000..d5933eb --- /dev/null +++ b/SushiBar/SushiBarView/FormSushis.cs @@ -0,0 +1,121 @@ +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; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormSushis : Form + { + public FormSushis() + { + InitializeComponent(); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + + public FormSushis(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormSushi_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["SushiComponents"].Visible = false; + dataGridView.Columns["SushiName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка суши"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi 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 SushiBindingModel + { + 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/SushiBar/SushiBarView/FormSushis.resx b/SushiBar/SushiBarView/FormSushis.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBarView/FormSushis.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/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs new file mode 100644 index 0000000..6eb85ab --- /dev/null +++ b/SushiBar/SushiBarView/Program.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using SushiBarBusinessLogic.BusinessLogics; +using SushiBarListImplement.Implements; +using SushiBarContracts.StoragesContracts; +using SushiBarView; +using NLog.Extensions.Logging; + + +namespace SushiBarView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + ApplicationConfiguration.Initialize(); + 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(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj new file mode 100644 index 0000000..091baa3 --- /dev/null +++ b/SushiBar/SushiBarView/SushiBarView.csproj @@ -0,0 +1,34 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/nlog.config b/SushiBar/SushiBarView/nlog.config new file mode 100644 index 0000000..609afe6 --- /dev/null +++ b/SushiBar/SushiBarView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file From 513440002a42eabb36731332afa15e5420bb9861 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 13 Mar 2024 15:27:48 +0400 Subject: [PATCH 04/13] done --- SushiBar/SushiBarView/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 0d12b88..400406a 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -6,7 +6,7 @@ using SushiBarBusinessLogic.BusinessLogics; using SushiBarFileImplement.Implements; using SushiBarContracts.StoragesContracts; using SushiBarView; -using NLog.Extensions.Logging; +using NLog.Extensions.Logging; namespace SushiBarView From bcab5d31c20ab6042cbd37bdf3b0121f8fe269a3 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 13 Mar 2024 15:53:26 +0400 Subject: [PATCH 05/13] start --- SushiBar/SushiBarView/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 836538a..47ac190 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -6,7 +6,7 @@ using SushiBarBusinessLogic.BusinessLogics; using SushiBarDatabaseImplement.Implements; using SushiBarContracts.StoragesContracts; using SushiBarView; -using NLog.Extensions.Logging; +using NLog.Extensions.Logging; namespace SushiBarView From 0cab146e7c540a971acf91c4d61bcea7450ff2e1 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Tue, 26 Mar 2024 23:20:22 +0400 Subject: [PATCH 06/13] tip complete --- .../{ => BusinessLogics}/OrderLogic.cs | 23 +- .../BusinessLogics/ShopLogic.cs | 176 ++++++++++++++ SushiBar/SushiBarBusinessLogic_/SushiLogic.cs | 6 +- .../BindingModels/ShopBindingModel.cs | 19 ++ .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../SearchModels/SupplySearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 23 ++ .../ViewModels/ShopViewModel.cs | 25 ++ .../SushiBarDataModels/Models/IShopModel.cs | 17 ++ .../SushiBarDataModels/Models/ISupplyModel.cs | 15 ++ .../DataFileSingleton.cs | 4 + .../Implements/ShopStorage.cs | 154 ++++++++++++ SushiBar/SushiBarFileImplement/Models/Shop.cs | 112 +++++++++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 123 ++++++++++ .../SushiBarListImplement_/Models/Shop.cs | 59 +++++ .../SushiBarView/FormCreateSupply.Designer.cs | 143 +++++++++++ SushiBar/SushiBarView/FormCreateSupply.cs | 99 ++++++++ SushiBar/SushiBarView/FormCreateSupply.resx | 120 ++++++++++ SushiBar/SushiBarView/FormMain.Designer.cs | 45 +++- SushiBar/SushiBarView/FormMain.cs | 26 ++ .../SushiBarView/FormSellSushi.Designer.cs | 120 ++++++++++ SushiBar/SushiBarView/FormSellSushi.cs | 88 +++++++ SushiBar/SushiBarView/FormSellSushi.resx | 120 ++++++++++ SushiBar/SushiBarView/FormShop.Designer.cs | 222 ++++++++++++++++++ SushiBar/SushiBarView/FormShop.cs | 127 ++++++++++ SushiBar/SushiBarView/FormShop.resx | 120 ++++++++++ SushiBar/SushiBarView/FormShops.Designer.cs | 130 ++++++++++ SushiBar/SushiBarView/FormShops.cs | 117 +++++++++ SushiBar/SushiBarView/FormShops.resx | 120 ++++++++++ SushiBar/SushiBarView/FormSushis.cs | 4 +- SushiBar/SushiBarView/Program.cs | 6 + 34 files changed, 2422 insertions(+), 9 deletions(-) rename SushiBar/SushiBarBusinessLogic_/{ => BusinessLogics}/OrderLogic.cs (86%) create mode 100644 SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/SupplySearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IShopModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/ISupplyModel.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Shop.cs create mode 100644 SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs create mode 100644 SushiBar/SushiBarListImplement_/Models/Shop.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.Designer.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.resx create mode 100644 SushiBar/SushiBarView/FormSellSushi.Designer.cs create mode 100644 SushiBar/SushiBarView/FormSellSushi.cs create mode 100644 SushiBar/SushiBarView/FormSellSushi.resx create mode 100644 SushiBar/SushiBarView/FormShop.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShop.cs create mode 100644 SushiBar/SushiBarView/FormShop.resx create mode 100644 SushiBar/SushiBarView/FormShops.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShops.cs create mode 100644 SushiBar/SushiBarView/FormShops.resx diff --git a/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/OrderLogic.cs similarity index 86% rename from SushiBar/SushiBarBusinessLogic_/OrderLogic.cs rename to SushiBar/SushiBarBusinessLogic_/BusinessLogics/OrderLogic.cs index ac3e5f0..ae8df9d 100644 --- a/SushiBar/SushiBarBusinessLogic_/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/OrderLogic.cs @@ -17,10 +17,13 @@ namespace SushiBarBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopStorage _shopStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; } public List? ReadList(OrderSearchModel? model) { @@ -60,6 +63,22 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + SushiId = order.SushiId, + Count = order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } return ChangeStatus(model, OrderStatus.Выдан); } @@ -75,7 +94,7 @@ namespace SushiBarBusinessLogic.BusinessLogics } if (model.Count <= 0) { - throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count)); + throw new ArgumentException("Колличество суши в заказе не может быть меньше 1", nameof(model.Count)); } if (model.Sum <= 0) { diff --git a/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..47cfd25 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs @@ -0,0 +1,176 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly ISushiStorage _sushiStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, ISushiStorage sushiStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _sushiStorage = sushiStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.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(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopSushis.ContainsKey(model.SushiId)) + { + var oldValue = shop.ShopSushis[model.SushiId]; + oldValue.Item2 += model.Count; + shop.ShopSushis[model.SushiId] = oldValue; + } + else + { + var sushi = _sushiStorage.GetElement(new SushiSearchModel + { + Id = model.SushiId + }); + if (sushi == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.SushiId} не найденн"); + } + shop.ShopSushis.Add(model.SushiId, (sushi, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool Sale(SupplySearchModel model) + { + if (!model.SushiId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check sushi count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs index fefe4a4..84f67e4 100644 --- a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs +++ b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs @@ -93,11 +93,11 @@ namespace SushiBarBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.SushiName)) { - throw new ArgumentNullException("Нет названия пиццы", nameof(model.SushiName)); + throw new ArgumentNullException("Нет названия суши", nameof(model.SushiName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена суши должна быть больше 0", nameof(model.Price)); } if (model.SushiComponents == null || model.SushiComponents.Count == 0) { @@ -110,7 +110,7 @@ namespace SushiBarBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Пицца с таким названием уже есть"); + throw new InvalidOperationException("Суши с таким названием уже есть"); } } } diff --git a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..dc490f3 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + public int SushiMaxCount { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..c3520bc --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int SushiId { get; set; } + public int Count { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..7862fa4 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..fbd2461 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/SupplySearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..d74c710 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class SupplySearchModel + { + public int? SushiId { get; set; } + public int? Count { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..5fa2582 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,23 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..d257b9b --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopSushis { get; set; } = new(); + [DisplayName("Вместимость")] + public int SushiMaxCount { get; set; } + } +} diff --git a/SushiBar/SushiBarDataModels/Models/IShopModel.cs b/SushiBar/SushiBarDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..52caf62 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IShopModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopSushis { get; } + public int SushiMaxCount { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/Models/ISupplyModel.cs b/SushiBar/SushiBarDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..d8b8348 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int SushiId { get; } + int Count { get; } + } +} diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index 26bfc23..d949177 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -14,9 +14,11 @@ namespace SushiBarFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string SushiFileName = "Sushi.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Sushis { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { @@ -30,12 +32,14 @@ namespace SushiBarFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..75281db --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,154 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + + public bool Sale(SupplySearchModel model) + { + if (model == null || !model.SushiId.HasValue || !model.Count.HasValue) + return false; + int remainingSpace = source.Shops.Select(x => x.Sushis.ContainsKey(model.SushiId.Value) ? x.Sushis[model.SushiId.Value] : 0).Sum(); + if (remainingSpace < model.Count) + { + return false; + } + var shops = source.Shops.Where(x => x.Sushis.ContainsKey(model.SushiId.Value)).OrderByDescending(x => x.Sushis[model.SushiId.Value]).ToList(); + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Sushis[model.SushiId.Value]; + if (residue > 0) + { + shop.Sushis.Remove(model.SushiId.Value); + shop.SushisUpdate(); + model.Count = residue; + } + else + { + if (residue == 0) + { + shop.Sushis.Remove(model.SushiId.Value); + } + else + { + shop.Sushis[model.SushiId.Value] = -residue; + } + shop.SushisUpdate(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + + public bool RestockingShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.SushiMaxCount - x.ShopSushis.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + { + return false; + } + foreach (Shop shop in source.Shops) + { + int free_places = shop.SushiMaxCount - shop.ShopSushis.Select(x => x.Value.Item2).Sum(); + if (free_places <= 0) + continue; + free_places = Math.Min(free_places, model.Count); + model.Count -= free_places; + if (shop.Sushis.ContainsKey(model.SushiId)) + { + shop.Sushis[model.SushiId] += free_places; + } + else + { + shop.Sushis.Add(model.SushiId, free_places); + } + shop.SushisUpdate(); + if (model.Count == 0) + { + source.SaveShops(); + return true; + } + } + return false; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Shop.cs b/SushiBar/SushiBarFileImplement/Models/Shop.cs new file mode 100644 index 0000000..2b2f403 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Shop.cs @@ -0,0 +1,112 @@ +using SushiBarDataModels.Models; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using SushiBarFileImplement; + +namespace SushiBarFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Sushis { get; private set; } = new(); + private Dictionary? _shopSushis = null; + + public Dictionary ShopSushis + { + get + { + if (_shopSushis == null) + { + var source = DataFileSingleton.GetInstance(); + _shopSushis = Sushis.ToDictionary(x => x.Key, y => ((source.Sushis.FirstOrDefault(z => z.Id == y.Key) as ISushiModel)!, y.Value)); + } + return _shopSushis; + } + } + + public int SushiMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Sushis = model.ShopSushis.ToDictionary(x => x.Key, x => x.Value.Item2), + SushiMaxCount = model.SushiMaxCount + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Adress = element.Element("Adress")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Sushis = element.Element("ShopSushis")!.Elements("ShopSushi")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + SushiMaxCount = Convert.ToInt32(element.Element("SushiMaxCount")!.Value) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + SushiMaxCount = model.SushiMaxCount; + Sushis = model.ShopSushis.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopSushis = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSushis = ShopSushis, + SushiMaxCount = SushiMaxCount + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopSushis", Sushis.Select( + x => new XElement("ShopSushi", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("SushiMaxCount", SushiMaxCount.ToString()) + ); + + public void SushisUpdate() + { + _shopSushis = null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement_/DataListSingleton.cs b/SushiBar/SushiBarListImplement_/DataListSingleton.cs index 6eabe76..7893d08 100644 --- a/SushiBar/SushiBarListImplement_/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement_/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs new file mode 100644 index 0000000..c4212a6 --- /dev/null +++ b/SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs @@ -0,0 +1,123 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public bool Sale(SupplySearchModel model) + { + throw new NotImplementedException(); + } + + public bool RestockingShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/SushiBar/SushiBarListImplement_/Models/Shop.cs b/SushiBar/SushiBarListImplement_/Models/Shop.cs new file mode 100644 index 0000000..76c50f0 --- /dev/null +++ b/SushiBar/SushiBarListImplement_/Models/Shop.cs @@ -0,0 +1,59 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopSushis { get; private set; } = new(); + public int SushiMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + SushiMaxCount = model.SushiMaxCount, + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + SushiMaxCount = model.SushiMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSushis = ShopSushis, + SushiMaxCount = SushiMaxCount, + }; +} +} diff --git a/SushiBar/SushiBarView/FormCreateSupply.Designer.cs b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..f71678a --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace SushiBarView +{ + partial class FormCreateSupply + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.labelSushi = new System.Windows.Forms.Label(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(115, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(344, 28); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(76, 20); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(12, 49); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(75, 20); + this.labelSushi.TabIndex = 2; + this.labelSushi.Text = "Изделие: "; + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(115, 46); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(344, 28); + this.comboBoxSushi.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 83); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 80); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(344, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(300, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(116, 39); + 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(168, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(116, 39); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 164); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelSushi); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelSushi; + private ComboBox comboBoxSushi; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.cs b/SushiBar/SushiBarView/FormCreateSupply.cs new file mode 100644 index 0000000..7637142 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SushiBarView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _sushiList = new List(); + + public FormCreateSupply(ILogger logger, ISushiLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _sushiList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_sushiList != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _sushiList; + comboBoxSushi.SelectedItem = null; + _logger.LogInformation("Загрузка суши для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBarView/FormCreateSupply.resx b/SushiBar/SushiBarView/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index 0c2348d..3fa62e0 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -36,10 +36,14 @@ this.menuStrip = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.operationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SuspendLayout(); // // ButtonCreateOrder @@ -95,7 +99,8 @@ // menuStrip // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1}); + this.toolStripMenuItem1, + this.operationToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(922, 24); @@ -106,7 +111,8 @@ // this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItemToolStripMenuItem, - this.sushiToolStripMenuItemToolStripMenuItem}); + this.sushiToolStripMenuItemToolStripMenuItem, + this.shopsToolStripMenuItem}); this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); this.toolStripMenuItem1.Text = "Справочники"; @@ -125,6 +131,29 @@ this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); // + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); + // + // operationToolStripMenuItem + // + this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.transactionToolStripMenuItem, + this.продажаToolStripMenuItem}); + this.operationToolStripMenuItem.Name = "operationToolStripMenuItem"; + this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20); + this.operationToolStripMenuItem.Text = "Операции"; + // + // transactionToolStripMenuItem + // + this.transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; + this.transactionToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.transactionToolStripMenuItem.Text = "Поставка"; + this.transactionToolStripMenuItem.Click += new System.EventHandler(this.transactionToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.Color.White; @@ -135,6 +164,14 @@ this.dataGridView.Size = new System.Drawing.Size(647, 344); this.dataGridView.TabIndex = 6; // + // продажаToolStripMenuItem + // + this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + this.продажаToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.продажаToolStripMenuItem.Text = "Продажа"; + this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click); + // + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -171,5 +208,9 @@ private ToolStripMenuItem componentsToolStripMenuItemToolStripMenuItem; private ToolStripMenuItem sushiToolStripMenuItemToolStripMenuItem; private DataGridView dataGridView; + private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem operationToolStripMenuItem; + private ToolStripMenuItem transactionToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index 0ca85b9..41faf69 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -167,5 +167,31 @@ MessageBoxIcon.Error); LoadData(); } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi)); + if (service is FormSellSushi form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/SushiBarView/FormSellSushi.Designer.cs b/SushiBar/SushiBarView/FormSellSushi.Designer.cs new file mode 100644 index 0000000..7751a9c --- /dev/null +++ b/SushiBar/SushiBarView/FormSellSushi.Designer.cs @@ -0,0 +1,120 @@ +namespace SushiBarView +{ + partial class FormSellSushi + { + /// + /// 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.labelSushi = new System.Windows.Forms.Label(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(12, 14); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(75, 20); + this.labelSushi.TabIndex = 0; + this.labelSushi.Text = "Суши: "; + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(115, 11); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(239, 28); + this.comboBoxSushi.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 55); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 52); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(239, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(128, 99); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(94, 29); + this.buttonSell.TabIndex = 4; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(242, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(366, 140); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelSushi); + this.Name = "FormSellSushi"; + this.Text = "Продажа суши"; + this.Load += new System.EventHandler(this.FormSellingSushi_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelSushi; + private ComboBox comboBoxSushi; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSellSushi.cs b/SushiBar/SushiBarView/FormSellSushi.cs new file mode 100644 index 0000000..ab448cf --- /dev/null +++ b/SushiBar/SushiBarView/FormSellSushi.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormSellSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IShopLogic _logicS; + private List _sushiList = new List(); + + public FormSellSushi(ILogger logger, ISushiLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormSellingSushi_Load(object sender, EventArgs e) + { + _sushiList = _logicP.ReadList(null); + if (_sushiList != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _sushiList; + comboBoxSushi.SelectedItem = null; + _logger.LogInformation("Загрузка суши для продажи"); + } + } + + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sale(new SupplySearchModel + { + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + 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/SushiBar/SushiBarView/FormSellSushi.resx b/SushiBar/SushiBarView/FormSellSushi.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormSellSushi.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.Designer.cs b/SushiBar/SushiBarView/FormShop.Designer.cs new file mode 100644 index 0000000..04d34df --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.Designer.cs @@ -0,0 +1,222 @@ +namespace SushiBarView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.labelAdress = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimeOpen = new System.Windows.Forms.DateTimePicker(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpSushiMaxCount = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpSushiMaxCount)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(11, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(102, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 27); + this.textBoxName.TabIndex = 1; + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(102, 59); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(427, 27); + this.textBoxAdress.TabIndex = 3; + // + // labelAdress + // + this.labelAdress.AutoSize = true; + this.labelAdress.Location = new System.Drawing.Point(11, 61); + this.labelAdress.Name = "labelAdress"; + this.labelAdress.Size = new System.Drawing.Size(58, 20); + this.labelAdress.TabIndex = 2; + this.labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(451, 457); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(130, 44); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(315, 457); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 44); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.SushiName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 185); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(569, 266); + this.dataGridView.TabIndex = 7; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // SushiName + // + this.SushiName.HeaderText = "Суши"; + this.SushiName.MinimumWidth = 6; + this.SushiName.Name = "SushiName"; + this.SushiName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 103); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 20); + this.label1.TabIndex = 8; + this.label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + this.dateTimeOpen.Location = new System.Drawing.Point(128, 103); + this.dateTimeOpen.Name = "dateTimeOpen"; + this.dateTimeOpen.Size = new System.Drawing.Size(401, 27); + this.dateTimeOpen.TabIndex = 9; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 148); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 20); + this.label2.TabIndex = 10; + this.label2.Text = "Вместимость"; + // + // numericUpSushiMaxCount + // + this.numericUpSushiMaxCount.Location = new System.Drawing.Point(128, 146); + this.numericUpSushiMaxCount.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.numericUpSushiMaxCount.Name = "numericUpSushiMaxCount"; + this.numericUpSushiMaxCount.Size = new System.Drawing.Size(401, 27); + this.numericUpSushiMaxCount.TabIndex = 11; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(593, 513); + this.Controls.Add(this.numericUpSushiMaxCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.dateTimeOpen); + this.Controls.Add(this.label1); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.labelAdress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpSushiMaxCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn SushiName; + private DataGridViewTextBoxColumn Count; + private Label label1; + private DateTimePicker dateTimeOpen; + private Label label2; + private NumericUpDown numericUpSushiMaxCount; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.cs b/SushiBar/SushiBarView/FormShop.cs new file mode 100644 index 0000000..bb46390 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.cs @@ -0,0 +1,127 @@ +using SushiBarDataModels.Models; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.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 SushiBarView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopSushis; + private DateTime? _openingDate = null; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopSushis = new Dictionary(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + numericUpSushiMaxCount.Value = view.SushiMaxCount; + _ShopSushis = view.ShopSushis ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopSushis != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopSushis) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.Value, + SushiMaxCount = (int)numericUpSushiMaxCount.Value + }; + 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/SushiBar/SushiBarView/FormShop.resx b/SushiBar/SushiBarView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.Designer.cs b/SushiBar/SushiBarView/FormShops.Designer.cs new file mode 100644 index 0000000..b54a130 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.Designer.cs @@ -0,0 +1,130 @@ +namespace SushiBarView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.cs b/SushiBar/SushiBarView/FormShops.cs new file mode 100644 index 0000000..a9fce63 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.ViewModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_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["ShopSushis"].Visible = false; + dataGridView.Columns["ShopName"].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(FormShop)); + if (service is FormShop 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(FormShop)); + if (service is FormShop 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 ShopBindingModel + { + 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/SushiBar/SushiBarView/FormShops.resx b/SushiBar/SushiBarView/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormSushis.cs b/SushiBar/SushiBarView/FormSushis.cs index d5933eb..219942a 100644 --- a/SushiBar/SushiBarView/FormSushis.cs +++ b/SushiBar/SushiBarView/FormSushis.cs @@ -92,7 +92,7 @@ namespace SushiBarView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление пиццы"); + _logger.LogInformation("Удаление суши"); try { if (!_logic.Delete(new SushiBindingModel @@ -106,7 +106,7 @@ namespace SushiBarView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления пиццы"); + _logger.LogError(ex, "Ошибка удаления суши"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 0d12b88..54a077e 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -47,6 +47,12 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From 7088ccb0aad5d6e1aefa2d38382e755a246876b1 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 27 Mar 2024 00:01:33 +0400 Subject: [PATCH 07/13] =?UTF-8?q?=D0=BA=D0=BE=D1=81=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=BE=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarView/FormSushis.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SushiBar/SushiBarView/FormSushis.cs b/SushiBar/SushiBarView/FormSushis.cs index 219942a..d5933eb 100644 --- a/SushiBar/SushiBarView/FormSushis.cs +++ b/SushiBar/SushiBarView/FormSushis.cs @@ -92,7 +92,7 @@ namespace SushiBarView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление суши"); + _logger.LogInformation("Удаление пиццы"); try { if (!_logic.Delete(new SushiBindingModel @@ -106,7 +106,7 @@ namespace SushiBarView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления суши"); + _logger.LogError(ex, "Ошибка удаления пиццы"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } From 16336bbb0ef773f87bb24de1e704ee6b9bd2c39b Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 27 Mar 2024 00:11:04 +0400 Subject: [PATCH 08/13] =?UTF-8?q?=D0=B3=D0=BB=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=B2=D0=B4=D0=BE=D1=85=20=D0=B8=20=D0=BC=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BA?= =?UTF-8?q?=D1=83=D1=87=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic_/ShopLogic.cs | 160 ------------------ SushiBar/SushiBarBusinessLogic_/SushiLogic.cs | 1 - SushiBar/SushiBarView/Program.cs | 1 - SushiBar/SushiBarView/SushiBarView.csproj | 1 + 4 files changed, 1 insertion(+), 162 deletions(-) delete mode 100644 SushiBar/SushiBarBusinessLogic_/ShopLogic.cs diff --git a/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs deleted file mode 100644 index 645b4e2..0000000 --- a/SushiBar/SushiBarBusinessLogic_/ShopLogic.cs +++ /dev/null @@ -1,160 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.StoragesContracts; -using SushiBarContracts.ViewModels; -using SushiBarContracts.BusinessLogicsContracts; - -namespace SushiBarBusinessLogic.BusinessLogics -{ - public class ShopLogic : IShopLogic - { - private readonly ILogger _logger; - private readonly IShopStorage _shopStorage; - private readonly ISushiStorage _sushiStorage; - - public ShopLogic(ILogger logger, IShopStorage shopStorage, ISushiStorage sushiStorage) - { - _logger = logger; - _shopStorage = shopStorage; - _sushiStorage = sushiStorage; - } - - public List? ReadList(ShopSearchModel? model) - { - _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - public ShopViewModel? ReadElement(ShopSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); - var element = _shopStorage.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(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool Update(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - - public bool Delete(ShopBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_shopStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - - public bool MakeSupply(SupplyBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (model.Count <= 0) - { - throw new ArgumentException("Количество изделий должно быть больше 0"); - } - var shop = _shopStorage.GetElement(new ShopSearchModel - { - Id = model.ShopId - }); - if (shop == null) - { - throw new ArgumentException("Магазина не существует"); - } - if (shop.ShopSushis.ContainsKey(model.SushiId)) - { - var oldValue = shop.ShopSushis[model.SushiId]; - oldValue.Item2 += model.Count; - shop.ShopSushis[model.SushiId] = oldValue; - } - else - { - var sushi = _sushiStorage.GetElement(new SushiSearchModel - { - Id = model.SushiId - }); - if (sushi == null) - { - throw new ArgumentException($"Поставка: Товар с id:{model.SushiId} не найденн"); - } - shop.ShopSushis.Add(model.SushiId, (sushi, model.Count)); - } - return true; - } - - private void CheckModel(ShopBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.Adress)) - { - throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - ShopName = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - } -} diff --git a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs index 84f67e4..e9b39fc 100644 --- a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs +++ b/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using SushiBarContracts.BindingModels; -using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 54a077e..8dbb779 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -8,7 +8,6 @@ using SushiBarContracts.StoragesContracts; using SushiBarView; using NLog.Extensions.Logging; - namespace SushiBarView { internal static class Program diff --git a/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj index 091baa3..574ede4 100644 --- a/SushiBar/SushiBarView/SushiBarView.csproj +++ b/SushiBar/SushiBarView/SushiBarView.csproj @@ -28,6 +28,7 @@ + From 1203148896cdefb98221c66642ef57c257d2e59c Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 27 Mar 2024 14:25:07 +0400 Subject: [PATCH 09/13] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 10 + .../Implements/ShopStorage.cs | 185 ++++++++++++++++ .../20240313082356_InitialCreate.cs | 206 +++++++++--------- 3 files changed, 298 insertions(+), 103 deletions(-) create mode 100644 SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs diff --git a/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs index 47cfd25..f14617f 100644 --- a/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs @@ -125,6 +125,16 @@ namespace SushiBarBusinessLogic.BusinessLogics } shop.ShopSushis.Add(model.SushiId, (sushi, model.Count)); } + + _shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + ShopSushis = shop.ShopSushis, + SushiMaxCount = shop.SushiMaxCount, + }); return true; } diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..f0f1fd1 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,185 @@ +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDatabaseImplement.Models; + +namespace SushiBarDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new SushiBarDatabase(); + return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList(). + Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new SushiBarDatabase(); + return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).Where(x => x.ShopName.Contains(model.ShopName)). + ToList().Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return new(); + } + using var context = new SushiBarDatabase(); + return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi) + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new SushiBarDatabase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new SushiBarDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateSushis(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new SushiBarDatabase(); + var shop = context.Shops.Include(x => x.Sushis).FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + context.Shops.Remove(shop); + context.SaveChanges(); + return shop.GetViewModel; + } + return null; + } + + public bool RestockingShops(SupplyBindingModel model) + { + using var context = new SushiBarDatabase(); + var transaction = context.Database.BeginTransaction(); + var Shops = context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList(). + Where(x => x.SushiMaxCount > x.ShopSushis.Select(x => x.Value.Item2).Sum()).ToList(); + if (model == null) + { + return false; + } + try + { + foreach (Shop shop in Shops) + { + int difference = shop.SushiMaxCount - shop.ShopSushis.Select(x => x.Value.Item2).Sum(); + int refill = Math.Min(difference, model.Count); + model.Count -= refill; + if (shop.ShopSushis.ContainsKey(model.SushiId)) + { + var datePair = shop.ShopSushis[model.SushiId]; + datePair.Item2 += refill; + shop.ShopSushis[model.SushiId] = datePair; + } + else + { + var sushi = context.Sushis.First(x => x.Id == model.SushiId); + shop.ShopSushis.Add(model.SushiId, (sushi, refill)); + } + shop.SushisDictionatyUpdate(context); + if (model.Count == 0) + { + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public bool Sale(SupplySearchModel model) + { + using var context = new SushiBarDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var shops = context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList(). + Where(x => x.ShopSushis.ContainsKey(model.SushiId.Value)).OrderByDescending(x => x.ShopSushis[model.SushiId.Value].Item2).ToList(); + + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.ShopSushis[model.SushiId.Value].Item2; + if (residue > 0) + { + shop.ShopSushis.Remove(model.SushiId.Value); + shop.SushisDictionatyUpdate(context); + context.SaveChanges(); + model.Count = residue; + + } + else + { + if (residue == 0) + shop.ShopSushis.Remove(model.SushiId.Value); + else + { + var dataPair = shop.ShopSushis[model.SushiId.Value]; + dataPair.Item2 = -residue; + shop.ShopSushis[model.SushiId.Value] = dataPair; + } + + shop.SushisDictionatyUpdate(context); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs index 4367175..3ffad67 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs @@ -8,118 +8,118 @@ namespace SushiBarDatabaseImplement.Migrations /// public partial class InitialCreate : Migration { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); - migrationBuilder.CreateTable( - name: "Sushis", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Sushis", x => x.Id); - }); + migrationBuilder.CreateTable( + name: "Sushis", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sushis", x => x.Id); + }); - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Sushis_SushiId", - column: x => x.SushiId, - principalTable: "Sushis", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Sushis_SushiId", + column: x => x.SushiId, + principalTable: "Sushis", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); - migrationBuilder.CreateTable( - name: "SushiComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_SushiComponents", x => x.Id); - table.ForeignKey( - name: "FK_SushiComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_SushiComponents_Sushis_SushiId", - column: x => x.SushiId, - principalTable: "Sushis", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); + migrationBuilder.CreateTable( + name: "SushiComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SushiComponents", x => x.Id); + table.ForeignKey( + name: "FK_SushiComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SushiComponents_Sushis_SushiId", + column: x => x.SushiId, + principalTable: "Sushis", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); - migrationBuilder.CreateIndex( - name: "IX_Orders_SushiId", - table: "Orders", - column: "SushiId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_SushiId", + table: "Orders", + column: "SushiId"); - migrationBuilder.CreateIndex( - name: "IX_SushiComponents_ComponentId", - table: "SushiComponents", - column: "ComponentId"); + migrationBuilder.CreateIndex( + name: "IX_SushiComponents_ComponentId", + table: "SushiComponents", + column: "ComponentId"); - migrationBuilder.CreateIndex( - name: "IX_SushiComponents_SushiId", - table: "SushiComponents", - column: "SushiId"); - } + migrationBuilder.CreateIndex( + name: "IX_SushiComponents_SushiId", + table: "SushiComponents", + column: "SushiId"); + } - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); - migrationBuilder.DropTable( - name: "SushiComponents"); + migrationBuilder.DropTable( + name: "SushiComponents"); - migrationBuilder.DropTable( - name: "Components"); + migrationBuilder.DropTable( + name: "Components"); - migrationBuilder.DropTable( - name: "Sushis"); + migrationBuilder.DropTable( + name: "Sushis"); + } } } -} From 84b0ae0b43e92393a6f03e38aa3259273e76ab04 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Tue, 9 Apr 2024 19:43:29 +0400 Subject: [PATCH 10/13] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 1 + .../20240313082356_InitialCreate.cs | 125 --------- ... 20240409135559_InitialCreate.Designer.cs} | 79 +++++- .../20240409135559_InitialCreate.cs | 126 +++++++++ ...40409140637_InitialCreate_Hard.Designer.cs | 248 ++++++++++++++++++ .../20240409140637_InitialCreate_Hard.cs | 78 ++++++ .../SushiBarDatabaseModelSnapshot.cs | 77 ++++++ .../SushiBarDatabaseImplement/Models/Shop.cs | 119 +++++++++ .../Models/ShopSushis.cs | 28 ++ .../SushiBarDatabaseImplement.csproj | 1 + .../SushiBarDatatbase.cs | 2 + 11 files changed, 758 insertions(+), 126 deletions(-) delete mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs rename SushiBar/SushiBarDatabaseImplement/Migrations/{20240313082356_InitialCreate.Designer.cs => 20240409135559_InitialCreate.Designer.cs} (68%) create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.Designer.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Models/Shop.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs index f0f1fd1..c5d472c 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs @@ -5,6 +5,7 @@ using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDatabaseImplement.Models; + namespace SushiBarDatabaseImplement.Implements { public class ShopStorage : IShopStorage diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs deleted file mode 100644 index 3ffad67..0000000 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace SushiBarDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Sushis", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Sushis", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Sushis_SushiId", - column: x => x.SushiId, - principalTable: "Sushis", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "SushiComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - SushiId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_SushiComponents", x => x.Id); - table.ForeignKey( - name: "FK_SushiComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_SushiComponents_Sushis_SushiId", - column: x => x.SushiId, - principalTable: "Sushis", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_SushiId", - table: "Orders", - column: "SushiId"); - - migrationBuilder.CreateIndex( - name: "IX_SushiComponents_ComponentId", - table: "SushiComponents", - column: "ComponentId"); - - migrationBuilder.CreateIndex( - name: "IX_SushiComponents_SushiId", - table: "SushiComponents", - column: "SushiId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "SushiComponents"); - - migrationBuilder.DropTable( - name: "Components"); - - migrationBuilder.DropTable( - name: "Sushis"); - } - } - } diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.Designer.cs similarity index 68% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.Designer.cs index 7809e8c..4dc8011 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using SushiBarDatabaseImplement; namespace SushiBarDatabaseImplement.Migrations { [DbContext(typeof(SushiBarDatabase))] - [Migration("20240313082356_InitialCreate")] + [Migration("20240409135559_InitialCreate")] partial class InitialCreate { /// @@ -78,6 +78,59 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SushiMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("SushiId"); + + b.ToTable("ShopSushis"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => { b.Property("Id") @@ -135,6 +188,25 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Sushi"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Shop", "Shop") + .WithMany("Sushis") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany() + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Sushi"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => { b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") @@ -159,6 +231,11 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("SushiComponents"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Navigation("Sushis"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => { b.Navigation("Components"); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.cs new file mode 100644 index 0000000..dd648b1 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409135559_InitialCreate.cs @@ -0,0 +1,126 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + + migrationBuilder.CreateTable( + name: "Sushis", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sushis", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Sushis_SushiId", + column: x => x.SushiId, + principalTable: "Sushis", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SushiComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SushiComponents", x => x.Id); + table.ForeignKey( + name: "FK_SushiComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SushiComponents_Sushis_SushiId", + column: x => x.SushiId, + principalTable: "Sushis", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_SushiId", + table: "Orders", + column: "SushiId"); + + migrationBuilder.CreateIndex( + name: "IX_SushiComponents_ComponentId", + table: "SushiComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_SushiComponents_SushiId", + table: "SushiComponents", + column: "SushiId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "SushiComponents"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Sushis"); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.Designer.cs new file mode 100644 index 0000000..e1a1efe --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SushiBarDatabaseImplement; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + [DbContext(typeof(SushiBarDatabase))] + [Migration("20240409140637_InitialCreate_Hard")] + partial class InitialCreate_Hard + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("SushiId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SushiMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("SushiId"); + + b.ToTable("ShopSushis"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SushiName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Sushis"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SushiId"); + + b.ToTable("SushiComponents"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Orders") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Shop", "Shop") + .WithMany("Sushis") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany() + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") + .WithMany("SushiComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Components") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => + { + b.Navigation("SushiComponents"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Navigation("Sushis"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.cs new file mode 100644 index 0000000..4a5a1d0 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240409140637_InitialCreate_Hard.cs @@ -0,0 +1,78 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate_Hard : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Adress = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + SushiMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopSushis", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SushiId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopSushis", x => x.Id); + table.ForeignKey( + name: "FK_ShopSushis_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopSushis_Sushis_SushiId", + column: x => x.SushiId, + principalTable: "Sushis", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopSushis_ShopId", + table: "ShopSushis", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopSushis_SushiId", + table: "ShopSushis", + column: "SushiId"); + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopSushis"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 43e1c41..b69c52f 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -75,6 +75,59 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SushiMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("SushiId"); + + b.ToTable("ShopSushis"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => { b.Property("Id") @@ -132,6 +185,25 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Sushi"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Shop", "Shop") + .WithMany("Sushis") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany() + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Sushi"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => { b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") @@ -156,6 +228,11 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("SushiComponents"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b => + { + b.Navigation("Sushis"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => { b.Navigation("Components"); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..8455db5 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs @@ -0,0 +1,119 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Adress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public int SushiMaxCount { get; set; } + + private Dictionary? _shopSushis = null; + + public Dictionary ShopSushis + { + get + { + if (_shopSushis == null) + { + if (_shopSushis == null) + { + _shopSushis = Sushis + .ToDictionary(recSP => recSP.SushiId, recSP => (recSP.Sushi as ISushiModel, recSP.Count)); + } + return _shopSushis; + } + return _shopSushis; + } + } + + [ForeignKey("ShopId")] + public List Sushis { get; set; } = new(); + + public static Shop Create(SushiBarDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Sushis = model.ShopSushis.Select(x => new ShopSushis + { + Sushi = context.Sushis.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + SushiMaxCount = model.SushiMaxCount + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + SushiMaxCount = model.SushiMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSushis = ShopSushis, + SushiMaxCount = SushiMaxCount + }; + + public void UpdateSushis(SushiBarDatabase context, ShopBindingModel model) + { + var ShopSushis = context.ShopSushis.Where(rec => rec.ShopId == model.Id).ToList(); + if (ShopSushis != null && ShopSushis.Count > 0) + { + context.ShopSushis.RemoveRange(ShopSushis.Where(rec => !model.ShopSushis.ContainsKey(rec.SushiId))); + context.SaveChanges(); + ShopSushis = context.ShopSushis.Where(rec => rec.ShopId == model.Id).ToList(); + foreach (var updateSushi in ShopSushis) + { + updateSushi.Count = model.ShopSushis[updateSushi.SushiId].Item2; + model.ShopSushis.Remove(updateSushi.SushiId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var ar in model.ShopSushis) + { + context.ShopSushis.Add(new ShopSushis + { + Shop = shop, + Sushi = context.Sushis.First(x => x.Id == ar.Key), + Count = ar.Value.Item2 + }); + context.SaveChanges(); + } + _shopSushis = null; + } + + public void SushisDictionatyUpdate(SushiBarDatabase context) + { + UpdateSushis(context, new ShopBindingModel + { + Id = Id, + ShopSushis = ShopSushis, + }); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs b/SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs new file mode 100644 index 0000000..1d54689 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs @@ -0,0 +1,28 @@ +using SushiBarDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDatabaseImplement.Models +{ + public class ShopSushis + { + public int Id { get; set; } + + [Required] + public int SushiId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Sushi Sushi { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj index 7adb075..14e4efd 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj @@ -18,6 +18,7 @@ + diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs index 715a501..e1d490f 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs @@ -22,5 +22,7 @@ namespace SushiBarDatabaseImplement public virtual DbSet Sushis { set; get; } public virtual DbSet SushiComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Shops { get; set; } + public virtual DbSet ShopSushis { get; set; } } } From 942059e051717624c183eb20317eabadad139a9e Mon Sep 17 00:00:00 2001 From: ValAnn Date: Tue, 23 Apr 2024 22:43:05 +0400 Subject: [PATCH 11/13] i dont know how to fix it --- SushiBar/SushiBarView/FormMain.Designer.cs | 44 +--------------------- SushiBar/SushiBarView/FormMain.cs | 26 ------------- 2 files changed, 1 insertion(+), 69 deletions(-) diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index ae3efea..cfbe231 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -36,9 +36,6 @@ this.menuStrip = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.operationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -47,7 +44,6 @@ this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SuspendLayout(); // // ButtonCreateOrder @@ -104,8 +100,6 @@ // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1, this.отчётыToolStripMenuItem}); - this.toolStripMenuItem1, - this.operationToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(922, 24); @@ -116,8 +110,7 @@ // this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItemToolStripMenuItem, - this.sushiToolStripMenuItemToolStripMenuItem, - this.shopsToolStripMenuItem}); + this.sushiToolStripMenuItemToolStripMenuItem}); this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); this.toolStripMenuItem1.Text = "Справочники"; @@ -136,29 +129,6 @@ this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); // - // shopsToolStripMenuItem - // - this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.shopsToolStripMenuItem.Text = "Магазины"; - this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); - // - // operationToolStripMenuItem - // - this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.transactionToolStripMenuItem, - this.продажаToolStripMenuItem}); - this.operationToolStripMenuItem.Name = "operationToolStripMenuItem"; - this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20); - this.operationToolStripMenuItem.Text = "Операции"; - // - // transactionToolStripMenuItem - // - this.transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; - this.transactionToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.transactionToolStripMenuItem.Text = "Поставка"; - this.transactionToolStripMenuItem.Click += new System.EventHandler(this.transactionToolStripMenuItem_Click); - // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.Color.White; @@ -200,14 +170,6 @@ this.ordersToolStripMenuItem.Text = "Заказы"; this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // - // продажаToolStripMenuItem - // - this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; - this.продажаToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.продажаToolStripMenuItem.Text = "Продажа"; - this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click); - // - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -248,9 +210,5 @@ private ToolStripMenuItem componentsToolStripMenuItem1; private ToolStripMenuItem componentSushiToolStripMenuItem1; private ToolStripMenuItem ordersToolStripMenuItem; - private ToolStripMenuItem shopsToolStripMenuItem; - private ToolStripMenuItem operationToolStripMenuItem; - private ToolStripMenuItem transactionToolStripMenuItem; - private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index 6165f25..17856df 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -200,31 +200,5 @@ MessageBoxIcon.Error); } } - private void shopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - - private void transactionToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); - if (service is FormCreateSupply form) - { - form.ShowDialog(); - } - } - - private void SellToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi)); - if (service is FormSellSushi form) - { - form.ShowDialog(); - } - } } } From eb7a8b37cceefc1a0098f35b08b43ab345f80d40 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Wed, 24 Apr 2024 15:07:36 +0400 Subject: [PATCH 12/13] process --- .../{ => BusinessLogics}/ComponentLogic.cs | 0 .../{ => BusinessLogics}/ReportLogic.cs | 57 ++- .../{ => BusinessLogics}/SushiLogic.cs | 0 .../OfficePackage/AbstractSaveToExcel.cs | 72 +++ .../OfficePackage/AbstractSaveToPdf.cs | 25 + .../OfficePackage/AbstractSaveToWord.cs | 44 ++ .../OfficePackage/HelperModels/ExcelShop.cs | 16 + .../HelperModels/PdfGroupedOrdersInfo.cs | 18 + .../HelperModels/WordRowParameters.cs | 14 + .../HelperModels/WordShopInfo.cs | 16 + .../OfficePackage/IDocument.cs | 14 + .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportGroupOrdersViewModel.cs | 15 + .../ViewModels/ReportShopsViewModel.cs | 15 + ...el.cs => ReportSushiComponentViewModel.cs} | 0 .../Implements/OrderStorage.cs | 2 +- .../Implements/OrderStorage.cs | 2 +- SushiBar/SushiBarView/FormMain.Designer.cs | 329 ++++++++----- SushiBar/SushiBarView/FormMain.cs | 54 +++ SushiBar/SushiBarView/FormMain.resx | 62 ++- .../FormReportGroupedOrders.Designer.cs | 86 ++++ .../SushiBarView/FormReportGroupedOrders.cs | 80 ++++ .../SushiBarView/FormReportGroupedOrders.resx | 120 +++++ .../SushiBarView/FormReportShop.Designer.cs | 116 +++++ SushiBar/SushiBarView/FormReportShop.cs | 78 ++++ SushiBar/SushiBarView/FormReportShop.resx | 120 +++++ SushiBar/SushiBarView/Program.cs | 10 +- .../SushiBarView/ReportGroupedOrders.rdlc | 441 ++++++++++++++++++ 28 files changed, 1681 insertions(+), 130 deletions(-) rename SushiBar/SushiBarBusinessLogic_/{ => BusinessLogics}/ComponentLogic.cs (100%) rename SushiBar/SushiBarBusinessLogic_/{ => BusinessLogics}/ReportLogic.cs (61%) rename SushiBar/SushiBarBusinessLogic_/{ => BusinessLogics}/SushiLogic.cs (100%) create mode 100644 SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelShop.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordRowParameters.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordShopInfo.cs create mode 100644 SushiBar/SushiBarBusinessLogic_/OfficePackage/IDocument.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ReportGroupOrdersViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ReportShopsViewModel.cs rename SushiBar/SushiBarContracts/ViewModels/{ReportPizzaComponentViewModel.cs => ReportSushiComponentViewModel.cs} (100%) create mode 100644 SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs create mode 100644 SushiBar/SushiBarView/FormReportGroupedOrders.cs create mode 100644 SushiBar/SushiBarView/FormReportGroupedOrders.resx create mode 100644 SushiBar/SushiBarView/FormReportShop.Designer.cs create mode 100644 SushiBar/SushiBarView/FormReportShop.cs create mode 100644 SushiBar/SushiBarView/FormReportShop.resx create mode 100644 SushiBar/SushiBarView/ReportGroupedOrders.rdlc diff --git a/SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ComponentLogic.cs similarity index 100% rename from SushiBar/SushiBarBusinessLogic_/ComponentLogic.cs rename to SushiBar/SushiBarBusinessLogic_/BusinessLogics/ComponentLogic.cs diff --git a/SushiBar/SushiBarBusinessLogic_/ReportLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ReportLogic.cs similarity index 61% rename from SushiBar/SushiBarBusinessLogic_/ReportLogic.cs rename to SushiBar/SushiBarBusinessLogic_/BusinessLogics/ReportLogic.cs index 81ae29c..9f795ff 100644 --- a/SushiBar/SushiBarBusinessLogic_/ReportLogic.cs +++ b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/ReportLogic.cs @@ -11,24 +11,25 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace SushiBarBusinessLogic +namespace SushiBarBusinessLogic.BusinessLogics { public class ReportLogic : IReportLogic { private readonly IComponentStorage _componentStorage; private readonly ISushiStorage _SushiStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ISushiStorage SushiStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, + public ReportLogic(ISushiStorage SushiStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _SushiStorage = SushiStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; - + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -89,5 +90,55 @@ namespace SushiBarBusinessLogic Orders = GetOrders(model) }); } + + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Sushis = x.ShopSushis.Select(x => (x.Value.Item1.SushiName, x.Value.Item2)).ToList(), + TotalCount = x.ShopSushis.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopSushisReport(new ExcelShop + { + FileName = model.FileName, + Title = "Наполненость магазинов", + ShopSushis = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов сгруппированных по дате заказов", + GroupedOrders = GetGroupedOrders() + }); + } } } diff --git a/SushiBar/SushiBarBusinessLogic_/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic_/BusinessLogics/SushiLogic.cs similarity index 100% rename from SushiBar/SushiBarBusinessLogic_/SushiLogic.cs rename to SushiBar/SushiBarBusinessLogic_/BusinessLogics/SushiLogic.cs diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs index 7c71989..bf11c7a 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs @@ -72,6 +72,78 @@ namespace SushiBarBusinessLogic.OfficePackage } SaveExcel(info); } + + public void CreateShopSushisReport(ExcelShop info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + foreach (var sr in info.ShopSushis) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = sr.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Sushi, Count) in sr.Sushis) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Sushi, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = sr.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } /// /// Создание excel-файла /// diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs index b3f0d21..5abcdbe 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs @@ -48,6 +48,31 @@ namespace SushiBarBusinessLogic.OfficePackage }); SavePdf(info); } + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + + foreach (var groupedOrder in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } /// /// Создание doc-файла /// diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs index bd162a0..246317a 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs @@ -38,6 +38,48 @@ namespace SushiBarBusinessLogic.OfficePackage } SaveWord(info); } + + public void CreateShopsDoc(WordShopInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + CreateRow(new WordRowParameters + { + Texts = new List { "Название", "Адрес", "Дата открытия" }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var shop in info.Shops) + { + CreateRow(new WordRowParameters + { + Texts = new List { shop.ShopName, shop.Adress, shop.OpeningDate.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + /// /// Создание doc-файла /// @@ -54,5 +96,7 @@ namespace SushiBarBusinessLogic.OfficePackage /// /// protected abstract void SaveWord(WordInfo info); + protected abstract void CreateTable(List colums); + protected abstract void CreateRow(WordRowParameters rowParameters); } } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelShop.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelShop.cs new file mode 100644 index 0000000..680c521 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelShop.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShop : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs new file mode 100644 index 0000000..fbcc93d --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -0,0 +1,18 @@ +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage.HelperModels +{ + public class PdfGroupedOrdersInfo : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List GroupedOrders { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordRowParameters.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordRowParameters.cs new file mode 100644 index 0000000..2df1cd9 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordRowParameters.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage.HelperModels +{ + public class WordRowParameters + { + public List Texts { get; set; } = new(); + public WordTextProperties TextProperties { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordShopInfo.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordShopInfo.cs new file mode 100644 index 0000000..75515bf --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordShopInfo.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopInfo : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/IDocument.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/IDocument.cs new file mode 100644 index 0000000..73263cc --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/IDocument.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage +{ + public interface IDocument + { + public string FileName { get; set; } + public string Title { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs index a993281..5e036bc 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs @@ -7,8 +7,13 @@ namespace SushiBarContracts.BusinessLogicsContracts { List GetSushiComponents(); List GetOrders(ReportBindingModel model); + List GetShops(); + List GetGroupedOrders(); void SaveSushisToWordFile(ReportBindingModel model); void SaveSushiComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopsToExcelFile(ReportBindingModel model); + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/ReportGroupOrdersViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ReportGroupOrdersViewModel.cs new file mode 100644 index 0000000..cd2bcc0 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ReportGroupOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class ReportGroupOrdersViewModel + { + public DateTime Date { get; set; } = DateTime.Now; + public int OrdersCount { get; set; } + public double OrdersSum { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/ReportShopsViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..d085d88 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.ViewModels +{ + public class ReportShopsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Sushi, int count)> Sushis { get; set; } = new(); + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/ReportPizzaComponentViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs similarity index 100% rename from SushiBar/SushiBarContracts/ViewModels/ReportPizzaComponentViewModel.cs rename to SushiBar/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 562ed67..2ac65a5 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -22,7 +22,7 @@ namespace SushiBarDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.DateFrom.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue) { return new(); } diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index cb2c3ca..a5d1561 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -24,7 +24,7 @@ namespace SushiBarFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.DateFrom.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue) { return new(); } diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index cfbe231..143c1e8 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -28,170 +28,245 @@ /// private void InitializeComponent() { - this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentSushiToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + ButtonCreateOrder = new Button(); + ButtonOrderReady = new Button(); + ButtonRef = new Button(); + ButtonIssuedOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + menuStrip = new MenuStrip(); + toolStripMenuItem1 = new ToolStripMenuItem(); + componentsToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem(); + sushiToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem1 = new ToolStripMenuItem(); + списокСушиToolStripMenuItem = new ToolStripMenuItem(); + сушиСИнгрToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + заказыToolStripMenuItem = new ToolStripMenuItem(); + заказыПоГруппамToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem1 = new ToolStripMenuItem(); + информацияToolStripMenuItem = new ToolStripMenuItem(); + загруженностьToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + поставкаToolStripMenuItem = new ToolStripMenuItem(); + продажаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // ButtonCreateOrder // - this.ButtonCreateOrder.Location = new System.Drawing.Point(676, 37); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonCreateOrder.TabIndex = 0; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + ButtonCreateOrder.Location = new Point(676, 37); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(217, 29); + ButtonCreateOrder.TabIndex = 0; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; // // ButtonOrderReady // - this.ButtonOrderReady.Location = new System.Drawing.Point(676, 180); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(217, 29); - this.ButtonOrderReady.TabIndex = 1; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + ButtonOrderReady.Location = new Point(676, 180); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(217, 29); + ButtonOrderReady.TabIndex = 1; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; // // ButtonRef // - this.ButtonRef.Location = new System.Drawing.Point(676, 323); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(217, 29); - this.ButtonRef.TabIndex = 2; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + ButtonRef.Location = new Point(676, 323); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(217, 29); + ButtonRef.TabIndex = 2; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; // // ButtonIssuedOrder // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(676, 256); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonIssuedOrder.TabIndex = 3; - this.ButtonIssuedOrder.Text = "Заказ выполнен"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + ButtonIssuedOrder.Location = new Point(676, 256); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(217, 29); + ButtonIssuedOrder.TabIndex = 3; + ButtonIssuedOrder.Text = "Заказ выполнен"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; // // ButtonTakeOrderInWork // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(676, 109); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(217, 29); - this.ButtonTakeOrderInWork.TabIndex = 4; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + ButtonTakeOrderInWork.Location = new Point(676, 109); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(217, 29); + ButtonTakeOrderInWork.TabIndex = 4; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // menuStrip // - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1, this.отчётыToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(922, 24); - this.menuStrip.TabIndex = 5; - this.menuStrip.Text = "menuStrip1"; + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, отчётыToolStripMenuItem, операцииToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(922, 24); + menuStrip.TabIndex = 5; + menuStrip.Text = "menuStrip1"; // // toolStripMenuItem1 // - this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItemToolStripMenuItem, - this.sushiToolStripMenuItemToolStripMenuItem}); - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItem1.Text = "Справочники"; + toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItemToolStripMenuItem, sushiToolStripMenuItemToolStripMenuItem, магазиныToolStripMenuItem }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(94, 20); + toolStripMenuItem1.Text = "Справочники"; // // componentsToolStripMenuItemToolStripMenuItem // - this.componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; - this.componentsToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; - this.componentsToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; + componentsToolStripMenuItemToolStripMenuItem.Size = new Size(145, 22); + componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItemToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // sushiToolStripMenuItemToolStripMenuItem // - this.sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; - this.sushiToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; - this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); + sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; + sushiToolStripMenuItemToolStripMenuItem.Size = new Size(145, 22); + sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; + sushiToolStripMenuItemToolStripMenuItem.Click += sushiToolStripMenuItem_Click; // - // dataGridView + // магазиныToolStripMenuItem // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(647, 344); - this.dataGridView.TabIndex = 6; + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(145, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; // // отчётыToolStripMenuItem // - this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItem1, - this.componentSushiToolStripMenuItem1, - this.ordersToolStripMenuItem}); - this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); - this.отчётыToolStripMenuItem.Text = "Отчёты"; + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, ordersToolStripMenuItem, магазиныToolStripMenuItem1 }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; // // componentsToolStripMenuItem1 // - this.componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1"; - this.componentsToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentsToolStripMenuItem1.Text = "Суши"; - this.componentsToolStripMenuItem1.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + componentsToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { списокСушиToolStripMenuItem, сушиСИнгрToolStripMenuItem }); + componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1"; + componentsToolStripMenuItem1.Size = new Size(180, 22); + componentsToolStripMenuItem1.Text = "Суши"; + componentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click; // - // componentSushiToolStripMenuItem1 + // списокСушиToolStripMenuItem // - this.componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1"; - this.componentSushiToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentSushiToolStripMenuItem1.Text = "Суши с компонентами"; - this.componentSushiToolStripMenuItem1.Click += new System.EventHandler(this.ComponentSushiToolStripMenuItem_Click); + списокСушиToolStripMenuItem.Name = "списокСушиToolStripMenuItem"; + списокСушиToolStripMenuItem.Size = new Size(201, 22); + списокСушиToolStripMenuItem.Text = "Список суши"; + списокСушиToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // сушиСИнгрToolStripMenuItem + // + сушиСИнгрToolStripMenuItem.Name = "сушиСИнгрToolStripMenuItem"; + сушиСИнгрToolStripMenuItem.Size = new Size(201, 22); + сушиСИнгрToolStripMenuItem.Text = "Суши с компонентами"; + сушиСИнгрToolStripMenuItem.Click += ComponentSushiToolStripMenuItem_Click; // // ordersToolStripMenuItem // - this.ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - this.ordersToolStripMenuItem.Size = new System.Drawing.Size(205, 22); - this.ordersToolStripMenuItem.Text = "Заказы"; - this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + ordersToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, заказыПоГруппамToolStripMenuItem }); + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(180, 22); + ordersToolStripMenuItem.Text = "Заказы"; + ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // заказыToolStripMenuItem + // + заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; + заказыToolStripMenuItem.Size = new Size(180, 22); + заказыToolStripMenuItem.Text = "Заказы"; + заказыToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // заказыПоГруппамToolStripMenuItem + // + заказыПоГруппамToolStripMenuItem.Name = "заказыПоГруппамToolStripMenuItem"; + заказыПоГруппамToolStripMenuItem.Size = new Size(180, 22); + заказыПоГруппамToolStripMenuItem.Text = "Заказы по группам"; + заказыПоГруппамToolStripMenuItem.Click += GroupOrdersToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem1 + // + магазиныToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { информацияToolStripMenuItem, загруженностьToolStripMenuItem }); + магазиныToolStripMenuItem1.Name = "магазиныToolStripMenuItem1"; + магазиныToolStripMenuItem1.Size = new Size(180, 22); + магазиныToolStripMenuItem1.Text = "Магазины"; + // + // информацияToolStripMenuItem + // + информацияToolStripMenuItem.Name = "информацияToolStripMenuItem"; + информацияToolStripMenuItem.Size = new Size(180, 22); + информацияToolStripMenuItem.Text = "Информация "; + информацияToolStripMenuItem.Click += InfoToolStripMenuItem_Click; + // + // загруженностьToolStripMenuItem + // + загруженностьToolStripMenuItem.Name = "загруженностьToolStripMenuItem"; + загруженностьToolStripMenuItem.Size = new Size(180, 22); + загруженностьToolStripMenuItem.Text = "Загруженность"; + загруженностьToolStripMenuItem.Click += BusyShopsToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(75, 20); + операцииToolStripMenuItem.Text = "Операции"; + // + // поставкаToolStripMenuItem + // + поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem"; + поставкаToolStripMenuItem.Size = new Size(125, 22); + поставкаToolStripMenuItem.Text = "Поставка"; + поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click; + // + // продажаToolStripMenuItem + // + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(125, 22); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(647, 344); + dataGridView.TabIndex = 6; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(922, 383); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "FormMain"; - 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(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(922, 383); + Controls.Add(dataGridView); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonRef); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonCreateOrder); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -208,7 +283,17 @@ private DataGridView dataGridView; private ToolStripMenuItem отчётыToolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem1; - private ToolStripMenuItem componentSushiToolStripMenuItem1; private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem списокСушиToolStripMenuItem; + private ToolStripMenuItem сушиСИнгрToolStripMenuItem; + private ToolStripMenuItem заказыToolStripMenuItem; + private ToolStripMenuItem заказыПоГруппамToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem1; + private ToolStripMenuItem информацияToolStripMenuItem; + private ToolStripMenuItem загруженностьToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem поставкаToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index 17856df..31f020c 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -200,5 +200,59 @@ MessageBoxIcon.Error); } } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi)); + if (service is FormSellSushi form) + { + form.ShowDialog(); + } + } + + private void InfoToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); + if (service is FormReportShop form) + { + form.ShowDialog(); + } + } + + private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/SushiBarView/FormMain.resx b/SushiBar/SushiBarView/FormMain.resx index 81a9e3d..6c82d08 100644 --- a/SushiBar/SushiBarView/FormMain.resx +++ b/SushiBar/SushiBarView/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs b/SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..e761a18 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace SushiBarView +{ + partial class FormReportGroupedOrders + { + /// + /// 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.panel = new System.Windows.Forms.Panel(); + this.buttonToPDF = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPDF); + this.panel.Controls.Add(this.buttonMake); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(970, 52); + this.panel.TabIndex = 1; + // + // buttonToPDF + // + this.buttonToPDF.Location = new System.Drawing.Point(486, 12); + this.buttonToPDF.Name = "buttonToPDF"; + this.buttonToPDF.Size = new System.Drawing.Size(411, 29); + this.buttonToPDF.TabIndex = 5; + this.buttonToPDF.Text = "В PDF"; + this.buttonToPDF.UseVisualStyleBackColor = true; + this.buttonToPDF.Click += new System.EventHandler(this.buttonToPDF_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(49, 12); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(377, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // FormReportGroupedOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(970, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportGroupedOrders"; + this.Text = "Отчёт по группированным заказам "; + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPDF; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportGroupedOrders.cs b/SushiBar/SushiBarView/FormReportGroupedOrders.cs new file mode 100644 index 0000000..0ceb432 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportGroupedOrders.cs @@ -0,0 +1,80 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedOrders(); + var source = new ReportDataSource("DataSetGroupedOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка группированных заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка группированных заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void buttonToPDF_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + }); + _logger.LogInformation("Сохранение списка группированных заказов"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка группированных заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/SushiBar/SushiBarView/FormReportGroupedOrders.resx b/SushiBar/SushiBarView/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportGroupedOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportShop.Designer.cs b/SushiBar/SushiBarView/FormReportShop.Designer.cs new file mode 100644 index 0000000..405a457 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportShop.Designer.cs @@ -0,0 +1,116 @@ +namespace SushiBarView +{ + partial class FormReportShop + { + /// + /// 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.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnShop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnSushi = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(0, 6); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(223, 29); + this.buttonSaveToExcel.TabIndex = 3; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnShop, + this.ColumnSushi, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 47); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(598, 403); + this.dataGridView.TabIndex = 2; + // + // ColumnShop + // + this.ColumnShop.FillWeight = 130F; + this.ColumnShop.HeaderText = "Магазин"; + this.ColumnShop.MinimumWidth = 6; + this.ColumnShop.Name = "ColumnShop"; + this.ColumnShop.ReadOnly = true; + // + // ColumnSushi + // + this.ColumnSushi.FillWeight = 140F; + this.ColumnSushi.HeaderText = "Пицца"; + this.ColumnSushi.MinimumWidth = 6; + this.ColumnSushi.Name = "ColumnSushi"; + this.ColumnSushi.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.FillWeight = 90F; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(598, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportShop"; + this.Text = "Наполненость магазинов"; + this.Load += new System.EventHandler(this.FormReportShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnSushi; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportShop.cs b/SushiBar/SushiBarView/FormReportShop.cs new file mode 100644 index 0000000..0fb09a2 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportShop.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormReportShop : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShop(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShop_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShops(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Sushis) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка пицц по магазинам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка пицц по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopsToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка пицц по магазинам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка пицц по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/SushiBar/SushiBarView/FormReportShop.resx b/SushiBar/SushiBarView/FormReportShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 9a64bcf..6417726 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -9,9 +9,9 @@ using SushiBarView; using NLog.Extensions.Logging; using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarBusinessLogic.OfficePackage; -using SushiBarBusinessLogic; using SushiBarView.Reports; -using NLog.Extensions.Logging; +using NLog.Extensions.Logging; +using SushiBarView; namespace SushiBarView { @@ -41,6 +41,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -54,6 +55,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -66,6 +68,10 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/ReportGroupedOrders.rdlc b/SushiBar/SushiBarView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..2ef2b88 --- /dev/null +++ b/SushiBar/SushiBarView/ReportGroupedOrders.rdlc @@ -0,0 +1,441 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + PrecastConcretePlantContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + PrecastConcretePlantContracts.ViewModels + ReportGroupOrdersViewModel + PrecastConcretePlantContracts.ViewModels.ReportGroupOrdersViewModel, PrecastConcretePlantContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Отчёт по заказам + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90406cm + + + 3.97461cm + + + 3.65711cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Общая сумма заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Date.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersCount.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersSum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 1.88242cm + 2.68676cm + 1.2cm + 11.53578cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.29409cm + 8.06542cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!OrdersSum.Value, "DataSetGroupedOrders") + + + + + + + 3.29409cm + 10.70653cm + 0.6cm + 3.48072cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +