From f5462ca1f8cdb11203a568e447dd11b3092cd5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 22:52:37 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= =?UTF-8?q?=20=D1=81=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractFoodOrdersDataModels.csproj | 9 +++++++++ .../Enums/OrderStatus.cs | 17 ++++++++++++++++ .../AbstractFoodOrdersDataModels/IId.cs | 13 ++++++++++++ .../Models/IComponentModel.cs | 14 +++++++++++++ .../Models/IOrderModel.cs | 20 +++++++++++++++++++ .../Models/IProductModel.cs | 15 ++++++++++++++ FoodOrders/FoodOrders.sln | 8 +++++++- 7 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/Enums/OrderStatus.cs create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/IId.cs create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/Models/IComponentModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs diff --git a/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Enums/OrderStatus.cs b/FoodOrders/AbstractFoodOrdersDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..a15d9e9 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/FoodOrders/AbstractFoodOrdersDataModels/IId.cs b/FoodOrders/AbstractFoodOrdersDataModels/IId.cs new file mode 100644 index 0000000..ba6b9c9 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Models/IComponentModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..2483568 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..fcef39d --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels.Models +{ + public interface IOrderModel : IId + { + int ProductId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } + +} diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs new file mode 100644 index 0000000..9470d89 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels.Models +{ + public interface IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + } +} diff --git a/FoodOrders/FoodOrders.sln b/FoodOrders/FoodOrders.sln index c663e00..d73092d 100644 --- a/FoodOrders/FoodOrders.sln +++ b/FoodOrders/FoodOrders.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodOrders", "FoodOrders\FoodOrders.csproj", "{4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrders", "FoodOrders\FoodOrders.csproj", "{4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersDataModels", "AbstractFoodOrdersDataModels\AbstractFoodOrdersDataModels.csproj", "{797093A6-6C7B-414E-874F-1BB48A6468C7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU {4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU {4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}.Release|Any CPU.Build.0 = Release|Any CPU + {797093A6-6C7B-414E-874F-1BB48A6468C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {797093A6-6C7B-414E-874F-1BB48A6468C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {797093A6-6C7B-414E-874F-1BB48A6468C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {797093A6-6C7B-414E-874F-1BB48A6468C7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From 1d3604e5d763c0f1b4372eec02b7175b19eadd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 09:16:53 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D1=81=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractFoodOrdersContracts.csproj | 13 ++++++++ .../BindingModels/ComponentBindingModel.cs | 17 +++++++++++ .../BindingModels/DishBindingModel.cs | 18 +++++++++++ .../BindingModels/OrderBindingModel.cs | 22 ++++++++++++++ .../IComponentLogic.cs | 20 +++++++++++++ .../BusinessLogicsContracts/IDishLogic.cs | 21 +++++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 +++++++++++++ .../SearchModels/ComponentSearchModel.cs | 15 ++++++++++ .../SearchModels/DishSearchModel.cs | 14 +++++++++ .../SearchModels/OrderSearchModel.cs | 14 +++++++++ .../StoragesContracts/IComponentStorage.cs | 22 ++++++++++++++ .../StoragesContracts/IDishStorage.cs | 22 ++++++++++++++ .../StoragesContracts/IOrderStorage.cs | 21 +++++++++++++ .../ViewModels/ComponentViewModel.cs | 20 +++++++++++++ .../ViewModels/DishViewModel.cs | 21 +++++++++++++ .../ViewModels/OrderViewModel.cs | 30 +++++++++++++++++++ .../{IProductModel.cs => IDishModel.cs} | 6 ++-- FoodOrders/FoodOrders.sln | 6 ++++ 18 files changed, 319 insertions(+), 3 deletions(-) create mode 100644 FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BindingModels/ComponentBindingModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/SearchModels/ComponentSearchModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/SearchModels/DishSearchModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/SearchModels/OrderSearchModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IComponentStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/ViewModels/ComponentViewModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/ViewModels/DishViewModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs rename FoodOrders/AbstractFoodOrdersDataModels/Models/{IProductModel.cs => IDishModel.cs} (58%) diff --git a/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj new file mode 100644 index 0000000..e562052 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ComponentBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..62ae5e2 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs new file mode 100644 index 0000000..5a45022 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs @@ -0,0 +1,18 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.BindingModels +{ + public class ProductBindingModel : IDishModel + { + public int Id { get; set; } + public string DishName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary DishComponents { get; set; } = new(); + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..21cf8d5 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using AbstractFoodOrdersDataModels.Enums; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ProductId { 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/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IComponentLogic.cs b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..98ae7fd --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs new file mode 100644 index 0000000..8b231cc --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs @@ -0,0 +1,21 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.BusinessLogicsContracts +{ + public interface IDishLogic + { + List? ReadList(DishSearchModel? model); + DishViewModel? ReadElement(DishSearchModel model); + bool Create(ProductBindingModel model); + bool Update(ProductBindingModel model); + bool Delete(ProductBindingModel model); + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..19f7572 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ComponentSearchModel.cs b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..bb206d5 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/SearchModels/DishSearchModel.cs b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/DishSearchModel.cs new file mode 100644 index 0000000..88f0b2a --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/DishSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.SearchModels +{ + public class DishSearchModel + { + public int? Id { get; set; } + public string? DishName { get; set; } + } +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/SearchModels/OrderSearchModel.cs b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..801b087 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IComponentStorage.cs b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..7e6849a --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs new file mode 100644 index 0000000..c3dcbac --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs @@ -0,0 +1,22 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.StoragesContracts +{ + public interface IDishStorage + { + List GetFullList(); + List GetFilteredList(DishSearchModel model); + DishViewModel? GetElement(DishSearchModel model); + DishViewModel? Insert(ProductBindingModel model); + DishViewModel? Update(ProductBindingModel model); + DishViewModel? Delete(ProductBindingModel model); + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IOrderStorage.cs b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..b0533b9 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ComponentViewModel.cs b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..1aa5c75 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/ViewModels/DishViewModel.cs b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/DishViewModel.cs new file mode 100644 index 0000000..dfab78c --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/DishViewModel.cs @@ -0,0 +1,21 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.ViewModels +{ + public class DishViewModel : IDishModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string DishName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary DishComponents { get; set; } = new(); + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..1c19ca4 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using AbstractFoodOrdersDataModels.Enums; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ProductId { get; set; } + [DisplayName("Изделие")] + public string ProductName { 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/FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IDishModel.cs similarity index 58% rename from FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs rename to FoodOrders/AbstractFoodOrdersDataModels/Models/IDishModel.cs index 9470d89..4ab72db 100644 --- a/FoodOrders/AbstractFoodOrdersDataModels/Models/IProductModel.cs +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IDishModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace AbstractFoodOrdersDataModels.Models { - public interface IProductModel : IId + public interface IDishModel : IId { - string ProductName { get; } + string DishName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary DishComponents { get; } } } diff --git a/FoodOrders/FoodOrders.sln b/FoodOrders/FoodOrders.sln index d73092d..e8ea3d4 100644 --- a/FoodOrders/FoodOrders.sln +++ b/FoodOrders/FoodOrders.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrders", "FoodOrders\Fo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersDataModels", "AbstractFoodOrdersDataModels\AbstractFoodOrdersDataModels.csproj", "{797093A6-6C7B-414E-874F-1BB48A6468C7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersContracts", "AbstractFoodOrdersContracts\AbstractFoodOrdersContracts.csproj", "{926B4BA4-42BC-4D7B-AF27-01B16493D883}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {797093A6-6C7B-414E-874F-1BB48A6468C7}.Debug|Any CPU.Build.0 = Debug|Any CPU {797093A6-6C7B-414E-874F-1BB48A6468C7}.Release|Any CPU.ActiveCfg = Release|Any CPU {797093A6-6C7B-414E-874F-1BB48A6468C7}.Release|Any CPU.Build.0 = Release|Any CPU + {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Debug|Any CPU.Build.0 = Debug|Any CPU + {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Release|Any CPU.ActiveCfg = Release|Any CPU + {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From d33680bddd63a6c51e18369fb3ef33dfeb288dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 09:45:52 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../AbstractFoodOrdersBusinessLogic.csproj | 17 +++ .../BusinessLogics/ComponentLogic.cs | 114 ++++++++++++++++++ .../AbstractFoodOrdersContracts.csproj | 4 + .../AbstractFoodOrdersDataModels.csproj | 4 + FoodOrders/FoodOrders.sln | 16 ++- FoodOrders/FoodOrders/FoodOrders.csproj | 4 + 7 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj create mode 100644 FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ComponentLogic.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..c6b950f 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/FoodOrders/AbstractFoodOrdersListImplement diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj b/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj new file mode 100644 index 0000000..9fc4037 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ComponentLogic.cs b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..f64f450 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,114 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + + +namespace AbstractFoodOrdersBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel{ ComponentName = model.ComponentName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } + +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj index e562052..8791d49 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj +++ b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj index 132c02c..6ea4cf5 100644 --- a/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj +++ b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/FoodOrders/FoodOrders.sln b/FoodOrders/FoodOrders.sln index e8ea3d4..e27e831 100644 --- a/FoodOrders/FoodOrders.sln +++ b/FoodOrders/FoodOrders.sln @@ -5,9 +5,13 @@ VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrders", "FoodOrders\FoodOrders.csproj", "{4DC7A9CF-C994-4010-B23B-F4DB4D964D1D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersDataModels", "AbstractFoodOrdersDataModels\AbstractFoodOrdersDataModels.csproj", "{797093A6-6C7B-414E-874F-1BB48A6468C7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersDataModels", "AbstractFoodOrdersDataModels\AbstractFoodOrdersDataModels.csproj", "{797093A6-6C7B-414E-874F-1BB48A6468C7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersContracts", "AbstractFoodOrdersContracts\AbstractFoodOrdersContracts.csproj", "{926B4BA4-42BC-4D7B-AF27-01B16493D883}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersContracts", "AbstractFoodOrdersContracts\AbstractFoodOrdersContracts.csproj", "{926B4BA4-42BC-4D7B-AF27-01B16493D883}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersBusinessLogic", "AbstractFoodOrdersBusinessLogic\AbstractFoodOrdersBusinessLogic.csproj", "{A595D2B1-2193-4688-BECD-6D815AEE1142}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersListImplement", "AbstractFoodOrdersListImplement\AbstractFoodOrdersListImplement.csproj", "{275ED134-536F-4025-BE10-2718F66FBD10}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +31,14 @@ Global {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Debug|Any CPU.Build.0 = Debug|Any CPU {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Release|Any CPU.ActiveCfg = Release|Any CPU {926B4BA4-42BC-4D7B-AF27-01B16493D883}.Release|Any CPU.Build.0 = Release|Any CPU + {A595D2B1-2193-4688-BECD-6D815AEE1142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A595D2B1-2193-4688-BECD-6D815AEE1142}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A595D2B1-2193-4688-BECD-6D815AEE1142}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A595D2B1-2193-4688-BECD-6D815AEE1142}.Release|Any CPU.Build.0 = Release|Any CPU + {275ED134-536F-4025-BE10-2718F66FBD10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {275ED134-536F-4025-BE10-2718F66FBD10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {275ED134-536F-4025-BE10-2718F66FBD10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {275ED134-536F-4025-BE10-2718F66FBD10}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FoodOrders/FoodOrders/FoodOrders.csproj b/FoodOrders/FoodOrders/FoodOrders.csproj index b57c89e..7173d64 100644 --- a/FoodOrders/FoodOrders/FoodOrders.csproj +++ b/FoodOrders/FoodOrders/FoodOrders.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file -- 2.25.1 From 48027c484dc13345e5ac2b061aa4d02708384344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 11:11:35 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=BE=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20+=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractFoodOrdersListImplement.csproj | 14 ++ .../DataListSingleton.cs | 31 +++++ .../Implements/ComponentStorage.cs | 12 ++ .../Implements/DishStorage.cs | 106 +++++++++++++++ .../Implements/OrderStorage.cs | 123 ++++++++++++++++++ .../Models/Component.cs | 47 +++++++ .../Models/Dish.cs | 49 +++++++ .../Models/Order.cs | 63 +++++++++ 8 files changed, 445 insertions(+) create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Implements/DishStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Implements/OrderStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Models/Component.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs diff --git a/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj b/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj new file mode 100644 index 0000000..9d405d7 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs new file mode 100644 index 0000000..48da865 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AbstractFoodOrdersListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..59235d1 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Implements +{ + internal class ComponentStorage + { + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/DishStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/DishStorage.cs new file mode 100644 index 0000000..022643b --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/DishStorage.cs @@ -0,0 +1,106 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Implements +{ + public class DishStorage : IDishStorage + { + private readonly DataListSingleton _source; + public DishStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var dish in _source.Dishes) + { + result.Add(dish.GetViewModel); + } + return result; + } + public List GetFilteredList(DishSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.DishName)) + { + return result; + } + foreach (var dish in _source.Dishes) + { + if (dish.DishName.Contains(model.DishName)) + { + result.Add(dish.GetViewModel); + } + } + return result; + } + public DishViewModel? GetElement(DishSearchModel model) + { + if (string.IsNullOrEmpty(model.DishName) && !model.Id.HasValue) + { + return null; + } + foreach (var dish in _source.Dishes) + { + if ((!string.IsNullOrEmpty(model.DishName) && dish.DishName == model.DishName) || + (model.Id.HasValue && dish.Id == model.Id)) + { + return dish.GetViewModel; + } + } + return null; + } + public DishViewModel? Insert(DishBindingModel model) + { + model.Id = 1; + foreach (var dish in _source.Dishes) + { + if (model.Id <= dish.Id) + { + model.Id = dish.Id + 1; + } + } + var newDish = Dish.Create(model); + if (newDish == null) + { + return null; + } + _source.Dishes.Add(newDish); + return newDish.GetViewModel; + } + public DishViewModel? Update(DishBindingModel model) + { + foreach (var dish in _source.Dishes) + { + if (dish.Id == model.Id) + { + dish.Update(model); + return dish.GetViewModel; + } + } + return null; + } + public DishViewModel? Delete(DishBindingModel model) + { + for (int i = 0; i < _source.Dishes.Count; ++i) + { + if (_source.Dishes[i].Id == model.Id) + { + var element = _source.Dishes[i]; + _source.Dishes.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/OrderStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..db015b8 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/OrderStorage.cs @@ -0,0 +1,123 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.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(AttachReinforcedName(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(AttachReinforcedName(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 AttachReinforcedName(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 AttachReinforcedName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachReinforcedName(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 AttachReinforcedName(element.GetViewModel); + } + } + return null; + } + private OrderViewModel AttachReinforcedName(OrderViewModel model) + { + //Из всех мест, это выглядит наиболее подходящим, для данной манипуляции. + //При расположении ниже нарушится целостность данных + //При расположении выше будет нарушен принцип разделения уровней + foreach (var reinforced in _source.Dishes) + { + if (reinforced.Id == model.DishId) + { + model.DishName = reinforced.DishName; + return model; + } + } + return model; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/Component.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/Component.cs new file mode 100644 index 0000000..406ac57 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } + +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs new file mode 100644 index 0000000..4759747 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs @@ -0,0 +1,49 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Models +{ + public class Dish : IDishModel + { + public int Id { get; private set; } + public string DishName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary DishComponents + { + get; + private set; + } = new Dictionary(); + public static Dish? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Dish(){ Id = model.Id, DishName = model.DishName, Price = model.Price, DishComponents = model.DishComponents }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + DishName = model.DishName; + Price = model.Price; + DishComponents = model.DishComponents; + } + public DishViewModel GetViewModel => new() + { + Id = Id, + DishName = DishName, + Price = Price, + DishComponents = DishComponents + }; + } + +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs new file mode 100644 index 0000000..293b645 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs @@ -0,0 +1,63 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Enums; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int DishId { 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, + DishId = model.DishId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + DishId = model.DishId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + DishId = DishId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} -- 2.25.1 From 130ea7cc1dbeebbf4b178198b7c355b7625a5f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 11:12:20 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/DishLogic.cs | 116 +++++++++++++++++ .../BusinessLogics/OrderLogic.cs | 120 ++++++++++++++++++ .../BindingModels/DishBindingModel.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 2 +- .../BusinessLogicsContracts/IDishLogic.cs | 6 +- .../StoragesContracts/IDishStorage.cs | 6 +- .../ViewModels/OrderViewModel.cs | 4 +- .../Models/IOrderModel.cs | 2 +- .../DataListSingleton.cs | 4 +- .../Models/Dish.cs | 4 +- 10 files changed, 251 insertions(+), 15 deletions(-) create mode 100644 FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/DishLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/DishLogic.cs b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/DishLogic.cs new file mode 100644 index 0000000..0b1cc44 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/DishLogic.cs @@ -0,0 +1,116 @@ +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersBusinessLogic.BusinessLogics +{ + public class DishLogic : IDishLogic + { + private readonly ILogger _logger; + private readonly IDishStorage _dishStorage; + public DishLogic(ILogger logger, IDishStorage dishStorage) + { + _logger = logger; + _dishStorage = dishStorage; + } + public List? ReadList(DishSearchModel? model) + { + _logger.LogInformation("ReadList. DishName:{DishName}.Id:{ Id}", model?.DishName, model?.Id); + var list = model == null ? _dishStorage.GetFullList() : _dishStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DishViewModel? ReadElement(DishSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DishName:{DishName}.Id:{ Id}", model.DishName, model.Id); + var element = _dishStorage.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(DishBindingModel model) + { + CheckModel(model); + if (_dishStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DishBindingModel model) + { + CheckModel(model); + if (_dishStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DishBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_dishStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DishBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DishName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.DishName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + if (model.DishComponents == null || model.DishComponents.Count == 0) + { + throw new ArgumentNullException("Перечень компонентов не может быть пустым", nameof(model.DishComponents)); + } + _logger.LogInformation("Dish. DishName:{DishName}.Price:{Price}.Id: { Id}", model.DishName, model.Price, model.Id); + var element = _dishStorage.GetElement(new DishSearchModel + { + DishName = model.DishName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..b598f0d --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,120 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersBusinessLogic.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("Reinforced. ReinforcedId:{ReinforcedId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.DishId, 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.DishId = element.DishId; + 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/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs index 5a45022..e48c8d1 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/DishBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AbstractFoodOrdersContracts.BindingModels { - public class ProductBindingModel : IDishModel + public class DishBindingModel : IDishModel { public int Id { get; set; } public string DishName { get; set; } = string.Empty; diff --git a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs index 21cf8d5..bdac97b 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/OrderBindingModel.cs @@ -11,7 +11,7 @@ namespace AbstractFoodOrdersContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } + public int DishId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs index 8b231cc..f003613 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs +++ b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IDishLogic.cs @@ -13,9 +13,9 @@ namespace AbstractFoodOrdersContracts.BusinessLogicsContracts { List? ReadList(DishSearchModel? model); DishViewModel? ReadElement(DishSearchModel model); - bool Create(ProductBindingModel model); - bool Update(ProductBindingModel model); - bool Delete(ProductBindingModel model); + bool Create(DishBindingModel model); + bool Update(DishBindingModel model); + bool Delete(DishBindingModel model); } } diff --git a/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs index c3dcbac..8250a86 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs +++ b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IDishStorage.cs @@ -14,9 +14,9 @@ namespace AbstractFoodOrdersContracts.StoragesContracts List GetFullList(); List GetFilteredList(DishSearchModel model); DishViewModel? GetElement(DishSearchModel model); - DishViewModel? Insert(ProductBindingModel model); - DishViewModel? Update(ProductBindingModel model); - DishViewModel? Delete(ProductBindingModel model); + DishViewModel? Insert(DishBindingModel model); + DishViewModel? Update(DishBindingModel model); + DishViewModel? Delete(DishBindingModel model); } } diff --git a/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs index 1c19ca4..15a83a9 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs +++ b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/OrderViewModel.cs @@ -13,9 +13,9 @@ namespace AbstractFoodOrdersContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int DishId { get; set; } [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public string DishName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs index fcef39d..e196a08 100644 --- a/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IOrderModel.cs @@ -9,7 +9,7 @@ namespace AbstractFoodOrdersDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } + int DishId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs index 48da865..b4e1a01 100644 --- a/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs +++ b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs @@ -12,12 +12,12 @@ namespace AbstractFoodOrdersListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Dishes { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Dishes = new List(); } public static DataListSingleton GetInstance() { diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs index 4759747..da864ae 100644 --- a/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs @@ -19,7 +19,7 @@ namespace AbstractFoodOrdersListImplement.Models get; private set; } = new Dictionary(); - public static Dish? Create(ProductBindingModel? model) + public static Dish? Create(DishBindingModel? model) { if (model == null) { @@ -27,7 +27,7 @@ namespace AbstractFoodOrdersListImplement.Models } return new Dish(){ Id = model.Id, DishName = model.DishName, Price = model.Price, DishComponents = model.DishComponents }; } - public void Update(ProductBindingModel? model) + public void Update(DishBindingModel? model) { if (model == null) { -- 2.25.1 From 44b015372f616a6f8e66c7f639a8aa6946f7e715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 10:48:37 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=B0?= =?UTF-8?q?=D1=8F=201=20=D0=BB=D0=B0=D0=B1=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractFoodOrdersBusinessLogic.csproj | 1 + .../AbstractFoodOrdersContracts.csproj | 1 + .../AbstractFoodOrdersDataModels.csproj | 1 + .../AbstractFoodOrdersListImplement.csproj | 5 + .../Implements/ComponentStorage.cs | 103 +++++++- FoodOrders/FoodOrders.sln | 4 +- FoodOrders/FoodOrders/FoodOrders.csproj | 17 ++ FoodOrders/FoodOrders/Form1.Designer.cs | 39 --- FoodOrders/FoodOrders/Form1.cs | 10 - FoodOrders/FoodOrders/Form1.resx | 120 --------- .../FoodOrders/FormComponent.Designer.cs | 118 +++++++++ FoodOrders/FoodOrders/FormComponent.cs | 97 ++++++++ FoodOrders/FoodOrders/FormComponent.resx | 60 +++++ .../FoodOrders/FormComponents.Designer.cs | 116 +++++++++ FoodOrders/FoodOrders/FormComponents.cs | 113 +++++++++ FoodOrders/FoodOrders/FormComponents.resx | 60 +++++ .../FoodOrders/FormCreateOrder.Designer.cs | 143 +++++++++++ FoodOrders/FoodOrders/FormCreateOrder.cs | 157 ++++++++++++ FoodOrders/FoodOrders/FormCreateOrder.resx | 60 +++++ FoodOrders/FoodOrders/FormDish.Designer.cs | 231 ++++++++++++++++++ FoodOrders/FoodOrders/FormDish.cs | 223 +++++++++++++++++ FoodOrders/FoodOrders/FormDish.resx | 69 ++++++ .../FoodOrders/FormDishComponent.Designer.cs | 119 +++++++++ FoodOrders/FoodOrders/FormDishComponent.cs | 90 +++++++ FoodOrders/FoodOrders/FormDishComponent.resx | 60 +++++ FoodOrders/FoodOrders/FormDishes.Designer.cs | 119 +++++++++ FoodOrders/FoodOrders/FormDishes.cs | 112 +++++++++ FoodOrders/FoodOrders/FormDishes.resx | 60 +++++ FoodOrders/FoodOrders/FormMain.Designer.cs | 177 ++++++++++++++ FoodOrders/FoodOrders/FormMain.cs | 162 ++++++++++++ FoodOrders/FoodOrders/FormMain.resx | 63 +++++ FoodOrders/FoodOrders/Program.cs | 41 +++- FoodOrders/FoodOrders/nlog.config | 15 ++ 33 files changed, 2591 insertions(+), 175 deletions(-) delete mode 100644 FoodOrders/FoodOrders/Form1.Designer.cs delete mode 100644 FoodOrders/FoodOrders/Form1.cs delete mode 100644 FoodOrders/FoodOrders/Form1.resx create mode 100644 FoodOrders/FoodOrders/FormComponent.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormComponent.cs create mode 100644 FoodOrders/FoodOrders/FormComponent.resx create mode 100644 FoodOrders/FoodOrders/FormComponents.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormComponents.cs create mode 100644 FoodOrders/FoodOrders/FormComponents.resx create mode 100644 FoodOrders/FoodOrders/FormCreateOrder.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormCreateOrder.cs create mode 100644 FoodOrders/FoodOrders/FormCreateOrder.resx create mode 100644 FoodOrders/FoodOrders/FormDish.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormDish.cs create mode 100644 FoodOrders/FoodOrders/FormDish.resx create mode 100644 FoodOrders/FoodOrders/FormDishComponent.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormDishComponent.cs create mode 100644 FoodOrders/FoodOrders/FormDishComponent.resx create mode 100644 FoodOrders/FoodOrders/FormDishes.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormDishes.cs create mode 100644 FoodOrders/FoodOrders/FormDishes.resx create mode 100644 FoodOrders/FoodOrders/FormMain.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormMain.cs create mode 100644 FoodOrders/FoodOrders/FormMain.resx create mode 100644 FoodOrders/FoodOrders/nlog.config diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj b/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj index 9fc4037..4bc8ed4 100644 --- a/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/AbstractFoodOrdersBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj index 8791d49..334fa22 100644 --- a/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj +++ b/FoodOrders/AbstractFoodOrdersContracts/AbstractFoodOrdersContracts.csproj @@ -8,6 +8,7 @@ + diff --git a/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj index 6ea4cf5..6e4397d 100644 --- a/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj +++ b/FoodOrders/AbstractFoodOrdersDataModels/AbstractFoodOrdersDataModels.csproj @@ -8,6 +8,7 @@ + diff --git a/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj b/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj index 9d405d7..6c08ca5 100644 --- a/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj +++ b/FoodOrders/AbstractFoodOrdersListImplement/AbstractFoodOrdersListImplement.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs index 59235d1..cd8665d 100644 --- a/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ComponentStorage.cs @@ -1,4 +1,9 @@ -using System; +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersListImplement.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +11,101 @@ using System.Threading.Tasks; namespace AbstractFoodOrdersListImplement.Implements { - internal class ComponentStorage + public class ComponentStorage : IComponentStorage { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var ingredient in _source.Components) + { + result.Add(ingredient.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var ingredient in _source.Components) + { + if (ingredient.ComponentName.Contains(model.ComponentName)) + { + result.Add(ingredient.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var ingredient in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && ingredient.ComponentName == model.ComponentName) || + (model.Id.HasValue && ingredient.Id == model.Id)) + { + return ingredient.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var ingredient in _source.Components) + { + if (model.Id <= ingredient.Id) + { + model.Id = ingredient.Id + 1; + } + } + var newIngredient = Component.Create(model); + if (newIngredient == null) + { + return null; + } + _source.Components.Add(newIngredient); + return newIngredient.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var ingredient in _source.Components) + { + if (ingredient.Id == model.Id) + { + ingredient.Update(model); + return ingredient.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } } } diff --git a/FoodOrders/FoodOrders.sln b/FoodOrders/FoodOrders.sln index e27e831..a185cde 100644 --- a/FoodOrders/FoodOrders.sln +++ b/FoodOrders/FoodOrders.sln @@ -9,9 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersDataModel EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersContracts", "AbstractFoodOrdersContracts\AbstractFoodOrdersContracts.csproj", "{926B4BA4-42BC-4D7B-AF27-01B16493D883}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersBusinessLogic", "AbstractFoodOrdersBusinessLogic\AbstractFoodOrdersBusinessLogic.csproj", "{A595D2B1-2193-4688-BECD-6D815AEE1142}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersBusinessLogic", "AbstractFoodOrdersBusinessLogic\AbstractFoodOrdersBusinessLogic.csproj", "{A595D2B1-2193-4688-BECD-6D815AEE1142}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersListImplement", "AbstractFoodOrdersListImplement\AbstractFoodOrdersListImplement.csproj", "{275ED134-536F-4025-BE10-2718F66FBD10}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFoodOrdersListImplement", "AbstractFoodOrdersListImplement\AbstractFoodOrdersListImplement.csproj", "{275ED134-536F-4025-BE10-2718F66FBD10}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/FoodOrders/FoodOrders/FoodOrders.csproj b/FoodOrders/FoodOrders/FoodOrders.csproj index 7173d64..ca31f64 100644 --- a/FoodOrders/FoodOrders/FoodOrders.csproj +++ b/FoodOrders/FoodOrders/FoodOrders.csproj @@ -10,6 +10,23 @@ + + + + + + + + + + + + + Form + + + Form + \ No newline at end of file diff --git a/FoodOrders/FoodOrders/Form1.Designer.cs b/FoodOrders/FoodOrders/Form1.Designer.cs deleted file mode 100644 index 9142cf3..0000000 --- a/FoodOrders/FoodOrders/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FoodOrders -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/Form1.cs b/FoodOrders/FoodOrders/Form1.cs deleted file mode 100644 index 387555b..0000000 --- a/FoodOrders/FoodOrders/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FoodOrders -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/Form1.resx b/FoodOrders/FoodOrders/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/FoodOrders/FoodOrders/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormComponent.Designer.cs b/FoodOrders/FoodOrders/FormComponent.Designer.cs new file mode 100644 index 0000000..3e57214 --- /dev/null +++ b/FoodOrders/FoodOrders/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AbstractFoodOrdersView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(28, 70); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(28, 113); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(48, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(130, 63); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(274, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(130, 106); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(171, 27); + this.textBoxCost.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(196, 169); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(310, 169); + 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); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(435, 222); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент "; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormComponent.cs b/FoodOrders/FoodOrders/FormComponent.cs new file mode 100644 index 0000000..e21bedd --- /dev/null +++ b/FoodOrders/FoodOrders/FormComponent.cs @@ -0,0 +1,97 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AbstractFoodOrdersView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FoodOrders/FoodOrders/FormComponent.resx b/FoodOrders/FoodOrders/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FoodOrders/FoodOrders/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/FoodOrders/FoodOrders/FormComponents.Designer.cs b/FoodOrders/FoodOrders/FormComponents.Designer.cs new file mode 100644 index 0000000..2e7c196 --- /dev/null +++ b/FoodOrders/FoodOrders/FormComponents.Designer.cs @@ -0,0 +1,116 @@ +namespace AbstractFoodOrdersView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonRef = 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.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 1); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(508, 448); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(561, 27); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(94, 29); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(561, 86); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(94, 29); + this.ButtonRef.TabIndex = 2; + this.ButtonRef.Text = "Изменить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(561, 144); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(94, 29); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(561, 194); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(94, 29); + this.ButtonUpd.TabIndex = 4; + this.ButtonUpd.Text = "Обновить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + 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.ButtonUpd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormComponents.cs b/FoodOrders/FoodOrders/FormComponents.cs new file mode 100644 index 0000000..3112e3f --- /dev/null +++ b/FoodOrders/FoodOrders/FormComponents.cs @@ -0,0 +1,113 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using FoodOrders; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AbstractFoodOrdersView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FoodOrders/FoodOrders/FormComponents.resx b/FoodOrders/FoodOrders/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FoodOrders/FoodOrders/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/FoodOrders/FoodOrders/FormCreateOrder.Designer.cs b/FoodOrders/FoodOrders/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..64f6102 --- /dev/null +++ b/FoodOrders/FoodOrders/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace FoodOrders +{ + 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.labelDish = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxDish = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelDish + // + this.labelDish.AutoSize = true; + this.labelDish.Location = new System.Drawing.Point(38, 30); + this.labelDish.Name = "labelDish"; + this.labelDish.Size = new System.Drawing.Size(58, 20); + this.labelDish.TabIndex = 0; + this.labelDish.Text = "Блюдо:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 76); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(38, 125); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(55, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма"; + // + // comboBoxDish + // + this.comboBoxDish.FormattingEnabled = true; + this.comboBoxDish.Location = new System.Drawing.Point(148, 27); + this.comboBoxDish.Name = "comboBoxDish"; + this.comboBoxDish.Size = new System.Drawing.Size(286, 28); + this.comboBoxDish.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(148, 69); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(286, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(148, 118); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(286, 27); + this.textBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(211, 174); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(340, 174); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(466, 229); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDish); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDish); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelDish; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxDish; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormCreateOrder.cs b/FoodOrders/FoodOrders/FormCreateOrder.cs new file mode 100644 index 0000000..36de5b0 --- /dev/null +++ b/FoodOrders/FoodOrders/FormCreateOrder.cs @@ -0,0 +1,157 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrders +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IDishLogic _logicD; + private readonly IOrderLogic _logicO; + private List? _list; + public int Id + { + get + { + return + Convert.ToInt32(comboBoxDish.SelectedValue); + } + set + { + comboBoxDish.SelectedValue = value; + } + } + public IDishModel? DishModel + { + 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 FormCreateOrder(ILogger logger, IDishLogic + logicD, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + _list = _logicD.ReadList(null); + + if (_list != null) + { + comboBoxDish.DisplayMember = "DishName"; + comboBoxDish.ValueMember = "Id"; + comboBoxDish.DataSource = _list; + comboBoxDish.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxDish.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxDish.SelectedValue); + var dish = _logicD.ReadElement(new DishSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (dish?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxProduct_SelectedIndexChanged(object sender, + EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDish.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + DishId = Convert.ToInt32(comboBoxDish.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/FoodOrders/FoodOrders/FormCreateOrder.resx b/FoodOrders/FoodOrders/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FoodOrders/FoodOrders/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/FoodOrders/FoodOrders/FormDish.Designer.cs b/FoodOrders/FoodOrders/FormDish.Designer.cs new file mode 100644 index 0000000..51c04d1 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDish.Designer.cs @@ -0,0 +1,231 @@ +namespace FoodOrders +{ + partial class FormDish + { + /// + /// 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.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.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.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.ButtonUpd); + this.groupBoxComponents.Controls.Add(this.ButtonDel); + this.groupBoxComponents.Controls.Add(this.ButtonRef); + this.groupBoxComponents.Controls.Add(this.ButtonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(12, 143); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Size = new System.Drawing.Size(821, 292); + this.groupBoxComponents.TabIndex = 0; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(690, 206); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(94, 29); + this.ButtonUpd.TabIndex = 4; + this.ButtonUpd.Text = "Обновить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(690, 161); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(94, 29); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(690, 114); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(94, 29); + this.ButtonRef.TabIndex = 2; + this.ButtonRef.Text = "Изменить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(690, 67); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(94, 29); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(648, 260); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(553, 455); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 1; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(678, 455); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 2; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(48, 37); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 3; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(48, 79); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(86, 20); + this.labelCost.TabIndex = 4; + this.labelCost.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(144, 30); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(353, 27); + this.textBoxName.TabIndex = 5; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(144, 72); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(192, 27); + this.textBoxPrice.TabIndex = 6; + // + // FormDish + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(845, 515); + this.Controls.Add(this.textBoxPrice); + 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.Controls.Add(this.groupBoxComponents); + this.Name = "FormDish"; + this.Text = "Блюдо"; + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox groupBoxComponents; + private DataGridView dataGridView; + private Button ButtonSave; + private Button ButtonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private Button ButtonAdd; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxPrice; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormDish.cs b/FoodOrders/FoodOrders/FormDish.cs new file mode 100644 index 0000000..41bf6c7 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDish.cs @@ -0,0 +1,223 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrders +{ + public partial class FormDish : Form + { + private readonly ILogger _logger; + private readonly IDishLogic _logic; + private int? _id; + private Dictionary _productComponents; + public int Id { set { _id = value; } } + + public FormDish(ILogger logger, IDishLogic logic) { + InitializeComponent(); + _logger = logger; + _logic = logic; + _productComponents = new Dictionary(); + } + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new DishSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.DishName; + textBoxPrice.Text = view.Price.ToString(); + _productComponents = view.DishComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_productComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _productComponents) + { + 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(FormDishComponent)); + if (service is FormDishComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _productComponents.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(FormDishComponent)); + if (service is FormDishComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _productComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _productComponents[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); + + _productComponents?.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 (_productComponents == null || _productComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new DishBindingModel + { + Id = _id ?? 0, + DishName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + DishComponents = _productComponents + }; + 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 _productComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FoodOrders/FoodOrders/FormDish.resx b/FoodOrders/FoodOrders/FormDish.resx new file mode 100644 index 0000000..58a78b5 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDish.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormDishComponent.Designer.cs b/FoodOrders/FoodOrders/FormDishComponent.Designer.cs new file mode 100644 index 0000000..2e071b3 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace FoodOrders +{ + partial class FormDishComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(38, 45); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(91, 20); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 92); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(150, 37); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(289, 28); + this.comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 85); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(289, 27); + this.textBoxCount.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(195, 138); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(334, 138); + 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); + // + // FormDishComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(476, 185); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Name = "FormDishComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormDishComponent.cs b/FoodOrders/FoodOrders/FormDishComponent.cs new file mode 100644 index 0000000..0f17863 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishComponent.cs @@ -0,0 +1,90 @@ +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.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 FoodOrders +{ + public partial class FormDishComponent : 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 FormDishComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FoodOrders/FoodOrders/FormDishComponent.resx b/FoodOrders/FoodOrders/FormDishComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishComponent.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/FoodOrders/FoodOrders/FormDishes.Designer.cs b/FoodOrders/FoodOrders/FormDishes.Designer.cs new file mode 100644 index 0000000..7c66d58 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishes.Designer.cs @@ -0,0 +1,119 @@ +namespace FoodOrders +{ + partial class FormDishes + { + /// + /// 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.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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(523, 186); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(523, 128); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(523, 71); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(523, 14); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 2); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.TabIndex = 5; + // + // FormDishes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(642, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormDishes"; + this.Text = "Блюда"; + this.Load += new System.EventHandler(this.FormDishes_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormDishes.cs b/FoodOrders/FoodOrders/FormDishes.cs new file mode 100644 index 0000000..d7edcc9 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishes.cs @@ -0,0 +1,112 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrders +{ + public partial class FormDishes : Form + { + private readonly ILogger _logger; + private readonly IDishLogic _logic; + + public FormDishes(ILogger logger, IDishLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDishes_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["DishComponents"].Visible = false; + dataGridView.Columns["DishName"].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(FormDish)); + if (service is FormDish 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(FormDish)); + if (service is FormDish 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 DishBindingModel { 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/FoodOrders/FoodOrders/FormDishes.resx b/FoodOrders/FoodOrders/FormDishes.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FoodOrders/FoodOrders/FormDishes.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/FoodOrders/FoodOrders/FormMain.Designer.cs b/FoodOrders/FoodOrders/FormMain.Designer.cs new file mode 100644 index 0000000..bf50541 --- /dev/null +++ b/FoodOrders/FoodOrders/FormMain.Designer.cs @@ -0,0 +1,177 @@ +namespace FoodOrders +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.БлюдаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1104, 28); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.КомпонентыToolStripMenuItem, + this.БлюдаToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // КомпонентыToolStripMenuItem + // + this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.КомпонентыToolStripMenuItem.Text = "Компоненты"; + this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // БлюдаToolStripMenuItem + // + this.БлюдаToolStripMenuItem.Name = "БлюдаToolStripMenuItem"; + this.БлюдаToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.БлюдаToolStripMenuItem.Text = "Блюда"; + this.БлюдаToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 40); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(798, 408); + this.dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Location = new System.Drawing.Point(831, 82); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(241, 29); + this.ButtonCreateOrder.TabIndex = 2; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(831, 141); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(241, 29); + this.ButtonTakeOrderInWork.TabIndex = 3; + this.ButtonTakeOrderInWork.Text = "Отдать заказ на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Location = new System.Drawing.Point(831, 202); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(241, 29); + this.ButtonOrderReady.TabIndex = 4; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Location = new System.Drawing.Point(831, 264); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(241, 29); + this.ButtonIssuedOrder.TabIndex = 5; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(831, 331); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(241, 29); + this.ButtonRef.TabIndex = 6; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1104, 470); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Доставка еды"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem БлюдаToolStripMenuItem; + private DataGridView dataGridView; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormMain.cs b/FoodOrders/FoodOrders/FormMain.cs new file mode 100644 index 0000000..b13b4df --- /dev/null +++ b/FoodOrders/FoodOrders/FormMain.cs @@ -0,0 +1,162 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersView; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrders +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["DishId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormDishes)); + if (service is FormDishes form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FoodOrders/FoodOrders/FormMain.resx b/FoodOrders/FoodOrders/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/FoodOrders/FoodOrders/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/FoodOrders/FoodOrders/Program.cs b/FoodOrders/FoodOrders/Program.cs index c3ed338..6a119c7 100644 --- a/FoodOrders/FoodOrders/Program.cs +++ b/FoodOrders/FoodOrders/Program.cs @@ -1,9 +1,21 @@ +using AbstractFoodOrdersBusinessLogic.BusinessLogics; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersListImplement.Implements; +using AbstractFoodOrdersView; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; + namespace FoodOrders { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +23,32 @@ namespace FoodOrders // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file diff --git a/FoodOrders/FoodOrders/nlog.config b/FoodOrders/FoodOrders/nlog.config new file mode 100644 index 0000000..330375f --- /dev/null +++ b/FoodOrders/FoodOrders/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1