From 520b361e50c3c48b55f41b8322c843f32cf6802f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 24 Feb 2024 21:32:11 +0400 Subject: [PATCH 1/6] Base.01 --- Diner/Diner.sln | 26 +- .../BindingModels/FoodBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 27 ++ .../BindingModels/SnackBindingModel.cs | 20 ++ .../BusinessLogicsContracts/IFoodLogic.cs | 21 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 22 ++ .../BusinessLogicsContracts/ISnackLogic.cs | 21 ++ Diner/DinerContracts/DinerContracts.csproj | 13 + .../SearchModels/FoodSearchModel.cs | 14 + .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/SnackSearchModel.cs | 14 + .../StoragesContracts/IFoodStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 22 ++ .../StoragesContracts/ISnackStorage.cs | 22 ++ .../ViewModels/FoodViewModel.cs | 22 ++ .../ViewModels/OrderViewModel.cs | 38 +++ .../ViewModels/SnackViewModel.cs | 23 ++ Diner/DinerDataModels/DinerDataModels.csproj | 9 + Diner/DinerDataModels/Enums/OrderStatus.cs | 21 ++ Diner/DinerDataModels/IID.cs | 13 + Diner/DinerDataModels/Models/IFoodModel.cs | 14 + Diner/DinerDataModels/Models/IOrderModel.cs | 19 ++ Diner/DinerDataModels/Models/ISnackModel.cs | 19 ++ Diner/DinerListImplement/DataListSingleton.cs | 28 ++ .../DinerListImplement.csproj | 14 + .../Implements/FoodStorage.cs | 98 +++++++ .../Implements/OrderStorage.cs | 91 +++++++ .../Implements/SnackStorage.cs | 97 +++++++ Diner/DinerListImplement/Models/Food.cs | 39 +++ Diner/DinerListImplement/Models/Order.cs | 60 +++++ Diner/DinerListImplement/Models/Snack.cs | 46 ++++ Diner/DinerView/DinerView.csproj | 40 ++- Diner/DinerView/Form1.Designer.cs | 39 --- Diner/DinerView/Form1.cs | 10 - Diner/DinerView/FormCreateOrder.Designer.cs | 146 +++++++++++ Diner/DinerView/FormCreateOrder.cs | 120 +++++++++ Diner/DinerView/FormCreateOrder.resx | 120 +++++++++ Diner/DinerView/FormFood.Designer.cs | 118 +++++++++ Diner/DinerView/FormFood.cs | 89 +++++++ Diner/DinerView/FormFood.resx | 120 +++++++++ Diner/DinerView/FormFoods.Designer.cs | 122 +++++++++ Diner/DinerView/FormFoods.cs | 109 ++++++++ Diner/DinerView/FormFoods.resx | 120 +++++++++ Diner/DinerView/FormMain.Designer.cs | 174 +++++++++++++ Diner/DinerView/FormMain.cs | 156 ++++++++++++ Diner/DinerView/FormMain.resx | 123 +++++++++ Diner/DinerView/FormSnack.Designer.cs | 241 ++++++++++++++++++ Diner/DinerView/FormSnack.cs | 203 +++++++++++++++ Diner/DinerView/FormSnack.resx | 129 ++++++++++ Diner/DinerView/FormSnackFood.Designer.cs | 120 +++++++++ Diner/DinerView/FormSnackFood.cs | 89 +++++++ Diner/DinerView/FormSnackFood.resx | 120 +++++++++ Diner/DinerView/Nlog.config | 15 ++ Diner/DinerView/Program.cs | 38 ++- .../Properties/Resources.Designer.cs | 63 +++++ .../{Form1.resx => Properties/Resources.resx} | 0 .../BusinessLogic/FoodLogic.cs | 96 +++++++ .../BusinessLogic/OrderLogic.cs | 89 +++++++ .../BusinessLogic/SnackLogic.cs | 95 +++++++ .../DineryBusinessLogic.csproj | 17 ++ 60 files changed, 3794 insertions(+), 52 deletions(-) create mode 100644 Diner/DinerContracts/BindingModels/FoodBindingModel.cs create mode 100644 Diner/DinerContracts/BindingModels/OrderBindingModel.cs create mode 100644 Diner/DinerContracts/BindingModels/SnackBindingModel.cs create mode 100644 Diner/DinerContracts/BusinessLogicsContracts/IFoodLogic.cs create mode 100644 Diner/DinerContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 Diner/DinerContracts/BusinessLogicsContracts/ISnackLogic.cs create mode 100644 Diner/DinerContracts/DinerContracts.csproj create mode 100644 Diner/DinerContracts/SearchModels/FoodSearchModel.cs create mode 100644 Diner/DinerContracts/SearchModels/OrderSearchModel.cs create mode 100644 Diner/DinerContracts/SearchModels/SnackSearchModel.cs create mode 100644 Diner/DinerContracts/StoragesContracts/IFoodStorage.cs create mode 100644 Diner/DinerContracts/StoragesContracts/IOrderStorage.cs create mode 100644 Diner/DinerContracts/StoragesContracts/ISnackStorage.cs create mode 100644 Diner/DinerContracts/ViewModels/FoodViewModel.cs create mode 100644 Diner/DinerContracts/ViewModels/OrderViewModel.cs create mode 100644 Diner/DinerContracts/ViewModels/SnackViewModel.cs create mode 100644 Diner/DinerDataModels/DinerDataModels.csproj create mode 100644 Diner/DinerDataModels/Enums/OrderStatus.cs create mode 100644 Diner/DinerDataModels/IID.cs create mode 100644 Diner/DinerDataModels/Models/IFoodModel.cs create mode 100644 Diner/DinerDataModels/Models/IOrderModel.cs create mode 100644 Diner/DinerDataModels/Models/ISnackModel.cs create mode 100644 Diner/DinerListImplement/DataListSingleton.cs create mode 100644 Diner/DinerListImplement/DinerListImplement.csproj create mode 100644 Diner/DinerListImplement/Implements/FoodStorage.cs create mode 100644 Diner/DinerListImplement/Implements/OrderStorage.cs create mode 100644 Diner/DinerListImplement/Implements/SnackStorage.cs create mode 100644 Diner/DinerListImplement/Models/Food.cs create mode 100644 Diner/DinerListImplement/Models/Order.cs create mode 100644 Diner/DinerListImplement/Models/Snack.cs delete mode 100644 Diner/DinerView/Form1.Designer.cs delete mode 100644 Diner/DinerView/Form1.cs create mode 100644 Diner/DinerView/FormCreateOrder.Designer.cs create mode 100644 Diner/DinerView/FormCreateOrder.cs create mode 100644 Diner/DinerView/FormCreateOrder.resx create mode 100644 Diner/DinerView/FormFood.Designer.cs create mode 100644 Diner/DinerView/FormFood.cs create mode 100644 Diner/DinerView/FormFood.resx create mode 100644 Diner/DinerView/FormFoods.Designer.cs create mode 100644 Diner/DinerView/FormFoods.cs create mode 100644 Diner/DinerView/FormFoods.resx create mode 100644 Diner/DinerView/FormMain.Designer.cs create mode 100644 Diner/DinerView/FormMain.cs create mode 100644 Diner/DinerView/FormMain.resx create mode 100644 Diner/DinerView/FormSnack.Designer.cs create mode 100644 Diner/DinerView/FormSnack.cs create mode 100644 Diner/DinerView/FormSnack.resx create mode 100644 Diner/DinerView/FormSnackFood.Designer.cs create mode 100644 Diner/DinerView/FormSnackFood.cs create mode 100644 Diner/DinerView/FormSnackFood.resx create mode 100644 Diner/DinerView/Nlog.config create mode 100644 Diner/DinerView/Properties/Resources.Designer.cs rename Diner/DinerView/{Form1.resx => Properties/Resources.resx} (100%) create mode 100644 Diner/DineryBusinessLogic/BusinessLogic/FoodLogic.cs create mode 100644 Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 Diner/DineryBusinessLogic/BusinessLogic/SnackLogic.cs create mode 100644 Diner/DineryBusinessLogic/DineryBusinessLogic.csproj diff --git a/Diner/Diner.sln b/Diner/Diner.sln index 9636b3a..04f27db 100644 --- a/Diner/Diner.sln +++ b/Diner/Diner.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34221.43 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerView", "DinerView\DinerView.csproj", "{7FC291E6-FE0A-4D25-B46F-724FB599F26F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerView", "DinerView\DinerView.csproj", "{7FC291E6-FE0A-4D25-B46F-724FB599F26F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerDataModels", "DinerDataModels\DinerDataModels.csproj", "{2AFAC265-13C0-432E-8F33-ABF764FD0877}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerContracts", "DinerContracts\DinerContracts.csproj", "{89BA6B4F-1F08-4327-B88B-E48335742088}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerListImplement", "DinerListImplement\DinerListImplement.csproj", "{33BCF269-AF60-4E7E-9F3B-2ECEDCEBF8F9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DineryBusinessLogic", "DineryBusinessLogic\DineryBusinessLogic.csproj", "{2920D9E3-AE18-4914-BD43-C04D9123FBD7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {7FC291E6-FE0A-4D25-B46F-724FB599F26F}.Debug|Any CPU.Build.0 = Debug|Any CPU {7FC291E6-FE0A-4D25-B46F-724FB599F26F}.Release|Any CPU.ActiveCfg = Release|Any CPU {7FC291E6-FE0A-4D25-B46F-724FB599F26F}.Release|Any CPU.Build.0 = Release|Any CPU + {2AFAC265-13C0-432E-8F33-ABF764FD0877}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2AFAC265-13C0-432E-8F33-ABF764FD0877}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AFAC265-13C0-432E-8F33-ABF764FD0877}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2AFAC265-13C0-432E-8F33-ABF764FD0877}.Release|Any CPU.Build.0 = Release|Any CPU + {89BA6B4F-1F08-4327-B88B-E48335742088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89BA6B4F-1F08-4327-B88B-E48335742088}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89BA6B4F-1F08-4327-B88B-E48335742088}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89BA6B4F-1F08-4327-B88B-E48335742088}.Release|Any CPU.Build.0 = Release|Any CPU + {33BCF269-AF60-4E7E-9F3B-2ECEDCEBF8F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33BCF269-AF60-4E7E-9F3B-2ECEDCEBF8F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33BCF269-AF60-4E7E-9F3B-2ECEDCEBF8F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33BCF269-AF60-4E7E-9F3B-2ECEDCEBF8F9}.Release|Any CPU.Build.0 = Release|Any CPU + {2920D9E3-AE18-4914-BD43-C04D9123FBD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2920D9E3-AE18-4914-BD43-C04D9123FBD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2920D9E3-AE18-4914-BD43-C04D9123FBD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2920D9E3-AE18-4914-BD43-C04D9123FBD7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Diner/DinerContracts/BindingModels/FoodBindingModel.cs b/Diner/DinerContracts/BindingModels/FoodBindingModel.cs new file mode 100644 index 0000000..3e207e7 --- /dev/null +++ b/Diner/DinerContracts/BindingModels/FoodBindingModel.cs @@ -0,0 +1,18 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class FoodBindingModel : IFoodModel + { + public string ComponentName { get; set; } = string.Empty; + + public double Price { get; set; } + + public int ID { get; set; } + } +} diff --git a/Diner/DinerContracts/BindingModels/OrderBindingModel.cs b/Diner/DinerContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..30afc15 --- /dev/null +++ b/Diner/DinerContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,27 @@ +using DinerDataModels.Enums; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + 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; } + + public int ID { get; set; } + } +} diff --git a/Diner/DinerContracts/BindingModels/SnackBindingModel.cs b/Diner/DinerContracts/BindingModels/SnackBindingModel.cs new file mode 100644 index 0000000..63a7941 --- /dev/null +++ b/Diner/DinerContracts/BindingModels/SnackBindingModel.cs @@ -0,0 +1,20 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class SnackBindingModel : ISnackModel + { + public string ProductName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary ProductComponents { get; set; } = new(); + + public int ID { get; set; } + } +} diff --git a/Diner/DinerContracts/BusinessLogicsContracts/IFoodLogic.cs b/Diner/DinerContracts/BusinessLogicsContracts/IFoodLogic.cs new file mode 100644 index 0000000..15b3493 --- /dev/null +++ b/Diner/DinerContracts/BusinessLogicsContracts/IFoodLogic.cs @@ -0,0 +1,21 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BusinessLogicsContacts +{ + public interface IFoodLogic + { + List? ReadList(FoodSearchModel? model); + FoodViewModel? ReadElement(FoodSearchModel model); + + bool Create(FoodBindingModel model); + bool Update(FoodBindingModel model); + bool Delete(FoodBindingModel model); + } +} diff --git a/Diner/DinerContracts/BusinessLogicsContracts/IOrderLogic.cs b/Diner/DinerContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..866aca8 --- /dev/null +++ b/Diner/DinerContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,22 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BusinessLogicsContacts +{ + 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/Diner/DinerContracts/BusinessLogicsContracts/ISnackLogic.cs b/Diner/DinerContracts/BusinessLogicsContracts/ISnackLogic.cs new file mode 100644 index 0000000..28fa9c2 --- /dev/null +++ b/Diner/DinerContracts/BusinessLogicsContracts/ISnackLogic.cs @@ -0,0 +1,21 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BusinessLogicsContacts +{ + public interface ISnackLogic + { + List? ReadList(SnackSearchModel? model); + SnackViewModel? ReadElement(SnackSearchModel model); + + bool Create(SnackBindingModel model); + bool Update(SnackBindingModel model); + bool Delete(SnackBindingModel model); + } +} diff --git a/Diner/DinerContracts/DinerContracts.csproj b/Diner/DinerContracts/DinerContracts.csproj new file mode 100644 index 0000000..3cc7782 --- /dev/null +++ b/Diner/DinerContracts/DinerContracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Diner/DinerContracts/SearchModels/FoodSearchModel.cs b/Diner/DinerContracts/SearchModels/FoodSearchModel.cs new file mode 100644 index 0000000..0367d5c --- /dev/null +++ b/Diner/DinerContracts/SearchModels/FoodSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.SearchModels +{ + public class FoodSearchModel + { + public int? ID { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/Diner/DinerContracts/SearchModels/OrderSearchModel.cs b/Diner/DinerContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..4b7490d --- /dev/null +++ b/Diner/DinerContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.SearchModels +{ + public class OrderSearchModel + { + public int? ID { get; set; } + } +} diff --git a/Diner/DinerContracts/SearchModels/SnackSearchModel.cs b/Diner/DinerContracts/SearchModels/SnackSearchModel.cs new file mode 100644 index 0000000..c3aade3 --- /dev/null +++ b/Diner/DinerContracts/SearchModels/SnackSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.SearchModels +{ + public class SnackSearchModel + { + public int? ID { get; set; } + public string? ProductName { get; set; } + } +} diff --git a/Diner/DinerContracts/StoragesContracts/IFoodStorage.cs b/Diner/DinerContracts/StoragesContracts/IFoodStorage.cs new file mode 100644 index 0000000..38ff690 --- /dev/null +++ b/Diner/DinerContracts/StoragesContracts/IFoodStorage.cs @@ -0,0 +1,21 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.StoragesContracts +{ + public interface IFoodStorage + { + List GetFullList(); + List GetFilteredList(FoodSearchModel model); + FoodViewModel? GetElement(FoodSearchModel model); + FoodViewModel? Insert(FoodBindingModel model); + FoodViewModel? Update(FoodBindingModel model); + FoodViewModel? Delete(FoodBindingModel model); + } +} diff --git a/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs b/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..aeab08a --- /dev/null +++ b/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.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/Diner/DinerContracts/StoragesContracts/ISnackStorage.cs b/Diner/DinerContracts/StoragesContracts/ISnackStorage.cs new file mode 100644 index 0000000..71889fb --- /dev/null +++ b/Diner/DinerContracts/StoragesContracts/ISnackStorage.cs @@ -0,0 +1,22 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.StoragesContracts +{ + public interface ISnackStorage + { + List GetFullList(); + List GetFilteredList(SnackSearchModel model); + SnackViewModel? GetElement(SnackSearchModel model); + + SnackViewModel? Insert(SnackBindingModel model); + SnackViewModel? Update(SnackBindingModel model); + SnackViewModel? Delete(SnackBindingModel model); + } +} diff --git a/Diner/DinerContracts/ViewModels/FoodViewModel.cs b/Diner/DinerContracts/ViewModels/FoodViewModel.cs new file mode 100644 index 0000000..d9b7523 --- /dev/null +++ b/Diner/DinerContracts/ViewModels/FoodViewModel.cs @@ -0,0 +1,22 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class FoodViewModel : IFoodModel + { + public int ID { get; set; } + + [DisplayName("Название еды для изготовления")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + } +} diff --git a/Diner/DinerContracts/ViewModels/OrderViewModel.cs b/Diner/DinerContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..8c41385 --- /dev/null +++ b/Diner/DinerContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,38 @@ +using DinerDataModels.Enums; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + public int ProductID { get; set; } + + [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; } + + [DisplayName("Номер")] + public int ID { get; set; } + + [DisplayName("Снэк")] + // какой снэк изготавливается в рамках заказа + public string ProductName { get; set; } = string.Empty; + } +} diff --git a/Diner/DinerContracts/ViewModels/SnackViewModel.cs b/Diner/DinerContracts/ViewModels/SnackViewModel.cs new file mode 100644 index 0000000..7b66741 --- /dev/null +++ b/Diner/DinerContracts/ViewModels/SnackViewModel.cs @@ -0,0 +1,23 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class SnackViewModel : ISnackModel + { + [DisplayName("Название снэка")] + public string ProductName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary ProductComponents { get; set; } = new(); + + public int ID { get; set; } + } +} diff --git a/Diner/DinerDataModels/DinerDataModels.csproj b/Diner/DinerDataModels/DinerDataModels.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/Diner/DinerDataModels/DinerDataModels.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Diner/DinerDataModels/Enums/OrderStatus.cs b/Diner/DinerDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..62a63ba --- /dev/null +++ b/Diner/DinerDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/Diner/DinerDataModels/IID.cs b/Diner/DinerDataModels/IID.cs new file mode 100644 index 0000000..170cbae --- /dev/null +++ b/Diner/DinerDataModels/IID.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels +{ + public interface IID + { + int ID { get; } + } +} diff --git a/Diner/DinerDataModels/Models/IFoodModel.cs b/Diner/DinerDataModels/Models/IFoodModel.cs new file mode 100644 index 0000000..b5e3176 --- /dev/null +++ b/Diner/DinerDataModels/Models/IFoodModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.Models +{ + public interface IFoodModel : IID + { + string ComponentName { get; } + double Price { get; } + } +} diff --git a/Diner/DinerDataModels/Models/IOrderModel.cs b/Diner/DinerDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..d23ef8e --- /dev/null +++ b/Diner/DinerDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using DinerDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.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/Diner/DinerDataModels/Models/ISnackModel.cs b/Diner/DinerDataModels/Models/ISnackModel.cs new file mode 100644 index 0000000..63683d2 --- /dev/null +++ b/Diner/DinerDataModels/Models/ISnackModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.Models +{ + public interface ISnackModel : IID + { + string ProductName { get; } + double Price { get; } + + // словарь для компонент. + // + Dictionary ProductComponents { get; } + + } +} diff --git a/Diner/DinerListImplement/DataListSingleton.cs b/Diner/DinerListImplement/DataListSingleton.cs new file mode 100644 index 0000000..0826264 --- /dev/null +++ b/Diner/DinerListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using DinerListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement +{ + internal class DataListSingleton + { + public static DataListSingleton? _instance; + + public List? Foods { get; set; } + public List? Snacks { get; set; } + public List? Orders { get; set; } + + private DataListSingleton() { + Foods = new List(); + Snacks = new List(); + Orders = new List(); + } + public static DataListSingleton GetInstance() { + if (_instance == null) _instance = new DataListSingleton(); + return _instance; + } + } +} diff --git a/Diner/DinerListImplement/DinerListImplement.csproj b/Diner/DinerListImplement/DinerListImplement.csproj new file mode 100644 index 0000000..cae5b14 --- /dev/null +++ b/Diner/DinerListImplement/DinerListImplement.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/Diner/DinerListImplement/Implements/FoodStorage.cs b/Diner/DinerListImplement/Implements/FoodStorage.cs new file mode 100644 index 0000000..11bf656 --- /dev/null +++ b/Diner/DinerListImplement/Implements/FoodStorage.cs @@ -0,0 +1,98 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using DinerListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Implements +{ + public class FoodStorage : IFoodStorage + { + private readonly DataListSingleton _source; + + public FoodStorage() { + _source = DataListSingleton.GetInstance(); + } + + public FoodViewModel? Delete(FoodBindingModel model) + { + for (int i = 0; i < _source.Foods.Count; ++i) { + if (_source.Foods[i].ID == model.ID) { + var element = _source.Foods[i]; + _source.Foods.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public FoodViewModel? GetElement(FoodSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.ID.HasValue) { + return null; + } + foreach (var component in _source.Foods) { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.ID.HasValue && component.ID == model.ID)) { + return component.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(FoodSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) { + return result; + } + foreach (var component in _source.Foods) { + if (component.ComponentName.Contains(model.ComponentName)) { + result.Add(component.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Foods) { + result.Add(component.GetViewModel); + } + return result; + } + + public FoodViewModel? Insert(FoodBindingModel model) + { + model.ID = 1; + foreach (var component in _source.Foods) { + if (model.ID <= component.ID) { + model.ID = component.ID + 1; + } + } + var newComponent = Food.Create(model); + if (newComponent == null) return null; + _source.Foods.Add(newComponent); + return newComponent.GetViewModel; + } + + public FoodViewModel? Update(FoodBindingModel model) + { + foreach (var component in _source.Foods) { + if (component.ID == model.ID) { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + } +} diff --git a/Diner/DinerListImplement/Implements/OrderStorage.cs b/Diner/DinerListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..b35564b --- /dev/null +++ b/Diner/DinerListImplement/Implements/OrderStorage.cs @@ -0,0 +1,91 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using DinerListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() { + _source = DataListSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) { + if (_source.Orders[i].ID == model.ID) { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public OrderViewModel GetElement(OrderSearchModel model) + { + if (!model.ID.HasValue) return null; + foreach (var order in _source.Orders) { + if (model.ID.HasValue && order.ID == model.ID) { + return order.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.ID.HasValue) return result; + foreach (var order in _source.Orders) { + if (order.ID == model.ID) { + result.Add(order.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) { + result.Add(order.GetViewModel); + } + return result; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.ID = 1; + foreach (var order in _source.Orders) { + if (model.ID <= order.ID) { + model.ID = order.ID + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) return null; + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) { + if (order.ID == model.ID) { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + } +} diff --git a/Diner/DinerListImplement/Implements/SnackStorage.cs b/Diner/DinerListImplement/Implements/SnackStorage.cs new file mode 100644 index 0000000..fd50138 --- /dev/null +++ b/Diner/DinerListImplement/Implements/SnackStorage.cs @@ -0,0 +1,97 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using DinerListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Implements +{ + public class SnackStorage : ISnackStorage + { + private readonly DataListSingleton _source; + + public SnackStorage() { + _source = DataListSingleton.GetInstance(); + } + + public SnackViewModel? Delete(SnackBindingModel model) + { + for (int i = 0; i < _source.Snacks.Count; ++i) { + if (_source.Snacks[i].ID == model.ID) { + var element = _source.Snacks[i]; + _source.Snacks.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public SnackViewModel? GetElement(SnackSearchModel model) + { + if (string.IsNullOrEmpty(model.ProductName) && !model.ID.HasValue) { + return null; + } + foreach (var product in _source.Snacks) { + if ((!string.IsNullOrEmpty(model.ProductName) && + product.ProductName == model.ProductName) || + (model.ID.HasValue && product.ID == model.ID)) { + return product.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(SnackSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ProductName)) { + return result; + } + foreach (var product in _source.Snacks) { + if (product.ProductName.Contains(model.ProductName)) { + result.Add(product.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var product in _source.Snacks) { + result.Add(product.GetViewModel); + } + return result; + } + + public SnackViewModel? Insert(SnackBindingModel model) + { + model.ID = 1; + foreach (var product in _source.Snacks) { + if (model.ID <= product.ID) { + model.ID = product.ID + 1; + } + } + var newProduct = Snack.Create(model); + if (newProduct == null) return null; + _source.Snacks.Add(newProduct); + return newProduct.GetViewModel; + } + + public SnackViewModel? Update(SnackBindingModel model) + { + foreach (var product in _source.Snacks) { + if (product.ID == model.ID) { + product.Update(model); + return product.GetViewModel; + } + } + return null; + } + } +} diff --git a/Diner/DinerListImplement/Models/Food.cs b/Diner/DinerListImplement/Models/Food.cs new file mode 100644 index 0000000..074ba20 --- /dev/null +++ b/Diner/DinerListImplement/Models/Food.cs @@ -0,0 +1,39 @@ +using DinerContracts.BindingModels; +using DinerContracts.ViewModels; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Models +{ + internal class Food : IFoodModel + { + public string ComponentName { get; private set; } = string.Empty; + + public double Price { get; set; } + + public int ID { get; private set; } + + public static Food? Create(FoodBindingModel? model) { + if (model == null) return null; + return new Food() { + ID = model.ID, + ComponentName = model.ComponentName, + Price = model.Price, + }; + } + public void Update(FoodBindingModel? model) { + if (model == null) return; + ComponentName = model.ComponentName; + Price = model.Price; + } + public FoodViewModel GetViewModel => new(){ + ID = ID, + ComponentName = ComponentName, + Price = Price, + }; + } +} diff --git a/Diner/DinerListImplement/Models/Order.cs b/Diner/DinerListImplement/Models/Order.cs new file mode 100644 index 0000000..0eb0df6 --- /dev/null +++ b/Diner/DinerListImplement/Models/Order.cs @@ -0,0 +1,60 @@ +using DinerContracts.BindingModels; +using DinerContracts.ViewModels; +using DinerDataModels.Enums; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Models +{ + internal class Order : IOrderModel + { + public int ProductID { get; private set; } + + public int Count { get; set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; set; } + + public int ID { get; private set; } + + public static Order? Create(OrderBindingModel? model) { + if (model == null) return null; + return new Order() + { + ID = model.ID, + ProductID = model.ProductID, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) { + if (model == null) return; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateImplement = model?.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + ID = ID, + ProductID = ProductID, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/Diner/DinerListImplement/Models/Snack.cs b/Diner/DinerListImplement/Models/Snack.cs new file mode 100644 index 0000000..3e3d43d --- /dev/null +++ b/Diner/DinerListImplement/Models/Snack.cs @@ -0,0 +1,46 @@ +using DinerContracts.BindingModels; +using DinerContracts.ViewModels; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Models +{ + internal class Snack : ISnackModel + { + public string ProductName { get; private set; } = String.Empty; + + public double Price { get; private set; } + + public Dictionary ProductComponents { get; private set; } = + new Dictionary(); + + public int ID { get; private set; } + + public static Snack? Create(SnackBindingModel? model) { + if (model == null) return null; + return new Snack() { + ID = model.ID, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(SnackBindingModel? model) { + if (model == null) return; + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public SnackViewModel GetViewModel => new() + { + ID = ID, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + } +} diff --git a/Diner/DinerView/DinerView.csproj b/Diner/DinerView/DinerView.csproj index b57c89e..1c0790c 100644 --- a/Diner/DinerView/DinerView.csproj +++ b/Diner/DinerView/DinerView.csproj @@ -2,10 +2,48 @@ WinExe - net6.0-windows + net8.0-windows7.0 enable true enable + + + + + + + Always + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/Diner/DinerView/Form1.Designer.cs b/Diner/DinerView/Form1.Designer.cs deleted file mode 100644 index 1bb9301..0000000 --- a/Diner/DinerView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace DinerView -{ - 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/Diner/DinerView/Form1.cs b/Diner/DinerView/Form1.cs deleted file mode 100644 index 3789d26..0000000 --- a/Diner/DinerView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DinerView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Diner/DinerView/FormCreateOrder.Designer.cs b/Diner/DinerView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..65c70ed --- /dev/null +++ b/Diner/DinerView/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace DinerView +{ + 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() + { + labelProduct = new Label(); + comboBoxProduct = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + label1 = new Label(); + textBoxSum = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelProduct + // + labelProduct.AutoSize = true; + labelProduct.Location = new Point(12, 9); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(37, 15); + labelProduct.TabIndex = 0; + labelProduct.Text = "Cнэк:"; + // + // comboBoxProduct + // + comboBoxProduct.BackColor = SystemColors.ButtonShadow; + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(93, 6); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(289, 23); + comboBoxProduct.TabIndex = 3; + comboBoxProduct.SelectedIndexChanged += comboBoxProduct_SelectedIndexChanged; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 37); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 4; + labelCount.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(93, 34); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(289, 23); + textBoxCount.TabIndex = 5; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 66); + label1.Name = "label1"; + label1.Size = new Size(48, 15); + label1.TabIndex = 6; + label1.Text = "Сумма:"; + // + // textBoxSum + // + textBoxSum.Location = new Point(93, 63); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(289, 23); + textBoxSum.TabIndex = 7; + // + // buttonCancel + // + buttonCancel.Location = new Point(307, 92); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(226, 92); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(394, 122); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxSum); + Controls.Add(label1); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxProduct); + Controls.Add(labelProduct); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelProduct; + private ComboBox comboBoxProduct; + private Label labelCount; + private TextBox textBoxCount; + private Label label1; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormCreateOrder.cs b/Diner/DinerView/FormCreateOrder.cs new file mode 100644 index 0000000..fdb9ebc --- /dev/null +++ b/Diner/DinerView/FormCreateOrder.cs @@ -0,0 +1,120 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.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 DinerView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISnackLogic _logicSnack; + private readonly IOrderLogic _logicOrder; + + public FormCreateOrder(ILogger logger, ISnackLogic logicSnack, IOrderLogic logicOrder) + { + InitializeComponent(); + _logger = logger; + _logicSnack = logicSnack; + _logicOrder = logicOrder; + } + + private void CalcSum() + { + if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxProduct.SelectedValue); + var product = _logicSnack.ReadElement(new SnackSearchModel { ID = id }); + int count = Convert.ToInt32(textBoxCount.Text); + _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 (comboBoxProduct.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicOrder.CreateOrder(new OrderBindingModel + { + ProductID = Convert.ToInt32(comboBoxProduct.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(); + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка Снэков"); + try + { + var list = _logicSnack.ReadList(null); + if (list != null) + { + comboBoxProduct.DisplayMember = "SnackName"; + comboBoxProduct.ValueMember = "ID"; + comboBoxProduct.DataSource = list; + comboBoxProduct.SelectedItem = null; + } + } + catch (Exception ex) { + _logger.LogError(ex, "Ошибка загрузки списка снэков"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Diner/DinerView/FormCreateOrder.resx b/Diner/DinerView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/DinerView/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/DinerView/FormFood.Designer.cs b/Diner/DinerView/FormFood.Designer.cs new file mode 100644 index 0000000..b103b0e --- /dev/null +++ b/Diner/DinerView/FormFood.Designer.cs @@ -0,0 +1,118 @@ +namespace DinerView +{ + partial class FormFood + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 38); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(77, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(305, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(77, 38); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(305, 23); + textBoxPrice.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(307, 67); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(226, 67); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormFood + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(394, 101); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormFood"; + Text = "Food"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormFood.cs b/Diner/DinerView/FormFood.cs new file mode 100644 index 0000000..5a4e2ec --- /dev/null +++ b/Diner/DinerView/FormFood.cs @@ -0,0 +1,89 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.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 DinerView +{ + public partial class FormFood : Form + { + private readonly ILogger _logger; + private readonly IFoodLogic _logic; + private int? _ID; + public int ID { set { _ID = value; } } + + public FormFood(ILogger logger, IFoodLogic 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 FoodSearchModel { ID = _ID.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxPrice.Text = view.Price.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 FoodBindingModel + { + ID = _ID ?? 0, + ComponentName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.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/Diner/DinerView/FormFood.resx b/Diner/DinerView/FormFood.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/DinerView/FormFood.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/DinerView/FormFoods.Designer.cs b/Diner/DinerView/FormFoods.Designer.cs new file mode 100644 index 0000000..abaac85 --- /dev/null +++ b/Diner/DinerView/FormFoods.Designer.cs @@ -0,0 +1,122 @@ +namespace DinerView +{ + partial class FormFoods + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonRemove = new Button(); + buttonUpdate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.BorderStyle = BorderStyle.None; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(563, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(578, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(219, 41); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(578, 59); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(219, 41); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(578, 106); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(219, 41); + buttonRemove.TabIndex = 3; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(578, 153); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(219, 41); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = SystemColors.ScrollBar; + ClientSize = new Size(800, 450); + Controls.Add(buttonUpdate); + Controls.Add(buttonRemove); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Foods"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonRemove; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormFoods.cs b/Diner/DinerView/FormFoods.cs new file mode 100644 index 0000000..b780e0e --- /dev/null +++ b/Diner/DinerView/FormFoods.cs @@ -0,0 +1,109 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +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 DinerView +{ + public partial class FormFoods : Form + { + private readonly ILogger _logger; + private readonly IFoodLogic _logic; + + public FormFoods(ILogger logger, IFoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + 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) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFood)); + if (service is FormFood form) + { + form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); + if (form.ShowDialog() == DialogResult.OK) LoadData(); + } + } + } + + private void buttonRemove_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 FoodBindingModel { ID = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления продукта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFood)); + if (service is FormFood form) + { + form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); + if (form.ShowDialog() == DialogResult.OK) LoadData(); + } + } + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Diner/DinerView/FormFoods.resx b/Diner/DinerView/FormFoods.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/DinerView/FormFoods.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/DinerView/FormMain.Designer.cs b/Diner/DinerView/FormMain.Designer.cs new file mode 100644 index 0000000..0d2183c --- /dev/null +++ b/Diner/DinerView/FormMain.Designer.cs @@ -0,0 +1,174 @@ +namespace DinerView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + toolStripMenuItemMenu = new ToolStripMenuItem(); + toolStripMenuItemFoods = new ToolStripMenuItem(); + toolStripMenuItemSnacks = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonInWork = new Button(); + buttonIsReady = new Button(); + buttonIsDelivery = new Button(); + buttonUpdateList = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.BackColor = SystemColors.Control; + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItemMenu }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1019, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "Справочник"; + // + // toolStripMenuItemMenu + // + toolStripMenuItemMenu.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemFoods, toolStripMenuItemSnacks }); + toolStripMenuItemMenu.Name = "toolStripMenuItemMenu"; + toolStripMenuItemMenu.Size = new Size(94, 20); + toolStripMenuItemMenu.Text = "Справочники"; + // + // toolStripMenuItemFoods + // + toolStripMenuItemFoods.Name = "toolStripMenuItemFoods"; + toolStripMenuItemFoods.Size = new Size(129, 22); + toolStripMenuItemFoods.Text = "Продукты"; + toolStripMenuItemFoods.Click += toolStripMenuItemFoods_Click; + // + // toolStripMenuItemSnacks + // + toolStripMenuItemSnacks.Name = "toolStripMenuItemSnacks"; + toolStripMenuItemSnacks.Size = new Size(129, 22); + toolStripMenuItemSnacks.Text = "Снэки"; + toolStripMenuItemSnacks.Click += toolStripMenuItemSnacks_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.BorderStyle = BorderStyle.None; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 24); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(789, 426); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(795, 36); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(212, 39); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonInWork + // + buttonInWork.Location = new Point(795, 81); + buttonInWork.Name = "buttonInWork"; + buttonInWork.Size = new Size(212, 39); + buttonInWork.TabIndex = 3; + buttonInWork.Text = "Отдать не выполнение"; + buttonInWork.UseVisualStyleBackColor = true; + buttonInWork.Click += buttonInWork_Click; + // + // buttonIsReady + // + buttonIsReady.Location = new Point(795, 126); + buttonIsReady.Name = "buttonIsReady"; + buttonIsReady.Size = new Size(212, 39); + buttonIsReady.TabIndex = 4; + buttonIsReady.Text = "Заказ готов"; + buttonIsReady.UseVisualStyleBackColor = true; + buttonIsReady.Click += buttonIsReady_Click; + // + // buttonIsDelivery + // + buttonIsDelivery.Location = new Point(795, 171); + buttonIsDelivery.Name = "buttonIsDelivery"; + buttonIsDelivery.Size = new Size(212, 39); + buttonIsDelivery.TabIndex = 5; + buttonIsDelivery.Text = "Заказ выдан"; + buttonIsDelivery.UseVisualStyleBackColor = true; + buttonIsDelivery.Click += buttonIsDelivery_Click; + // + // buttonUpdateList + // + buttonUpdateList.Location = new Point(795, 216); + buttonUpdateList.Name = "buttonUpdateList"; + buttonUpdateList.Size = new Size(212, 39); + buttonUpdateList.TabIndex = 6; + buttonUpdateList.Text = "Обновить список"; + buttonUpdateList.UseVisualStyleBackColor = true; + buttonUpdateList.Click += buttonUpdateList_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = SystemColors.ScrollBar; + ClientSize = new Size(1019, 450); + Controls.Add(buttonUpdateList); + Controls.Add(buttonIsDelivery); + Controls.Add(buttonIsReady); + Controls.Add(buttonInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem toolStripMenuItemMenu; + private DataGridView dataGridView; + private ToolStripMenuItem toolStripMenuItemFoods; + private ToolStripMenuItem toolStripMenuItemSnacks; + private Button buttonCreateOrder; + private Button buttonInWork; + private Button buttonIsReady; + private Button buttonIsDelivery; + private Button buttonUpdateList; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormMain.cs b/Diner/DinerView/FormMain.cs new file mode 100644 index 0000000..da07e29 --- /dev/null +++ b/Diner/DinerView/FormMain.cs @@ -0,0 +1,156 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DinerView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ProductID"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void toolStripMenuItemFoods_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFoods)); + if (service is FormFoods form) { + form.ShowDialog(); + LoadData(); + } + } + + private void toolStripMenuItemSnacks_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSnack)); + if (service is FormSnack form) { + form.ShowDialog(); + LoadData(); + } + } + + 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 buttonInWork_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 buttonIsReady_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 buttonIsDelivery_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 buttonUpdateList_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Diner/DinerView/FormMain.resx b/Diner/DinerView/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/Diner/DinerView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Diner/DinerView/FormSnack.Designer.cs b/Diner/DinerView/FormSnack.Designer.cs new file mode 100644 index 0000000..2069a27 --- /dev/null +++ b/Diner/DinerView/FormSnack.Designer.cs @@ -0,0 +1,241 @@ +namespace DinerView +{ + partial class FormSnack + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxFoods = new GroupBox(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnFood = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ColumnID = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBoxFoods.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 36); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(85, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(367, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(85, 36); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(367, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxFoods + // + groupBoxFoods.BackColor = SystemColors.ControlDark; + groupBoxFoods.Controls.Add(buttonUpdate); + groupBoxFoods.Controls.Add(buttonRemove); + groupBoxFoods.Controls.Add(buttonChange); + groupBoxFoods.Controls.Add(buttonAdd); + groupBoxFoods.Controls.Add(dataGridView); + groupBoxFoods.ForeColor = SystemColors.Control; + groupBoxFoods.Location = new Point(12, 65); + groupBoxFoods.Name = "groupBoxFoods"; + groupBoxFoods.Size = new Size(657, 373); + groupBoxFoods.TabIndex = 4; + groupBoxFoods.TabStop = false; + groupBoxFoods.Text = "Foods"; + // + // buttonUpdate + // + buttonUpdate.ForeColor = Color.Black; + buttonUpdate.Location = new Point(446, 148); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(205, 37); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonRemove + // + buttonRemove.ForeColor = Color.Black; + buttonRemove.Location = new Point(446, 105); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(205, 37); + buttonRemove.TabIndex = 3; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonChange + // + buttonChange.ForeColor = Color.Black; + buttonChange.Location = new Point(446, 62); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(205, 37); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonAdd + // + buttonAdd.ForeColor = Color.Black; + buttonAdd.Location = new Point(446, 19); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(205, 37); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ButtonFace; + dataGridView.BorderStyle = BorderStyle.None; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnFood, ColumnCount, ColumnID }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(3, 19); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 22; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(437, 351); + dataGridView.TabIndex = 0; + // + // ColumnFood + // + ColumnFood.HeaderText = "Food"; + ColumnFood.Name = "ColumnFood"; + ColumnFood.ReadOnly = true; + ColumnFood.Width = 337; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.Name = "ColumnID"; + ColumnID.ReadOnly = true; + ColumnID.Visible = false; + // + // buttonCancel + // + buttonCancel.Location = new Point(587, 30); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 27); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(499, 30); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(82, 27); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormSnack + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(681, 450); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBoxFoods); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormSnack"; + Text = "Snack"; + Load += FormSnack_Load; + groupBoxFoods.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxFoods; + private DataGridView dataGridView; + private Button buttonChange; + private Button buttonAdd; + private DataGridViewTextBoxColumn ColumnFood; + private DataGridViewTextBoxColumn ColumnCount; + private DataGridViewTextBoxColumn ColumnID; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormSnack.cs b/Diner/DinerView/FormSnack.cs new file mode 100644 index 0000000..917ca54 --- /dev/null +++ b/Diner/DinerView/FormSnack.cs @@ -0,0 +1,203 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.SearchModels; +using DinerDataModels.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.Security.Cryptography.Xml; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DinerView +{ + public partial class FormSnack : Form + { + private readonly ILogger _logger; + private readonly ISnackLogic _logic; + private int? _ID; + private Dictionary _productComponents; + public int ID { set { _ID = value; } } + public FormSnack(ILogger logger, ISnackLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _productComponents = new Dictionary(); + } + + private void FormSnack_Load(object sender, EventArgs e) + { + if (_ID.HasValue) + { + _logger.LogInformation("Загрузка снэка"); + try + { + var view = _logic.ReadElement(new SnackSearchModel { ID = _ID.Value }); + if (view != null) + { + textBoxName.Text = view.ProductName; + textBoxPrice.Text = view.Price.ToString(); + _productComponents = view.ProductComponents ?? 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 elem in _productComponents) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ComponentName, elem.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки продукта снэка"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _productComponents) + price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2); + return Math.Round(price * 1.1, 2); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSnackFood)); + if (service is FormSnackFood form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.foodModel == null) return; + _logger.LogInformation("Добавление нового снэка: {ComponentName} - {Count}", form.foodModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.ID)) + { + _productComponents[form.ID] = (form.foodModel, form.Count); + } + else + { + _productComponents.Add(form.ID, (form.foodModel, form.Count)); + } + LoadData(); + } + } + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSnackFood)); + if (service is FormSnackFood 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.foodModel == null) return; + _logger.LogInformation("Изменение снэка: {ComponentName} - {Count}", form.foodModel.ComponentName, form.Count); + _productComponents[form.ID] = (form.foodModel, form.Count); + LoadData(); + } + } + } + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление снэка: {ComponentName}", 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 buttonUpdate_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 SnackBindingModel + { + ID = _ID ?? 0, + ProductName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ProductComponents = _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(); + } + } +} diff --git a/Diner/DinerView/FormSnack.resx b/Diner/DinerView/FormSnack.resx new file mode 100644 index 0000000..d84b5d1 --- /dev/null +++ b/Diner/DinerView/FormSnack.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Diner/DinerView/FormSnackFood.Designer.cs b/Diner/DinerView/FormSnackFood.Designer.cs new file mode 100644 index 0000000..93309e0 --- /dev/null +++ b/Diner/DinerView/FormSnackFood.Designer.cs @@ -0,0 +1,120 @@ +namespace DinerView +{ + partial class FormSnackFood + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(28, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Еда:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 35); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(77, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количесиво:"; + // + // comboBoxComponent + // + comboBoxComponent.BackColor = SystemColors.ButtonShadow; + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(91, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(291, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(91, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(291, 23); + textBoxCount.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(307, 64); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(226, 66); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormSnackFood + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(394, 101); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormSnackFood"; + Text = "Snack food"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormSnackFood.cs b/Diner/DinerView/FormSnackFood.cs new file mode 100644 index 0000000..6ca4a12 --- /dev/null +++ b/Diner/DinerView/FormSnackFood.cs @@ -0,0 +1,89 @@ +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.ViewModels; +using DinerDataModels.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 DinerView +{ + public partial class FormSnackFood : Form + { + private readonly List? _list; + public int ID + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IFoodModel? foodModel + { + 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 FormSnackFood(IFoodLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "FoodName"; + 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/Diner/DinerView/FormSnackFood.resx b/Diner/DinerView/FormSnackFood.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/DinerView/FormSnackFood.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/DinerView/Nlog.config b/Diner/DinerView/Nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/Diner/DinerView/Nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Diner/DinerView/Program.cs b/Diner/DinerView/Program.cs index 44e822d..17fe7e5 100644 --- a/Diner/DinerView/Program.cs +++ b/Diner/DinerView/Program.cs @@ -1,7 +1,17 @@ +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.StoragesContracts; +using DinerListImplement.Implements; +using DineryBusinessLogic.BusinessLogic; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace DinerView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +21,33 @@ namespace DinerView // 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(); } } } \ No newline at end of file diff --git a/Diner/DinerView/Properties/Resources.Designer.cs b/Diner/DinerView/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c751ab2 --- /dev/null +++ b/Diner/DinerView/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace DinerView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DinerView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Diner/DinerView/Form1.resx b/Diner/DinerView/Properties/Resources.resx similarity index 100% rename from Diner/DinerView/Form1.resx rename to Diner/DinerView/Properties/Resources.resx diff --git a/Diner/DineryBusinessLogic/BusinessLogic/FoodLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/FoodLogic.cs new file mode 100644 index 0000000..307e3be --- /dev/null +++ b/Diner/DineryBusinessLogic/BusinessLogic/FoodLogic.cs @@ -0,0 +1,96 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.BusinessLogic +{ + public class FoodLogic : IFoodLogic + { + private readonly ILogger _logger; + private readonly IFoodStorage _componentStorage; + + public FoodLogic(ILogger logger, IFoodStorage componentStorage) { + _logger = logger; + _componentStorage = componentStorage; + } + + public bool Create(FoodBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(FoodBindingModel 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; + } + + public FoodViewModel? ReadElement(FoodSearchModel 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 List? ReadList(FoodSearchModel? 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 bool Update(FoodBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(FoodBindingModel 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.Price <= 0) + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price)); + _logger.LogInformation("Component. ComponentName:{ComponentName}. Price:{Price}. ID:{ID}", + model.ComponentName, model.Price, model.ID); + var element = _componentStorage.GetElement(new FoodSearchModel { ComponentName = model.ComponentName }); + if (element != null && element.ID != model.ID) + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } +} diff --git a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..032e0b0 --- /dev/null +++ b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,89 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using DinerDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. ID:{ID}", model?.ID); + var list= model == null? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) { + if (model == null) throw new ArgumentNullException(nameof(model)); + if (!withParams) return; + if (string.IsNullOrEmpty((model.ID).ToString())) + throw new ArgumentNullException("Нет ID заказа", nameof(model.ID)); + if (model.Sum <= 0) + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + _logger.LogInformation("Order. ProductID:{ProductID}. Count:{Count}. Sum:{Sum}. Status:{Status}. " + + "DateCreate:{DateCreate}. DateImplement:{DateImplement}. ID:{ID}", + model.ProductID, model.Count, model.Sum, model.Status, model.DateCreate, model.DateImplement, model.ID); + var element = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); + if (element == null) + throw new InvalidOperationException("Нет такого заказа"); + } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { + CheckModel(model, false); + + if (model.Status + 1 != newOrderStatus) { + _logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed."); + return false; + } + model.Status = newOrderStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + return true; + } + } +} diff --git a/Diner/DineryBusinessLogic/BusinessLogic/SnackLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/SnackLogic.cs new file mode 100644 index 0000000..db9a8bc --- /dev/null +++ b/Diner/DineryBusinessLogic/BusinessLogic/SnackLogic.cs @@ -0,0 +1,95 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.BusinessLogic +{ + public class SnackLogic : ISnackLogic + { + private readonly ILogger _logger; + private readonly ISnackStorage _productStorage; + + public SnackLogic(ILogger logger, ISnackStorage productStorage) { + _logger = logger; + _productStorage = productStorage; + } + + public bool Create(SnackBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(SnackBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. ID:{ID}", model.ID); + if (_productStorage.Delete(model) == null) { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public SnackViewModel? ReadElement(SnackSearchModel model) + { + if (model == null) throw new ArgumentNullException(nameof(model)); + _logger.LogInformation("ReadElement. ProductName:{ProductName}. ID:{ID}", model.ProductName, model.ID); + var element = _productStorage.GetElement(model); + if (element == null) { + _logger.LogWarning("ReadElement. elementn not found"); + return null; + } + _logger.LogInformation("ReadElement find. ID:{ID}", element.ID); + return element; + } + + public List? ReadList(SnackSearchModel? model) + { + _logger.LogInformation("ReadList. ProductName:{ProductName}. ID:{ID}", model?.ProductName, model?.ID); + var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + if (list == null) { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(SnackBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(SnackBindingModel model, bool withParams = true) { + if (model == null) throw new ArgumentNullException(nameof(model)); + if (!withParams) return; + if (string.IsNullOrEmpty(model.ProductName)) + throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); + if (model.Price <= 0) + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + _logger.LogInformation("Product. ProductName:{ProductName}. Price:{Price}. ID:{ID}", + model.ProductName, model.Price, model.Price); + var element = _productStorage.GetElement(new SnackSearchModel { ProductName = model.ProductName }); + if (element != null && element.ID != model.ID) + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } +} diff --git a/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj b/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj new file mode 100644 index 0000000..6c5b7ff --- /dev/null +++ b/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + -- 2.25.1 From e04c4a3165d5f4f0172520098b1da85738551dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 25 Feb 2024 16:50:29 +0400 Subject: [PATCH 2/6] Base.02 --- Diner/DinerView/FormCreateOrder.cs | 7 +++-- Diner/DinerView/FormFoods.cs | 11 +++----- Diner/DinerView/FormMain.Designer.cs | 26 ++++++++++++------- Diner/DinerView/FormSnack.Designer.cs | 25 +++++++++--------- Diner/DinerView/FormSnack.resx | 6 ++--- Diner/DinerView/FormSnackFood.cs | 2 +- .../BusinessLogic/OrderLogic.cs | 13 +++++++--- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/Diner/DinerView/FormCreateOrder.cs b/Diner/DinerView/FormCreateOrder.cs index fdb9ebc..ab0d45c 100644 --- a/Diner/DinerView/FormCreateOrder.cs +++ b/Diner/DinerView/FormCreateOrder.cs @@ -1,6 +1,7 @@ using DinerContracts.BindingModels; using DinerContracts.BusinessLogicsContacts; using DinerContracts.SearchModels; +using DinerDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -37,6 +38,7 @@ namespace DinerView int id = Convert.ToInt32(comboBoxProduct.SelectedValue); var product = _logicSnack.ReadElement(new SnackSearchModel { ID = id }); int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) @@ -77,7 +79,8 @@ namespace DinerView { ProductID = Convert.ToInt32(comboBoxProduct.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + }); if (!operationResult) throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -105,7 +108,7 @@ namespace DinerView var list = _logicSnack.ReadList(null); if (list != null) { - comboBoxProduct.DisplayMember = "SnackName"; + comboBoxProduct.DisplayMember = "ProductName"; comboBoxProduct.ValueMember = "ID"; comboBoxProduct.DataSource = list; comboBoxProduct.SelectedItem = null; diff --git a/Diner/DinerView/FormFoods.cs b/Diner/DinerView/FormFoods.cs index b780e0e..0ce206a 100644 --- a/Diner/DinerView/FormFoods.cs +++ b/Diner/DinerView/FormFoods.cs @@ -47,14 +47,9 @@ namespace DinerView private void buttonAdd_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormFood)); - if (service is FormFood form) - { - form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); - if (form.ShowDialog() == DialogResult.OK) LoadData(); - } + var service = Program.ServiceProvider?.GetService(typeof(FormFood)); + if (service is FormFood form) { + if (form.ShowDialog() == DialogResult.OK) LoadData(); } } diff --git a/Diner/DinerView/FormMain.Designer.cs b/Diner/DinerView/FormMain.Designer.cs index 0d2183c..f90cca1 100644 --- a/Diner/DinerView/FormMain.Designer.cs +++ b/Diner/DinerView/FormMain.Designer.cs @@ -48,7 +48,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItemMenu }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1019, 24); + menuStrip.Size = new Size(951, 24); menuStrip.TabIndex = 0; menuStrip.Text = "Справочник"; // @@ -75,18 +75,24 @@ // // dataGridView // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.BackgroundColor = SystemColors.Control; dataGridView.BorderStyle = BorderStyle.None; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 24); + dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; - dataGridView.Size = new Size(789, 426); - dataGridView.TabIndex = 1; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(726, 426); + dataGridView.TabIndex = 0; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(795, 36); + buttonCreateOrder.Location = new Point(732, 36); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(212, 39); buttonCreateOrder.TabIndex = 2; @@ -96,7 +102,7 @@ // // buttonInWork // - buttonInWork.Location = new Point(795, 81); + buttonInWork.Location = new Point(732, 81); buttonInWork.Name = "buttonInWork"; buttonInWork.Size = new Size(212, 39); buttonInWork.TabIndex = 3; @@ -106,7 +112,7 @@ // // buttonIsReady // - buttonIsReady.Location = new Point(795, 126); + buttonIsReady.Location = new Point(732, 126); buttonIsReady.Name = "buttonIsReady"; buttonIsReady.Size = new Size(212, 39); buttonIsReady.TabIndex = 4; @@ -116,7 +122,7 @@ // // buttonIsDelivery // - buttonIsDelivery.Location = new Point(795, 171); + buttonIsDelivery.Location = new Point(732, 171); buttonIsDelivery.Name = "buttonIsDelivery"; buttonIsDelivery.Size = new Size(212, 39); buttonIsDelivery.TabIndex = 5; @@ -126,7 +132,7 @@ // // buttonUpdateList // - buttonUpdateList.Location = new Point(795, 216); + buttonUpdateList.Location = new Point(732, 216); buttonUpdateList.Name = "buttonUpdateList"; buttonUpdateList.Size = new Size(212, 39); buttonUpdateList.TabIndex = 6; @@ -139,7 +145,7 @@ AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; BackColor = SystemColors.ScrollBar; - ClientSize = new Size(1019, 450); + ClientSize = new Size(951, 450); Controls.Add(buttonUpdateList); Controls.Add(buttonIsDelivery); Controls.Add(buttonIsReady); diff --git a/Diner/DinerView/FormSnack.Designer.cs b/Diner/DinerView/FormSnack.Designer.cs index 2069a27..320031c 100644 --- a/Diner/DinerView/FormSnack.Designer.cs +++ b/Diner/DinerView/FormSnack.Designer.cs @@ -38,9 +38,9 @@ buttonChange = new Button(); buttonAdd = new Button(); dataGridView = new DataGridView(); + ColumnID = new DataGridViewTextBoxColumn(); ColumnFood = new DataGridViewTextBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); - ColumnID = new DataGridViewTextBoxColumn(); buttonCancel = new Button(); buttonSave = new Button(); groupBoxFoods.SuspendLayout(); @@ -147,18 +147,26 @@ dataGridView.BackgroundColor = SystemColors.ButtonFace; dataGridView.BorderStyle = BorderStyle.None; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnFood, ColumnCount, ColumnID }); + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnFood, ColumnCount }); dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(3, 19); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.DefaultCellStyle.ForeColor = Color.Black; dataGridView.RowTemplate.Height = 22; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.Size = new Size(437, 351); dataGridView.TabIndex = 0; // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.Name = "ColumnID"; + ColumnID.ReadOnly = true; + ColumnID.Visible = false; + // // ColumnFood // ColumnFood.HeaderText = "Food"; @@ -172,13 +180,6 @@ ColumnCount.Name = "ColumnCount"; ColumnCount.ReadOnly = true; // - // ColumnID - // - ColumnID.HeaderText = "ID"; - ColumnID.Name = "ColumnID"; - ColumnID.ReadOnly = true; - ColumnID.Visible = false; - // // buttonCancel // buttonCancel.Location = new Point(587, 30); @@ -230,12 +231,12 @@ private DataGridView dataGridView; private Button buttonChange; private Button buttonAdd; - private DataGridViewTextBoxColumn ColumnFood; - private DataGridViewTextBoxColumn ColumnCount; - private DataGridViewTextBoxColumn ColumnID; private Button buttonUpdate; private Button buttonRemove; private Button buttonCancel; private Button buttonSave; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnFood; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/Diner/DinerView/FormSnack.resx b/Diner/DinerView/FormSnack.resx index d84b5d1..e97a008 100644 --- a/Diner/DinerView/FormSnack.resx +++ b/Diner/DinerView/FormSnack.resx @@ -117,13 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + True True - - True - \ No newline at end of file diff --git a/Diner/DinerView/FormSnackFood.cs b/Diner/DinerView/FormSnackFood.cs index 6ca4a12..fe603ca 100644 --- a/Diner/DinerView/FormSnackFood.cs +++ b/Diner/DinerView/FormSnackFood.cs @@ -57,7 +57,7 @@ namespace DinerView _list = logic.ReadList(null); if (_list != null) { - comboBoxComponent.DisplayMember = "FoodName"; + comboBoxComponent.DisplayMember = "ComponentName"; comboBoxComponent.ValueMember = "ID"; comboBoxComponent.DataSource = _list; comboBoxComponent.SelectedItem = null; diff --git a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs index 032e0b0..39059c0 100644 --- a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -70,9 +70,6 @@ namespace DineryBusinessLogic.BusinessLogic _logger.LogInformation("Order. ProductID:{ProductID}. Count:{Count}. Sum:{Sum}. Status:{Status}. " + "DateCreate:{DateCreate}. DateImplement:{DateImplement}. ID:{ID}", model.ProductID, model.Count, model.Sum, model.Status, model.DateCreate, model.DateImplement, model.ID); - var element = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); - if (element == null) - throw new InvalidOperationException("Нет такого заказа"); } private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { CheckModel(model, false); @@ -82,7 +79,15 @@ namespace DineryBusinessLogic.BusinessLogic return false; } model.Status = newOrderStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + var viewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); + if (viewModel == null) { + throw new ArgumentNullException(nameof(model)); + } + viewModel.Status = model.Status; + if (model.Status == OrderStatus.Готов) { + model.DateImplement = DateTime.Now; + viewModel.DateImplement = DateTime.Now; + } return true; } } -- 2.25.1 From bb8f28e937de25ad9257c6d6b5fbe56ae4d98824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 25 Feb 2024 18:07:14 +0400 Subject: [PATCH 3/6] Base.03 --- .../StoragesContracts/IOrderStorage.cs | 2 +- Diner/DinerListImplement/DataListSingleton.cs | 6 ++-- .../Implements/OrderStorage.cs | 28 +++++++++++++------ Diner/DinerListImplement/Models/Order.cs | 2 -- .../BusinessLogic/OrderLogic.cs | 26 +++++++++++------ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs b/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs index aeab08a..1cea2b4 100644 --- a/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs +++ b/Diner/DinerContracts/StoragesContracts/IOrderStorage.cs @@ -13,7 +13,7 @@ namespace DinerContracts.StoragesContracts { List GetFullList(); List GetFilteredList(OrderSearchModel model); - OrderViewModel GetElement(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); diff --git a/Diner/DinerListImplement/DataListSingleton.cs b/Diner/DinerListImplement/DataListSingleton.cs index 0826264..0341e42 100644 --- a/Diner/DinerListImplement/DataListSingleton.cs +++ b/Diner/DinerListImplement/DataListSingleton.cs @@ -11,9 +11,9 @@ namespace DinerListImplement { public static DataListSingleton? _instance; - public List? Foods { get; set; } - public List? Snacks { get; set; } - public List? Orders { get; set; } + public List Foods { get; set; } + public List Snacks { get; set; } + public List Orders { get; set; } private DataListSingleton() { Foods = new List(); diff --git a/Diner/DinerListImplement/Implements/OrderStorage.cs b/Diner/DinerListImplement/Implements/OrderStorage.cs index b35564b..9c8bb55 100644 --- a/Diner/DinerListImplement/Implements/OrderStorage.cs +++ b/Diner/DinerListImplement/Implements/OrderStorage.cs @@ -25,18 +25,18 @@ namespace DinerListImplement.Implements if (_source.Orders[i].ID == model.ID) { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } return null; } - public OrderViewModel GetElement(OrderSearchModel model) + public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.ID.HasValue) return null; foreach (var order in _source.Orders) { if (model.ID.HasValue && order.ID == model.ID) { - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -48,7 +48,7 @@ namespace DinerListImplement.Implements if (!model.ID.HasValue) return result; foreach (var order in _source.Orders) { if (order.ID == model.ID) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } return result; @@ -58,11 +58,23 @@ namespace DinerListImplement.Implements { var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } - + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var product in _source.Snacks) + { + if (product.ID == order.ProductID) + { + viewModel.ProductName = product.ProductName; + break; + } + } + return viewModel; + } public OrderViewModel? Insert(OrderBindingModel model) { model.ID = 1; @@ -74,7 +86,7 @@ namespace DinerListImplement.Implements var newOrder = Order.Create(model); if (newOrder == null) return null; _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -82,7 +94,7 @@ namespace DinerListImplement.Implements foreach (var order in _source.Orders) { if (order.ID == model.ID) { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } return null; diff --git a/Diner/DinerListImplement/Models/Order.cs b/Diner/DinerListImplement/Models/Order.cs index 0eb0df6..9e73f3e 100644 --- a/Diner/DinerListImplement/Models/Order.cs +++ b/Diner/DinerListImplement/Models/Order.cs @@ -41,8 +41,6 @@ namespace DinerListImplement.Models } public void Update(OrderBindingModel? model) { if (model == null) return; - Count = model.Count; - Sum = model.Sum; Status = model.Status; DateImplement = model?.DateImplement; } diff --git a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs index 39059c0..d8ca688 100644 --- a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -26,7 +26,9 @@ namespace DineryBusinessLogic.BusinessLogic public bool CreateOrder(OrderBindingModel model) { CheckModel(model); + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } @@ -46,7 +48,7 @@ namespace DineryBusinessLogic.BusinessLogic public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. ID:{ID}", model?.ID); - var list= model == null? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + var list = model == null? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; @@ -73,20 +75,26 @@ namespace DineryBusinessLogic.BusinessLogic } private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { CheckModel(model, false); - - if (model.Status + 1 != newOrderStatus) { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed."); return false; } model.Status = newOrderStatus; - var viewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); - if (viewModel == null) { - throw new ArgumentNullException(nameof(model)); - } - viewModel.Status = model.Status; if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; - viewModel.DateImplement = DateTime.Now; + } + else { + model.DateImplement = viewModel.DateImplement; + } + if (_orderStorage.Update(model) == null) { + model.Status--; + _logger.LogWarning("Update operarion failed"); + return false; } return true; } -- 2.25.1 From a7446a549b278967debee9c4af973504ae2d4766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 25 Feb 2024 18:12:09 +0400 Subject: [PATCH 4/6] Base.04 --- Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs index d8ca688..9e3f458 100644 --- a/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Diner/DineryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -92,7 +92,6 @@ namespace DineryBusinessLogic.BusinessLogic model.DateImplement = viewModel.DateImplement; } if (_orderStorage.Update(model) == null) { - model.Status--; _logger.LogWarning("Update operarion failed"); return false; } -- 2.25.1 From 5c7bc07585d22fe006ebc80f114ad1c6aa5b61cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 26 Feb 2024 20:28:10 +0400 Subject: [PATCH 5/6] Base.05 --- Diner/DinerView/FormMain.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Diner/DinerView/FormMain.Designer.cs b/Diner/DinerView/FormMain.Designer.cs index f90cca1..71c298a 100644 --- a/Diner/DinerView/FormMain.Designer.cs +++ b/Diner/DinerView/FormMain.Designer.cs @@ -106,7 +106,7 @@ buttonInWork.Name = "buttonInWork"; buttonInWork.Size = new Size(212, 39); buttonInWork.TabIndex = 3; - buttonInWork.Text = "Отдать не выполнение"; + buttonInWork.Text = "Отдать на выполнение"; buttonInWork.UseVisualStyleBackColor = true; buttonInWork.Click += buttonInWork_Click; // -- 2.25.1 From ab7d28ebc2ae3b0fa2060ec98cf3e2c0b6dfa988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 2 Mar 2024 15:11:38 +0400 Subject: [PATCH 6/6] Base.06 --- Diner/DinerListImplement/Models/Snack.cs | 2 +- Diner/DinerView/FormFoods.Designer.cs | 4 +- Diner/DinerView/FormMain.cs | 4 +- Diner/DinerView/FormSnack.Designer.cs | 46 ++++----- Diner/DinerView/FormSnacks.Designer.cs | 122 +++++++++++++++++++++++ Diner/DinerView/FormSnacks.cs | 103 +++++++++++++++++++ Diner/DinerView/FormSnacks.resx | 120 ++++++++++++++++++++++ Diner/DinerView/Program.cs | 1 + 8 files changed, 374 insertions(+), 28 deletions(-) create mode 100644 Diner/DinerView/FormSnacks.Designer.cs create mode 100644 Diner/DinerView/FormSnacks.cs create mode 100644 Diner/DinerView/FormSnacks.resx diff --git a/Diner/DinerListImplement/Models/Snack.cs b/Diner/DinerListImplement/Models/Snack.cs index 3e3d43d..83242a0 100644 --- a/Diner/DinerListImplement/Models/Snack.cs +++ b/Diner/DinerListImplement/Models/Snack.cs @@ -11,7 +11,7 @@ namespace DinerListImplement.Models { internal class Snack : ISnackModel { - public string ProductName { get; private set; } = String.Empty; + public string ProductName { get; private set; } = string.Empty; public double Price { get; private set; } diff --git a/Diner/DinerView/FormFoods.Designer.cs b/Diner/DinerView/FormFoods.Designer.cs index abaac85..9771ab1 100644 --- a/Diner/DinerView/FormFoods.Designer.cs +++ b/Diner/DinerView/FormFoods.Designer.cs @@ -93,7 +93,7 @@ buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += buttonUpdate_Click; // - // FormComponents + // FormFoods // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; @@ -104,7 +104,7 @@ Controls.Add(buttonChange); Controls.Add(buttonAdd); Controls.Add(dataGridView); - Name = "FormComponents"; + Name = "FormFoods"; Text = "Foods"; Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/Diner/DinerView/FormMain.cs b/Diner/DinerView/FormMain.cs index da07e29..a7d2786 100644 --- a/Diner/DinerView/FormMain.cs +++ b/Diner/DinerView/FormMain.cs @@ -61,8 +61,8 @@ namespace DinerView private void toolStripMenuItemSnacks_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSnack)); - if (service is FormSnack form) { + var service = Program.ServiceProvider?.GetService(typeof(FormSnacks)); + if (service is FormSnacks form) { form.ShowDialog(); LoadData(); } diff --git a/Diner/DinerView/FormSnack.Designer.cs b/Diner/DinerView/FormSnack.Designer.cs index 320031c..112185a 100644 --- a/Diner/DinerView/FormSnack.Designer.cs +++ b/Diner/DinerView/FormSnack.Designer.cs @@ -38,11 +38,11 @@ buttonChange = new Button(); buttonAdd = new Button(); dataGridView = new DataGridView(); + buttonCancel = new Button(); + buttonSave = new Button(); ColumnID = new DataGridViewTextBoxColumn(); ColumnFood = new DataGridViewTextBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); - buttonCancel = new Button(); - buttonSave = new Button(); groupBoxFoods.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -94,7 +94,7 @@ groupBoxFoods.Size = new Size(657, 373); groupBoxFoods.TabIndex = 4; groupBoxFoods.TabStop = false; - groupBoxFoods.Text = "Foods"; + groupBoxFoods.Text = "Используемые продукты"; // // buttonUpdate // @@ -160,26 +160,6 @@ dataGridView.Size = new Size(437, 351); dataGridView.TabIndex = 0; // - // ColumnID - // - ColumnID.HeaderText = "ID"; - ColumnID.Name = "ColumnID"; - ColumnID.ReadOnly = true; - ColumnID.Visible = false; - // - // ColumnFood - // - ColumnFood.HeaderText = "Food"; - ColumnFood.Name = "ColumnFood"; - ColumnFood.ReadOnly = true; - ColumnFood.Width = 337; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.Name = "ColumnCount"; - ColumnCount.ReadOnly = true; - // // buttonCancel // buttonCancel.Location = new Point(587, 30); @@ -200,6 +180,26 @@ buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += buttonSave_Click; // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.Name = "ColumnID"; + ColumnID.ReadOnly = true; + ColumnID.Visible = false; + // + // ColumnFood + // + ColumnFood.HeaderText = "Продукт"; + ColumnFood.Name = "ColumnFood"; + ColumnFood.ReadOnly = true; + ColumnFood.Width = 337; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // // FormSnack // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/Diner/DinerView/FormSnacks.Designer.cs b/Diner/DinerView/FormSnacks.Designer.cs new file mode 100644 index 0000000..beecc90 --- /dev/null +++ b/Diner/DinerView/FormSnacks.Designer.cs @@ -0,0 +1,122 @@ +namespace DinerView +{ + partial class FormSnacks + { + /// + /// 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() + { + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpdate + // + buttonUpdate.Location = new Point(578, 153); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(219, 41); + buttonUpdate.TabIndex = 9; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(578, 106); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(219, 41); + buttonRemove.TabIndex = 8; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonChange + // + buttonChange.Location = new Point(578, 59); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(219, 41); + buttonChange.TabIndex = 7; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(578, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(219, 41); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.BorderStyle = BorderStyle.None; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(563, 450); + dataGridView.TabIndex = 5; + // + // FormSnacks + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = SystemColors.ScrollBar; + ClientSize = new Size(800, 450); + Controls.Add(buttonUpdate); + Controls.Add(buttonRemove); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormSnacks"; + Text = "FormSnacks"; + Load += FormSnacks_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Diner/DinerView/FormSnacks.cs b/Diner/DinerView/FormSnacks.cs new file mode 100644 index 0000000..6d427e8 --- /dev/null +++ b/Diner/DinerView/FormSnacks.cs @@ -0,0 +1,103 @@ +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContacts; +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 DinerView +{ + public partial class FormSnacks : Form + { + private readonly ILogger _logger; + private readonly ISnackLogic _logic; + public FormSnacks(ILogger logger, ISnackLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ID"].Visible = false; + dataGridView.Columns["ProductComponents"].Visible = false; + dataGridView.Columns["ProductName"].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(FormSnack)); + if (service is FormSnack form) { + if (form.ShowDialog() == DialogResult.OK) LoadData(); + } + } + + private void buttonRemove_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 SnackBindingModel { ID = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления снэка"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSnack)); + if (service is FormSnack form) + { + form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); + if (form.ShowDialog() == DialogResult.OK) LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormSnacks_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Diner/DinerView/FormSnacks.resx b/Diner/DinerView/FormSnacks.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/DinerView/FormSnacks.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/DinerView/Program.cs b/Diner/DinerView/Program.cs index 17fe7e5..d6e7583 100644 --- a/Diner/DinerView/Program.cs +++ b/Diner/DinerView/Program.cs @@ -48,6 +48,7 @@ namespace DinerView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1