From 47211b373ebd5143525d73c62290dff4cad155d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 12:37:50 +0400 Subject: [PATCH 01/14] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ComponentBindingModel.cs | 17 +++ .../BindingModels/OrderBindingModel.cs | 22 ++++ .../BindingModels/PastryBindingModel.cs | 21 +++ .../IComponentLogic.cs | 21 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 +++ .../BusinessLogicsContracts/IPastryLogic.cs | 20 +++ .../ConfectioneryContracts.csproj | 20 +++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 ++ .../SearchModels/PastrySearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++++ .../StoragesContracts/IOrderStorage.cs | 21 +++ .../StoragesContracts/IPastryStorage.cs | 21 +++ .../ViewModels/ComponentViewModel.cs | 19 +++ .../ViewModels/OrderViewModel.cs | 30 +++++ .../ViewModels/PastryViewModel.cs | 24 ++++ .../ConfectioneryDataModels.csproj | 16 +++ .../IComponentModel.cs | 14 ++ .../ConfectionaryDataModels/IOrderModel.cs | 19 +++ .../ConfectionaryDataModels/IPastryModel.cs | 15 +++ Confectionery/ConfectionaryDataModels/Iid.cs | 13 ++ .../ConfectionaryDataModels/OrderStatus.cs | 11 ++ Confectionery/Confectionery.sln | 26 +++- .../ComponentLogic.cs | 122 ++++++++++++++++++ .../ConfectioneryBusinessLogic.csproj | 20 +++ .../ConfectioneryBusinessLogic/OrderLogic.cs | 42 ++++++ .../ConfectioneryBusinessLogic/PastryLogic.cs | 42 ++++++ .../ConfectioneryListImplement/Component.cs | 47 +++++++ .../ComponentStorage.cs | 109 ++++++++++++++++ .../ConfectioneryListImplement.csproj | 14 ++ .../DataListSingleton.cs | 30 +++++ .../ConfectioneryListImplement/Order.cs | 43 ++++++ .../ConfectioneryListImplement/Pastry.cs | 54 ++++++++ .../ConfectioneryView.csproj | 19 +++ Confectionery/ConfectioneryView/Form1.cs | 10 -- .../FormComponent.Designer.cs | 119 +++++++++++++++++ .../ConfectioneryView/FormComponent.cs | 99 ++++++++++++++ .../ConfectioneryView/FormComponent.resx | 60 +++++++++ .../FormComponents.Designer.cs | 115 +++++++++++++++++ .../ConfectioneryView/FormComponents.cs | 121 +++++++++++++++++ .../ConfectioneryView/FormComponents.resx | 60 +++++++++ ...rm1.Designer.cs => FormPastry.Designer.cs} | 12 +- Confectionery/ConfectioneryView/FormPastry.cs | 23 ++++ .../ConfectioneryView/FormPastry.resx | 120 +++++++++++++++++ .../FormPastryComponent.Designer.cs | 119 +++++++++++++++++ .../ConfectioneryView/FormPastryComponent.cs | 94 ++++++++++++++ .../FormPastryComponent.resx | 60 +++++++++ Confectionery/ConfectioneryView/Program.cs | 6 +- 48 files changed, 1975 insertions(+), 18 deletions(-) create mode 100644 Confectionery/ConfectionaryContracts/BindingModels/ComponentBindingModel.cs create mode 100644 Confectionery/ConfectionaryContracts/BindingModels/OrderBindingModel.cs create mode 100644 Confectionery/ConfectionaryContracts/BindingModels/PastryBindingModel.cs create mode 100644 Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IPastryLogic.cs create mode 100644 Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj create mode 100644 Confectionery/ConfectionaryContracts/SearchModels/ComponentSearchModel.cs create mode 100644 Confectionery/ConfectionaryContracts/SearchModels/OrderSearchModel.cs create mode 100644 Confectionery/ConfectionaryContracts/SearchModels/PastrySearchModel.cs create mode 100644 Confectionery/ConfectionaryContracts/StoragesContracts/IComponentStorage.cs create mode 100644 Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs create mode 100644 Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs create mode 100644 Confectionery/ConfectionaryContracts/ViewModels/ComponentViewModel.cs create mode 100644 Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs create mode 100644 Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj create mode 100644 Confectionery/ConfectionaryDataModels/IComponentModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/IOrderModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/IPastryModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/Iid.cs create mode 100644 Confectionery/ConfectionaryDataModels/OrderStatus.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj create mode 100644 Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs create mode 100644 Confectionery/ConfectioneryListImplement/Component.cs create mode 100644 Confectionery/ConfectioneryListImplement/ComponentStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj create mode 100644 Confectionery/ConfectioneryListImplement/DataListSingleton.cs create mode 100644 Confectionery/ConfectioneryListImplement/Order.cs create mode 100644 Confectionery/ConfectioneryListImplement/Pastry.cs delete mode 100644 Confectionery/ConfectioneryView/Form1.cs create mode 100644 Confectionery/ConfectioneryView/FormComponent.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormComponent.cs create mode 100644 Confectionery/ConfectioneryView/FormComponent.resx create mode 100644 Confectionery/ConfectioneryView/FormComponents.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormComponents.cs create mode 100644 Confectionery/ConfectioneryView/FormComponents.resx rename Confectionery/ConfectioneryView/{Form1.Designer.cs => FormPastry.Designer.cs} (76%) create mode 100644 Confectionery/ConfectioneryView/FormPastry.cs create mode 100644 Confectionery/ConfectioneryView/FormPastry.resx create mode 100644 Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormPastryComponent.cs create mode 100644 Confectionery/ConfectioneryView/FormPastryComponent.resx diff --git a/Confectionery/ConfectionaryContracts/BindingModels/ComponentBindingModel.cs b/Confectionery/ConfectionaryContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..6437bc7 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + + } +} diff --git a/Confectionery/ConfectionaryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectionaryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..ad6b29d --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PastryId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + + } +} diff --git a/Confectionery/ConfectionaryContracts/BindingModels/PastryBindingModel.cs b/Confectionery/ConfectionaryContracts/BindingModels/PastryBindingModel.cs new file mode 100644 index 0000000..4b95cd1 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BindingModels/PastryBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class PastryBindingModel : IPastryModel + { + public int Id { get; set; } + public string PastryName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PastryComponents + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IComponentLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..379c582 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + + } +} diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..fc1f506 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IPastryLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IPastryLogic.cs new file mode 100644 index 0000000..961f022 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IPastryLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IPastryLogic + { + List? ReadList(PastrySearchModel? model); + PastryViewModel? ReadElement(PastrySearchModel model); + bool Create(PastryBindingModel model); + bool Update(PastryBindingModel model); + bool Delete(PastryBindingModel model); + } +} diff --git a/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj new file mode 100644 index 0000000..5a76ab1 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Confectionery/ConfectionaryContracts/SearchModels/ComponentSearchModel.cs b/Confectionery/ConfectionaryContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..e12031b --- /dev/null +++ b/Confectionery/ConfectionaryContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectionaryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..9393fab --- /dev/null +++ b/Confectionery/ConfectionaryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/SearchModels/PastrySearchModel.cs b/Confectionery/ConfectionaryContracts/SearchModels/PastrySearchModel.cs new file mode 100644 index 0000000..33c17c1 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/SearchModels/PastrySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class PastrySearchModel + { + public int? Id { get; set; } + public string? PastryName { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IComponentStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..d7aa878 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..5a3228c --- /dev/null +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + internal interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs new file mode 100644 index 0000000..f08be11 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + internal interface IPastryStorage + { + List GetFullList(); + List GetFilteredList(PastrySearchModel model); + PastryViewModel? GetElement(PastrySearchModel model); + PastryViewModel? Insert(PastryBindingModel model); + PastryViewModel? Update(PastryBindingModel model); + PastryViewModel? Delete(PastryBindingModel model); + } +} diff --git a/Confectionery/ConfectionaryContracts/ViewModels/ComponentViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..c0c7c2a --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; +using System.ComponentModel; + +namespace ConfectioneryContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..d0d6367 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; +using System.ComponentModel; +using ConfectioneryDataModels.Enums; + +namespace ConfectioneryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int PastryId { get; set; } + [DisplayName("Изделие")] + public string PastryName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs new file mode 100644 index 0000000..4eea8da --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; +using System.ComponentModel; + +namespace ConfectioneryContracts.ViewModels +{ + public class PastryViewModel : IPastryModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string PastryName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary PastryComponents + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj new file mode 100644 index 0000000..792d358 --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj @@ -0,0 +1,16 @@ + + + + net6.0 + enable + enable + + + + + + + + + + diff --git a/Confectionery/ConfectionaryDataModels/IComponentModel.cs b/Confectionery/ConfectionaryDataModels/IComponentModel.cs new file mode 100644 index 0000000..bfba2c6 --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IComponentModel : Iid + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/Confectionery/ConfectionaryDataModels/IOrderModel.cs b/Confectionery/ConfectionaryDataModels/IOrderModel.cs new file mode 100644 index 0000000..fed83f2 --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/IOrderModel.cs @@ -0,0 +1,19 @@ +using ConfectioneryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IOrderModel : Iid + { + int PastryId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/Confectionery/ConfectionaryDataModels/IPastryModel.cs b/Confectionery/ConfectionaryDataModels/IPastryModel.cs new file mode 100644 index 0000000..7ac7324 --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/IPastryModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IPastryModel : Iid + { + string PastryName { get; } + double Price { get; } + Dictionary PastryComponents { get; } + } +} diff --git a/Confectionery/ConfectionaryDataModels/Iid.cs b/Confectionery/ConfectionaryDataModels/Iid.cs new file mode 100644 index 0000000..1c4791e --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/Iid.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels +{ + public interface Iid + { + int Id { get; } + } +} diff --git a/Confectionery/ConfectionaryDataModels/OrderStatus.cs b/Confectionery/ConfectionaryDataModels/OrderStatus.cs new file mode 100644 index 0000000..9bcdc71 --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace ConfectioneryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3, + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 8e2d453..a7f5d85 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{2DAD8519-A540-4312-B881-47D4AFE97E7F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{2DAD8519-A540-4312-B881-47D4AFE97E7F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectionaryDataModels\ConfectioneryDataModels.csproj", "{0E74E5DA-C6A4-4001-A02A-7B4316A1B9ED}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectionaryContracts\ConfectioneryContracts.csproj", "{4BC782E2-5108-4C55-9F76-ACE5A56B8735}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{2822ACD8-8B94-4BF2-8C55-478677FDD1FE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{EE30482F-8998-4178-8412-421A02F6A6B4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {2DAD8519-A540-4312-B881-47D4AFE97E7F}.Debug|Any CPU.Build.0 = Debug|Any CPU {2DAD8519-A540-4312-B881-47D4AFE97E7F}.Release|Any CPU.ActiveCfg = Release|Any CPU {2DAD8519-A540-4312-B881-47D4AFE97E7F}.Release|Any CPU.Build.0 = Release|Any CPU + {0E74E5DA-C6A4-4001-A02A-7B4316A1B9ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E74E5DA-C6A4-4001-A02A-7B4316A1B9ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E74E5DA-C6A4-4001-A02A-7B4316A1B9ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E74E5DA-C6A4-4001-A02A-7B4316A1B9ED}.Release|Any CPU.Build.0 = Release|Any CPU + {4BC782E2-5108-4C55-9F76-ACE5A56B8735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BC782E2-5108-4C55-9F76-ACE5A56B8735}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BC782E2-5108-4C55-9F76-ACE5A56B8735}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BC782E2-5108-4C55-9F76-ACE5A56B8735}.Release|Any CPU.Build.0 = Release|Any CPU + {2822ACD8-8B94-4BF2-8C55-478677FDD1FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2822ACD8-8B94-4BF2-8C55-478677FDD1FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2822ACD8-8B94-4BF2-8C55-478677FDD1FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2822ACD8-8B94-4BF2-8C55-478677FDD1FE}.Release|Any CPU.Build.0 = Release|Any CPU + {EE30482F-8998-4178-8412-421A02F6A6B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE30482F-8998-4178-8412-421A02F6A6B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs b/Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..95afffe --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; + + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj new file mode 100644 index 0000000..a03d415 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..27e4feb --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic +{ + internal class OrderLogic : IOrderLogic + { + public bool CreateOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool FinishOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(OrderSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs new file mode 100644 index 0000000..d8a5d69 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + internal class PastryLogic : IPastryLogic + { + public bool Create(PastryBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(PastryBindingModel model) + { + throw new NotImplementedException(); + } + + public PastryViewModel? ReadElement(PastrySearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(PastrySearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(PastryBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Component.cs b/Confectionery/ConfectioneryListImplement/Component.cs new file mode 100644 index 0000000..9683495 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Component.cs @@ -0,0 +1,47 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + } +} diff --git a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs new file mode 100644 index 0000000..03ed3c0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs @@ -0,0 +1,109 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + internal class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..54e27de --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..7068cc9 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Pastrys { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Pastrys = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Order.cs b/Confectionery/ConfectioneryListImplement/Order.cs new file mode 100644 index 0000000..b35f396 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Order.cs @@ -0,0 +1,43 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + internal class Order : IOrderModel + { + public int PastryId => throw new NotImplementedException(); + + public int Count => throw new NotImplementedException(); + + public double Sum => throw new NotImplementedException(); + + public OrderStatus Status => throw new NotImplementedException(); + + public DateTime DateCreate => throw new NotImplementedException(); + + public DateTime? DateImplement => throw new NotImplementedException(); + + public int Id => throw new NotImplementedException(); + + public static Order? Create(OrderBindingModel? model) + { + return new Order(); + } + + public void Update(OrderBindingModel? model) + { + + } + + public OrderViewModel GetViewModel => new() + { + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Pastry.cs b/Confectionery/ConfectioneryListImplement/Pastry.cs new file mode 100644 index 0000000..ce7f3f3 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Pastry.cs @@ -0,0 +1,54 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + internal class Pastry : IPastryModel + { + public int Id { get; private set; } + public string PastryName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PastryComponents + { + get; + private set; + } = new Dictionary(); + public static Pastry? Create(PastryBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pastry() + { + Id = model.Id, + PastryName = model.PastryName, + Price = model.Price, + PastryComponents = model.PastryComponents + }; + } + public void Update(PastryBindingModel? model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + PastryComponents = model.PastryComponents; + } + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryComponents = PastryComponents + }; + } +} diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj index b57c89e..55e33bf 100644 --- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -8,4 +8,23 @@ enable + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Form1.cs b/Confectionery/ConfectioneryView/Form1.cs deleted file mode 100644 index 0d39778..0000000 --- a/Confectionery/ConfectioneryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ConfectioneryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs new file mode 100644 index 0000000..417103e --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ConfectioneryView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(54, 42); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(54, 95); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(48, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(173, 39); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(295, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(173, 95); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(160, 27); + this.textBoxCost.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(104, 158); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(315, 158); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(495, 232); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "FormComponent"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.cs b/Confectionery/ConfectioneryView/FormComponent.cs new file mode 100644 index 0000000..49006fb --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.cs @@ -0,0 +1,99 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/Confectionery/ConfectioneryView/FormComponent.resx b/Confectionery/ConfectioneryView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponents.Designer.cs b/Confectionery/ConfectioneryView/FormComponents.Designer.cs new file mode 100644 index 0000000..bd9263c --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace ConfectioneryView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(490, 426); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(534, 26); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(111, 32); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(534, 232); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(111, 32); + this.ButtonRef.TabIndex = 2; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(534, 163); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(111, 32); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(534, 94); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(111, 32); + this.ButtonUpd.TabIndex = 4; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(670, 450); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponents.cs b/Confectionery/ConfectioneryView/FormComponents.cs new file mode 100644 index 0000000..98aeb9c --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponents.cs @@ -0,0 +1,121 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormComponents.resx b/Confectionery/ConfectioneryView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Form1.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs similarity index 76% rename from Confectionery/ConfectioneryView/Form1.Designer.cs rename to Confectionery/ConfectioneryView/FormPastry.Designer.cs index 4fdee0d..bd84ac9 100644 --- a/Confectionery/ConfectioneryView/Form1.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -1,14 +1,14 @@ namespace ConfectioneryView { - partial class Form1 + partial class FormPastry { /// - /// Required designer variable. + /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// - /// Clean up any resources being used. + /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) @@ -23,15 +23,15 @@ #region Windows Form Designer generated code /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// 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"; + this.Text = "FormPastry"; } #endregion diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs new file mode 100644 index 0000000..3fd8072 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormPastry : Form + { + private readonly ILogger _logger; + private int? _id; + public FormPastry() + { + InitializeComponent(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormPastry.resx b/Confectionery/ConfectioneryView/FormPastry.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastry.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/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs new file mode 100644 index 0000000..e9b2d8c --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ConfectioneryView +{ + partial class FormPastryComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelComponent = new System.Windows.Forms.Label(); + this.labelQuantity = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(61, 41); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(91, 20); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // labelQuantity + // + this.labelQuantity.AutoSize = true; + this.labelQuantity.Location = new System.Drawing.Point(61, 110); + this.labelQuantity.Name = "labelQuantity"; + this.labelQuantity.Size = new System.Drawing.Size(93, 20); + this.labelQuantity.TabIndex = 1; + this.labelQuantity.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(187, 107); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(125, 27); + this.textBoxCount.TabIndex = 2; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(187, 38); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(151, 28); + this.comboBoxComponent.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(128, 214); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(349, 214); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormPastryComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(654, 450); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelQuantity); + this.Controls.Add(this.labelComponent); + this.Name = "FormPastryComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private Label labelQuantity; + private TextBox textBoxCount; + private ComboBox comboBoxComponent; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastryComponent.cs b/Confectionery/ConfectioneryView/FormPastryComponent.cs new file mode 100644 index 0000000..5149af3 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.cs @@ -0,0 +1,94 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormPastryComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + + public FormPastryComponent(IComponentLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/Confectionery/ConfectioneryView/FormPastryComponent.resx b/Confectionery/ConfectioneryView/FormPastryComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 8b4cd92..575f8c6 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -1,7 +1,11 @@ +using Microsoft.Extensions.DependencyInjection; + namespace ConfectioneryView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +15,7 @@ namespace ConfectioneryView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormComponent()); } } } \ No newline at end of file -- 2.25.1 From 54775f3000c04773159c078b8a9c671848160377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 13:00:47 +0400 Subject: [PATCH 02/14] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormPastry.Designer.cs | 48 +++- Confectionery/ConfectioneryView/FormPastry.cs | 207 +++++++++++++++++- .../ConfectioneryView/FormPastry.resx | 62 +----- 3 files changed, 252 insertions(+), 65 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index bd84ac9..8e229a3 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -28,12 +28,56 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(281, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(125, 27); + this.textBoxName.TabIndex = 0; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(281, 62); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(125, 27); + this.textBoxPrice.TabIndex = 1; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 250); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(300, 188); + this.dataGridView.TabIndex = 2; + // + // FormPastry + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1025, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Name = "FormPastry"; this.Text = "FormPastry"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private TextBox textBoxName; + private TextBox textBoxPrice; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs index 3fd8072..dfd0549 100644 --- a/Confectionery/ConfectioneryView/FormPastry.cs +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -1,4 +1,8 @@ -using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.ComponentModel; @@ -14,10 +18,209 @@ namespace ConfectioneryView public partial class FormPastry : Form { private readonly ILogger _logger; + private readonly IPastryLogic _logic; private int? _id; - public FormPastry() + private Dictionary _pastryComponents; + public int Id { set { _id = value; } } + + public FormPastry(ILogger logger, IPastryLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + _pastryComponents = new Dictionary(); + } + + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PastrySearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PastryName; + textBoxPrice.Text = view.Price.ToString(); + _pastryComponents = view.PastryComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_pastryComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _pastryComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); + if (service is FormPastryComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_pastryComponents.ContainsKey(form.Id)) + { + _pastryComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _pastryComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); + if (service is FormPastryComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _pastryComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _pastryComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + 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 (_pastryComponents == null || _pastryComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PastryBindingModel + { + Id = _id ?? 0, + PastryName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PastryComponents = _pastryComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _pastryComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); } } } diff --git a/Confectionery/ConfectioneryView/FormPastry.resx b/Confectionery/ConfectioneryView/FormPastry.resx index 1af7de1..f298a7b 100644 --- a/Confectionery/ConfectioneryView/FormPastry.resx +++ b/Confectionery/ConfectioneryView/FormPastry.resx @@ -1,64 +1,4 @@ - - - + -- 2.25.1 From 6706d8214221ad420e9ff61b02a8ab25e4aacf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 15:14:49 +0400 Subject: [PATCH 03/14] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=20=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormPastry.Designer.cs | 130 +++++++++++++++++- Confectionery/ConfectioneryView/FormPastry.cs | 7 +- 2 files changed, 129 insertions(+), 8 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index 8e229a3..b2d43bf 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -31,19 +31,29 @@ this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxPrice = new System.Windows.Forms.TextBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.groupBox = new System.Windows.Forms.GroupBox(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.groupBox.SuspendLayout(); this.SuspendLayout(); // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(281, 12); + this.textBoxName.Location = new System.Drawing.Point(204, 16); this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(125, 27); + this.textBoxName.Size = new System.Drawing.Size(223, 27); this.textBoxName.TabIndex = 0; // // textBoxPrice // - this.textBoxPrice.Location = new System.Drawing.Point(281, 62); + this.textBoxPrice.Location = new System.Drawing.Point(204, 64); this.textBoxPrice.Name = "textBoxPrice"; this.textBoxPrice.Size = new System.Drawing.Size(125, 27); this.textBoxPrice.TabIndex = 1; @@ -51,24 +61,121 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 250); + this.dataGridView.Location = new System.Drawing.Point(6, 26); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(300, 188); + this.dataGridView.Size = new System.Drawing.Size(422, 297); this.dataGridView.TabIndex = 2; // + // groupBox + // + this.groupBox.Controls.Add(this.ButtonRef); + this.groupBox.Controls.Add(this.ButtonDel); + this.groupBox.Controls.Add(this.ButtonUpd); + this.groupBox.Controls.Add(this.ButtonAdd); + this.groupBox.Controls.Add(this.dataGridView); + this.groupBox.Location = new System.Drawing.Point(12, 109); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(619, 329); + this.groupBox.TabIndex = 3; + this.groupBox.TabStop = false; + this.groupBox.Text = "Компоненты"; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(477, 251); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(94, 29); + this.ButtonRef.TabIndex = 6; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(477, 184); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(94, 29); + this.ButtonDel.TabIndex = 5; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(477, 118); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(94, 29); + this.ButtonUpd.TabIndex = 4; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(477, 53); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(94, 29); + this.ButtonAdd.TabIndex = 3; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(235, 459); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 7; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(433, 459); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Удалить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(82, 19); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 9; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(82, 67); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(86, 20); + this.labelPrice.TabIndex = 10; + this.labelPrice.Text = "Стоимость:"; + // // FormPastry // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1025, 450); - this.Controls.Add(this.dataGridView); + this.ClientSize = new System.Drawing.Size(643, 511); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.groupBox); this.Controls.Add(this.textBoxPrice); this.Controls.Add(this.textBoxName); this.Name = "FormPastry"; this.Text = "FormPastry"; ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.groupBox.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -79,5 +186,14 @@ private TextBox textBoxName; private TextBox textBoxPrice; private DataGridView dataGridView; + private GroupBox groupBox; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private Button ButtonSave; + private Button ButtonCancel; + private Label labelName; + private Label labelPrice; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs index dfd0549..6b6714a 100644 --- a/Confectionery/ConfectioneryView/FormPastry.cs +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -31,7 +31,7 @@ namespace ConfectioneryView _pastryComponents = new Dictionary(); } - private void FormProduct_Load(object sender, EventArgs e) + private void FormPastry_Load(object sender, EventArgs e) { if (_id.HasValue) { @@ -137,6 +137,11 @@ namespace ConfectioneryView } } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) -- 2.25.1 From 32d416e795e3fb0c27c325e168f7dcce6a1f9871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 15:35:42 +0400 Subject: [PATCH 04/14] =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D1=87?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=81=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCreateOrder.Designer.cs | 139 ++++++++++++++++++ .../ConfectioneryView/FormCreateOrder.cs | 116 +++++++++++++++ .../ConfectioneryView/FormCreateOrder.resx | 60 ++++++++ .../ConfectioneryView/FormPastry.Designer.cs | 2 +- 4 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.resx diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..420ff18 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -0,0 +1,139 @@ +namespace ConfectioneryView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelPastry = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(38, 30); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(71, 20); + this.labelPastry.TabIndex = 0; + this.labelPastry.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 67); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(38, 102); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(58, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(150, 22); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(337, 28); + this.comboBoxPastry.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 60); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(337, 27); + this.textBoxCount.TabIndex = 4; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(150, 95); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(337, 27); + this.textBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(216, 137); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(361, 137); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(499, 180); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPastry); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPastry; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPastry; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs new file mode 100644 index 0000000..08894b5 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -0,0 +1,116 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPastryLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + // прописать логику + } + private void CalcSum() + { + if (comboBoxPastry.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPastry.SelectedValue); + var product = _logicP.ReadElement(new PastrySearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void 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 (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.resx b/Confectionery/ConfectioneryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index b2d43bf..196a105 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -138,7 +138,7 @@ this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Size = new System.Drawing.Size(94, 29); this.ButtonCancel.TabIndex = 8; - this.ButtonCancel.Text = "Удалить"; + this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // -- 2.25.1 From 0763ef71df23d5ee95ee73c0bada42183d411451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 15:58:29 +0400 Subject: [PATCH 05/14] =?UTF-8?q?=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D1=87=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCreateOrder.Designer.cs | 5 + .../ConfectioneryView/FormCreateOrder.cs | 3 +- .../ConfectioneryView/FormMain.Designer.cs | 174 ++++++++++++++++++ Confectionery/ConfectioneryView/FormMain.cs | 151 +++++++++++++++ Confectionery/ConfectioneryView/FormMain.resx | 63 +++++++ 5 files changed, 394 insertions(+), 2 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormMain.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormMain.cs create mode 100644 Confectionery/ConfectioneryView/FormMain.resx diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs index 420ff18..44040db 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -72,6 +72,7 @@ this.comboBoxPastry.Name = "comboBoxPastry"; this.comboBoxPastry.Size = new System.Drawing.Size(337, 28); this.comboBoxPastry.TabIndex = 3; + this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPastry_SelectedIndexChanged); // // textBoxCount // @@ -79,6 +80,7 @@ this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(337, 27); this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); // // textBoxSum // @@ -95,6 +97,7 @@ this.ButtonSave.TabIndex = 6; this.ButtonSave.Text = "Сохранить"; this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // ButtonCancel // @@ -104,6 +107,7 @@ this.ButtonCancel.TabIndex = 7; this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // FormCreateOrder // @@ -120,6 +124,7 @@ this.Controls.Add(this.labelPastry); this.Name = "FormCreateOrder"; this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index 08894b5..d49bc4d 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -62,8 +62,7 @@ namespace ConfectioneryView { CalcSum(); } - private void ComboBoxProduct_SelectedIndexChanged(object sender, - EventArgs e) + private void ComboBoxPastry_SelectedIndexChanged(object sender, EventArgs e) { CalcSum(); } diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs new file mode 100644 index 0000000..9f6753d --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -0,0 +1,174 @@ +namespace ConfectioneryView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1376, 28); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.изделияToolStripMenuItem.Text = "Изделия"; + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(13, 31); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 29; + this.dataGridView1.Size = new System.Drawing.Size(968, 526); + this.dataGridView1.TabIndex = 1; + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Location = new System.Drawing.Point(1050, 67); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(246, 29); + this.ButtonCreateOrder.TabIndex = 2; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(1050, 164); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(246, 29); + this.ButtonTakeOrderInWork.TabIndex = 3; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Location = new System.Drawing.Point(1050, 256); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(246, 29); + this.ButtonOrderReady.TabIndex = 4; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Location = new System.Drawing.Point(1050, 351); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(246, 29); + this.ButtonIssuedOrder.TabIndex = 5; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(1050, 441); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(246, 29); + this.ButtonRef.TabIndex = 6; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1376, 569); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Кондитерская"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView1; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs new file mode 100644 index 0000000..02c0bf6 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -0,0 +1,151 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class 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("Загрузка заказов"); + // прописать логику + } + + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + // прописать логику + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.resx b/Confectionery/ConfectioneryView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file -- 2.25.1 From b4a88a1231d0179bdfa758be2175476572c237cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 22:14:35 +0400 Subject: [PATCH 06/14] =?UTF-8?q?=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryContracts.csproj | 2 + .../StoragesContracts/IOrderStorage.cs | 2 +- .../StoragesContracts/IPastryStorage.cs | 2 +- .../ConfectioneryDataModels.csproj | 2 + .../ConfectioneryBusinessLogic.csproj | 2 + .../ConfectioneryBusinessLogic/OrderLogic.cs | 123 +++++++++++++++--- .../ConfectioneryBusinessLogic/PastryLogic.cs | 108 +++++++++++++-- .../ComponentStorage.cs | 2 +- .../ConfectioneryListImplement.csproj | 5 + .../DataListSingleton.cs | 4 +- .../OrderStorage.cs | 122 +++++++++++++++++ .../PastryStorage.cs | 114 ++++++++++++++++ .../ConfectioneryView.csproj | 2 + .../ConfectioneryView/FormMain.Designer.cs | 28 ++-- Confectionery/ConfectioneryView/FormMain.cs | 24 +++- .../FormPastries.Designer.cs | 110 ++++++++++++++++ .../ConfectioneryView/FormPastries.cs | 112 ++++++++++++++++ .../ConfectioneryView/FormPastries.resx | 60 +++++++++ Confectionery/ConfectioneryView/Program.cs | 34 ++++- 19 files changed, 808 insertions(+), 50 deletions(-) create mode 100644 Confectionery/ConfectioneryListImplement/OrderStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/PastryStorage.cs create mode 100644 Confectionery/ConfectioneryView/FormPastries.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormPastries.cs create mode 100644 Confectionery/ConfectioneryView/FormPastries.resx diff --git a/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj index 5a76ab1..c07ce67 100644 --- a/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj +++ b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj @@ -11,6 +11,8 @@ + + diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs index 5a3228c..cbdd94f 100644 --- a/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace ConfectioneryContracts.StoragesContracts { - internal interface IOrderStorage + public interface IOrderStorage { List GetFullList(); List GetFilteredList(OrderSearchModel model); diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs index f08be11..50d7584 100644 --- a/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace ConfectioneryContracts.StoragesContracts { - internal interface IPastryStorage + public interface IPastryStorage { List GetFullList(); List GetFilteredList(PastrySearchModel model); diff --git a/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj index 792d358..8ee6bda 100644 --- a/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj +++ b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj @@ -11,6 +11,8 @@ + + diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj index a03d415..3aceb59 100644 --- a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -11,6 +11,8 @@ + + diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs index 27e4feb..939b321 100644 --- a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs @@ -9,34 +9,127 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.StoragesContracts; using Microsoft.Extensions.Logging; +using ConfectioneryDataModels.Enums; -namespace ConfectioneryBusinessLogic +namespace ConfectioneryBusinessLogic.BusinessLogics { - internal class OrderLogic : IOrderLogic + 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) { - throw new NotImplementedException(); - } - - public bool DeliveryOrder(OrderBindingModel model) - { - throw new NotImplementedException(); - } - - public bool FinishOrder(OrderBindingModel model) - { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public List? ReadList(OrderSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; } public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PastryId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.PastryId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PastryId: {PastryId}. PastryCount: {Count}", model.Id, model.Sum, + model.PastryId, model.Count); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) + { + _logger.LogWarning("Change status operation failed. Order not found"); + return false; + } + if (order.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}", + newStatus, order.Status); + return false; + } + model.PastryId = order.PastryId; + model.Count = order.Count; + model.Sum = order.Sum; + model.DateCreate = order.DateCreate; + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; } } } diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs index d8a5d69..781d3a1 100644 --- a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs @@ -12,31 +12,113 @@ using Microsoft.Extensions.Logging; namespace ConfectioneryBusinessLogic.BusinessLogics { - internal class PastryLogic : IPastryLogic + public class PastryLogic : IPastryLogic { - public bool Create(PastryBindingModel model) - { - throw new NotImplementedException(); - } + private readonly ILogger _logger; - public bool Delete(PastryBindingModel model) - { - throw new NotImplementedException(); - } + private readonly IPastryStorage _iceCreamStorage; - public PastryViewModel? ReadElement(PastrySearchModel model) + public PastryLogic(ILogger logger, IPastryStorage iceCreamStorage) { - throw new NotImplementedException(); + _logger = logger; + _iceCreamStorage = iceCreamStorage; } public List? ReadList(PastrySearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id); + var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public PastryViewModel? ReadElement(PastrySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id); + var element = _iceCreamStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(PastryBindingModel model) + { + CheckModel(model); + if (_iceCreamStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Update(PastryBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_iceCreamStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PastryBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_iceCreamStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PastryBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PastryName)) + { + throw new ArgumentNullException("Нет названия мороженого", nameof(model.PastryName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price)); + } + if (model.PastryComponents == null || model.PastryComponents.Count == 0) + { + throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); + } + _logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id); + var element = _iceCreamStorage.GetElement(new PastrySearchModel + { + PastryName = model.PastryName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Мороженое с таким названием уже есть"); + } } } } diff --git a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs index 03ed3c0..a57bac3 100644 --- a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs +++ b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace ConfectioneryListImplement.Implements { - internal class ComponentStorage : IComponentStorage + public class ComponentStorage : IComponentStorage { private readonly DataListSingleton _source; public ComponentStorage() diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj index 54e27de..9fd6be9 100644 --- a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index 7068cc9..c823733 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -11,12 +11,12 @@ namespace ConfectioneryListImplement.Models private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Pastrys { get; set; } + public List Pastries { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Pastrys = new List(); + Pastries = new List(); } public static DataListSingleton GetInstance() { diff --git a/Confectionery/ConfectioneryListImplement/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/OrderStorage.cs new file mode 100644 index 0000000..c4c13e2 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/OrderStorage.cs @@ -0,0 +1,122 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AddPastryName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AddPastryName(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return AddPastryName(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AddPastryName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddPastryName(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AddPastryName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AddPastryName(OrderViewModel model) + { + var selectedPastry = _source.Pastries.Find(pastry => pastry.Id == model.PastryId); + if (selectedPastry != null) + { + model.PastryName = selectedPastry.PastryName; + } + return model; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/PastryStorage.cs new file mode 100644 index 0000000..3231fe7 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/PastryStorage.cs @@ -0,0 +1,114 @@ +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.BindingModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class PastryStorage : IPastryStorage + { + private readonly DataListSingleton _source; + + public PastryStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var pastry in _source.Pastries) + { + result.Add(pastry.GetViewModel); + } + return result; + } + + public List GetFilteredList(PastrySearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PastryName)) + { + return result; + } + foreach (var pastry in _source.Pastries) + { + if (pastry.PastryName.Contains(model.PastryName)) + { + result.Add(pastry.GetViewModel); + } + } + return result; + } + + public PastryViewModel? GetElement(PastrySearchModel model) + { + if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue) + { + return null; + } + foreach (var pastry in _source.Pastries) + { + if ((!string.IsNullOrEmpty(model.PastryName) && + pastry.PastryName == model.PastryName) || + (model.Id.HasValue && pastry.Id == model.Id)) + { + return pastry.GetViewModel; + } + } + return null; + } + + public PastryViewModel? Insert(PastryBindingModel model) + { + model.Id = 1; + foreach (var pastry in _source.Pastries) + { + if (model.Id <= pastry.Id) + { + model.Id = pastry.Id + 1; + } + } + var newPastry = Pastry.Create(model); + if (newPastry == null) + { + return null; + } + _source.Pastries.Add(newPastry); + return newPastry.GetViewModel; + } + + public PastryViewModel? Update(PastryBindingModel model) + { + foreach (var pastry in _source.Pastries) + { + if (pastry.Id == model.Id) + { + pastry.Update(model); + return pastry.GetViewModel; + } + } + return null; + } + + public PastryViewModel? Delete(PastryBindingModel model) + { + for (int i = 0; i < _source.Pastries.Count; ++i) + { + if (_source.Pastries[i].Id == model.Id) + { + var element = _source.Pastries[i]; + _source.Pastries.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj index 55e33bf..0c70544 100644 --- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -19,6 +19,8 @@ + + diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 9f6753d..61c24bb 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -32,14 +32,14 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dataGridView = new System.Windows.Forms.DataGridView(); this.ButtonCreateOrder = new System.Windows.Forms.Button(); this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // // menuStrip1 @@ -67,22 +67,24 @@ this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // - // dataGridView1 + // dataGridView // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(13, 31); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersWidth = 51; - this.dataGridView1.RowTemplate.Height = 29; - this.dataGridView1.Size = new System.Drawing.Size(968, 526); - this.dataGridView1.TabIndex = 1; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(13, 31); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(968, 526); + this.dataGridView.TabIndex = 1; // // ButtonCreateOrder // @@ -144,7 +146,7 @@ this.Controls.Add(this.ButtonOrderReady); this.Controls.Add(this.ButtonTakeOrderInWork); this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "FormMain"; @@ -152,7 +154,7 @@ this.Load += new System.EventHandler(this.FormMain_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -164,7 +166,7 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; - private DataGridView dataGridView1; + private DataGridView dataGridView; private Button ButtonCreateOrder; private Button ButtonTakeOrderInWork; private Button ButtonOrderReady; diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index 02c0bf6..b6a28cf 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -31,8 +31,22 @@ namespace ConfectioneryView private void LoadData() { - _logger.LogInformation("Загрузка заказов"); - // прописать логику + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PastryId"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Orders loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Orders loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) @@ -47,7 +61,11 @@ namespace ConfectioneryView private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - // прописать логику + var service = Program.ServiceProvider?.GetService(typeof(FormPastries)); + if (service is FormPastries form) + { + form.ShowDialog(); + } } private void ButtonCreateOrder_Click(object sender, EventArgs e) diff --git a/Confectionery/ConfectioneryView/FormPastries.Designer.cs b/Confectionery/ConfectioneryView/FormPastries.Designer.cs new file mode 100644 index 0000000..d1f2fa9 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.Designer.cs @@ -0,0 +1,110 @@ +namespace ConfectioneryView +{ + partial class FormPastries + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(490, 426); + this.dataGridView.TabIndex = 0; + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(530, 94); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(111, 32); + this.ButtonUpd.TabIndex = 8; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(530, 163); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(111, 32); + this.ButtonDel.TabIndex = 7; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(530, 232); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(111, 32); + this.ButtonRef.TabIndex = 6; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(530, 26); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(111, 32); + this.ButtonAdd.TabIndex = 5; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + // + // FormPastries + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(670, 450); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormPastries"; + this.Text = "Выпечка"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs new file mode 100644 index 0000000..7932f5b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; + +namespace ConfectioneryView +{ + public partial class FormPastries : Form + { + private readonly ILogger _logger; + + private readonly IPastryLogic _logic; + public FormPastries(ILogger logger, IPastryLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormPastrys_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PastryComponents"].Visible = false; + } + _logger.LogInformation("Pastries loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Pastries loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); + if (service is FormPastry form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); + if (service is FormPastry form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of ice cream"); + try + { + if (!_logic.Delete(new PastryBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice cream deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormPastries.resx b/Confectionery/ConfectioneryView/FormPastries.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 575f8c6..cebaeea 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -1,4 +1,10 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace ConfectioneryView { @@ -15,7 +21,33 @@ namespace ConfectioneryView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormComponent()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 921039458979852a4df1210f918653cf61ecb650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 27 Feb 2024 23:07:55 +0400 Subject: [PATCH 07/14] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryBusinessLogic/PastryLogic.cs | 18 +++++----- .../FormCreateOrder.Designer.cs | 8 ++--- .../ConfectioneryView/FormCreateOrder.cs | 19 ++++++++-- .../ConfectioneryView/FormMain.Designer.cs | 30 ++++++++-------- Confectionery/ConfectioneryView/FormMain.cs | 6 ++-- Confectionery/ConfectioneryView/FormMain.resx | 5 ++- .../FormPastries.Designer.cs | 4 +++ .../ConfectioneryView/FormPastry.Designer.cs | 35 ++++++++++++++++++- .../ConfectioneryView/FormPastry.resx | 9 +++++ 9 files changed, 98 insertions(+), 36 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs index 781d3a1..549c7bd 100644 --- a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs @@ -16,18 +16,18 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { private readonly ILogger _logger; - private readonly IPastryStorage _iceCreamStorage; + private readonly IPastryStorage _pastryStorage; - public PastryLogic(ILogger logger, IPastryStorage iceCreamStorage) + public PastryLogic(ILogger logger, IPastryStorage pastryStorage) { _logger = logger; - _iceCreamStorage = iceCreamStorage; + _pastryStorage = pastryStorage; } public List? ReadList(PastrySearchModel? model) { _logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id); - var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model); + var list = model == null ? _pastryStorage.GetFullList() : _pastryStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -44,7 +44,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id); - var element = _iceCreamStorage.GetElement(model); + var element = _pastryStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -57,7 +57,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics public bool Create(PastryBindingModel model) { CheckModel(model); - if (_iceCreamStorage.Insert(model) == null) + if (_pastryStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -68,7 +68,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics public bool Update(PastryBindingModel model) { CheckModel(model); - if (_iceCreamStorage.Update(model) == null) + if (_pastryStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -80,7 +80,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_iceCreamStorage.Delete(model) == null) + if (_pastryStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -111,7 +111,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); } _logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id); - var element = _iceCreamStorage.GetElement(new PastrySearchModel + var element = _pastryStorage.GetElement(new PastrySearchModel { PastryName = model.PastryName }); diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs index 44040db..1e7a083 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -70,7 +70,7 @@ this.comboBoxPastry.FormattingEnabled = true; this.comboBoxPastry.Location = new System.Drawing.Point(150, 22); this.comboBoxPastry.Name = "comboBoxPastry"; - this.comboBoxPastry.Size = new System.Drawing.Size(337, 28); + this.comboBoxPastry.Size = new System.Drawing.Size(429, 28); this.comboBoxPastry.TabIndex = 3; this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPastry_SelectedIndexChanged); // @@ -78,7 +78,7 @@ // this.textBoxCount.Location = new System.Drawing.Point(150, 60); this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(337, 27); + this.textBoxCount.Size = new System.Drawing.Size(429, 27); this.textBoxCount.TabIndex = 4; this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); // @@ -86,7 +86,7 @@ // this.textBoxSum.Location = new System.Drawing.Point(150, 95); this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.Size = new System.Drawing.Size(337, 27); + this.textBoxSum.Size = new System.Drawing.Size(429, 27); this.textBoxSum.TabIndex = 5; // // ButtonSave @@ -113,7 +113,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(499, 180); + this.ClientSize = new System.Drawing.Size(591, 180); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonSave); this.Controls.Add(this.textBoxSum); diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index d49bc4d..16fe46e 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -29,8 +29,23 @@ namespace ConfectioneryView private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка изделий для заказа"); - // прописать логику + _logger.LogInformation("Loading ice cream for order"); + try + { + var pastryList = _logicP.ReadList(null); + if (pastryList != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = pastryList; + comboBoxPastry.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading ice cream for order"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() { diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 61c24bb..a1b389c 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -38,20 +38,20 @@ this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); + this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // - // menuStrip1 + // menuStrip // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1376, 28); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1376, 28); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip"; // // справочникиToolStripMenuItem // @@ -147,13 +147,13 @@ this.Controls.Add(this.ButtonTakeOrderInWork); this.Controls.Add(this.ButtonCreateOrder); this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; this.Name = "FormMain"; this.Text = "Кондитерская"; this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -162,7 +162,7 @@ #endregion - private MenuStrip menuStrip1; + private MenuStrip menuStrip; private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index b6a28cf..a2460ec 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -70,8 +70,7 @@ namespace ConfectioneryView private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -82,8 +81,7 @@ namespace ConfectioneryView { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { diff --git a/Confectionery/ConfectioneryView/FormMain.resx b/Confectionery/ConfectioneryView/FormMain.resx index 938108a..076b77c 100644 --- a/Confectionery/ConfectioneryView/FormMain.resx +++ b/Confectionery/ConfectioneryView/FormMain.resx @@ -57,7 +57,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + 25 + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastries.Designer.cs b/Confectionery/ConfectioneryView/FormPastries.Designer.cs index d1f2fa9..0fa90d8 100644 --- a/Confectionery/ConfectioneryView/FormPastries.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastries.Designer.cs @@ -54,6 +54,7 @@ this.ButtonUpd.TabIndex = 8; this.ButtonUpd.Text = "Изменить"; this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonEdit_Click); // // ButtonDel // @@ -63,6 +64,7 @@ this.ButtonDel.TabIndex = 7; this.ButtonDel.Text = "Удалить"; this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); // // ButtonRef // @@ -72,6 +74,7 @@ this.ButtonRef.TabIndex = 6; this.ButtonRef.Text = "Обновить"; this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonUpd_Click); // // ButtonAdd // @@ -81,6 +84,7 @@ this.ButtonAdd.TabIndex = 5; this.ButtonAdd.Text = "Добавить"; this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); // // FormPastries // diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index 196a105..13090a7 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -40,6 +40,9 @@ this.ButtonCancel = new System.Windows.Forms.Button(); this.labelName = new System.Windows.Forms.Label(); this.labelPrice = new System.Windows.Forms.Label(); + this.Number = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.groupBox.SuspendLayout(); this.SuspendLayout(); @@ -61,6 +64,10 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Number, + this.Component, + this.Count}); this.dataGridView.Location = new System.Drawing.Point(6, 26); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; @@ -160,6 +167,28 @@ this.labelPrice.TabIndex = 10; this.labelPrice.Text = "Стоимость:"; // + // Number + // + this.Number.HeaderText = "Номер"; + this.Number.MinimumWidth = 6; + this.Number.Name = "Number"; + this.Number.Visible = false; + this.Number.Width = 125; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.Width = 125; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // // FormPastry // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -173,7 +202,8 @@ this.Controls.Add(this.textBoxPrice); this.Controls.Add(this.textBoxName); this.Name = "FormPastry"; - this.Text = "FormPastry"; + this.Text = "Выпечка"; + this.Load += new System.EventHandler(this.FormPastry_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.groupBox.ResumeLayout(false); this.ResumeLayout(false); @@ -195,5 +225,8 @@ private Button ButtonCancel; private Label labelName; private Label labelPrice; + private DataGridViewTextBoxColumn Number; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastry.resx b/Confectionery/ConfectioneryView/FormPastry.resx index f298a7b..ac1ce00 100644 --- a/Confectionery/ConfectioneryView/FormPastry.resx +++ b/Confectionery/ConfectioneryView/FormPastry.resx @@ -57,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + \ No newline at end of file -- 2.25.1 From deef66e3fc32d68dc01461d690395369a2ebd72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 28 Feb 2024 10:03:27 +0400 Subject: [PATCH 08/14] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryBusinessLogic/OrderLogic.cs | 4 +- .../ConfectioneryBusinessLogic/PastryLogic.cs | 8 +-- .../ConfectioneryListImplement/Order.cs | 43 ++++++++++++---- .../FormCreateOrder.Designer.cs | 1 + .../ConfectioneryView/FormPastry.Designer.cs | 51 ++++++++++--------- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs index 939b321..a9f668d 100644 --- a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs @@ -82,11 +82,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (model.PastryId <= 0) { - throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.PastryId)); + throw new ArgumentNullException("Некорректный идентификатор выпечки", nameof(model.PastryId)); } if (model.Count <= 0) { - throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count)); + throw new ArgumentNullException("В заказе должно быть хотя бы одна выпечка", nameof(model.Count)); } if (model.Sum <= 0) { diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs index 549c7bd..e356da6 100644 --- a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs @@ -100,15 +100,15 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.PastryName)) { - throw new ArgumentNullException("Нет названия мороженого", nameof(model.PastryName)); + throw new ArgumentNullException("Нет названия выпечки", nameof(model.PastryName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена выпечки должна быть больше 0", nameof(model.Price)); } if (model.PastryComponents == null || model.PastryComponents.Count == 0) { - throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); + throw new ArgumentNullException("Выпечка должна состоять хотя бы из одного компонента"); } _logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id); var element = _pastryStorage.GetElement(new PastrySearchModel @@ -117,7 +117,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Мороженое с таким названием уже есть"); + throw new InvalidOperationException("Выпечка с таким названием уже есть"); } } } diff --git a/Confectionery/ConfectioneryListImplement/Order.cs b/Confectionery/ConfectioneryListImplement/Order.cs index b35f396..7f0cb44 100644 --- a/Confectionery/ConfectioneryListImplement/Order.cs +++ b/Confectionery/ConfectioneryListImplement/Order.cs @@ -12,32 +12,57 @@ namespace ConfectioneryListImplement { internal class Order : IOrderModel { - public int PastryId => throw new NotImplementedException(); + public int Id { get; private set; } - public int Count => throw new NotImplementedException(); + public int PastryId { get; private set; } - public double Sum => throw new NotImplementedException(); + public int Count { get; private set; } - public OrderStatus Status => throw new NotImplementedException(); + public double Sum { get; private set; } - public DateTime DateCreate => throw new NotImplementedException(); + public OrderStatus Status { get; private set; } - public DateTime? DateImplement => throw new NotImplementedException(); + public DateTime DateCreate { get; private set; } - public int Id => throw new NotImplementedException(); + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { - return new Order(); + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; } public void Update(OrderBindingModel? model) { - + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { + Id = Id, + PastryId = PastryId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement }; } } diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs index 1e7a083..5ecf40e 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -84,6 +84,7 @@ // // textBoxSum // + this.textBoxSum.Enabled = false; this.textBoxSum.Location = new System.Drawing.Point(150, 95); this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.Size = new System.Drawing.Size(429, 27); diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index 13090a7..722b427 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -31,6 +31,9 @@ this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxPrice = new System.Windows.Forms.TextBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Number = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox = new System.Windows.Forms.GroupBox(); this.ButtonRef = new System.Windows.Forms.Button(); this.ButtonDel = new System.Windows.Forms.Button(); @@ -40,9 +43,6 @@ this.ButtonCancel = new System.Windows.Forms.Button(); this.labelName = new System.Windows.Forms.Label(); this.labelPrice = new System.Windows.Forms.Label(); - this.Number = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.groupBox.SuspendLayout(); this.SuspendLayout(); @@ -56,6 +56,7 @@ // // textBoxPrice // + this.textBoxPrice.Enabled = false; this.textBoxPrice.Location = new System.Drawing.Point(204, 64); this.textBoxPrice.Name = "textBoxPrice"; this.textBoxPrice.Size = new System.Drawing.Size(125, 27); @@ -75,6 +76,28 @@ this.dataGridView.Size = new System.Drawing.Size(422, 297); this.dataGridView.TabIndex = 2; // + // Number + // + this.Number.HeaderText = "Номер"; + this.Number.MinimumWidth = 6; + this.Number.Name = "Number"; + this.Number.Visible = false; + this.Number.Width = 125; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.Width = 125; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // // groupBox // this.groupBox.Controls.Add(this.ButtonRef); @@ -167,28 +190,6 @@ this.labelPrice.TabIndex = 10; this.labelPrice.Text = "Стоимость:"; // - // Number - // - this.Number.HeaderText = "Номер"; - this.Number.MinimumWidth = 6; - this.Number.Name = "Number"; - this.Number.Visible = false; - this.Number.Width = 125; - // - // Component - // - this.Component.HeaderText = "Компонент"; - this.Component.MinimumWidth = 6; - this.Component.Name = "Component"; - this.Component.Width = 125; - // - // Count - // - this.Count.HeaderText = "Количество"; - this.Count.MinimumWidth = 6; - this.Count.Name = "Count"; - this.Count.Width = 125; - // // FormPastry // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); -- 2.25.1 From 47e2bc50b85f6383b811d1e1630c8c9d9ae1c6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 9 Mar 2024 14:46:08 +0400 Subject: [PATCH 09/14] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/Confectionery.sln | 10 +- .../ConfectioneryFileImplement/Component.cs | 60 +++++++++++ .../ConfectioneryFileImplement.csproj | 14 +++ .../DataFileSilgleton.cs | 61 +++++++++++ .../ConfectioneryFileImplement/Pastry.cs | 102 ++++++++++++++++++ .../ConfectioneryListImplement/Component.cs | 2 +- .../ConfectioneryView/FormCreateOrder.cs | 4 +- 7 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 Confectionery/ConfectioneryFileImplement/Component.cs create mode 100644 Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj create mode 100644 Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs create mode 100644 Confectionery/ConfectioneryFileImplement/Pastry.cs diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index a7f5d85..6079332 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -9,9 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectionaryContracts\ConfectioneryContracts.csproj", "{4BC782E2-5108-4C55-9F76-ACE5A56B8735}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{2822ACD8-8B94-4BF2-8C55-478677FDD1FE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{2822ACD8-8B94-4BF2-8C55-478677FDD1FE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{EE30482F-8998-4178-8412-421A02F6A6B4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{EE30482F-8998-4178-8412-421A02F6A6B4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryFileImplement", "ConfectioneryFileImplement\ConfectioneryFileImplement.csproj", "{89C5A160-FB85-4D56-AFD7-506CC6005080}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {EE30482F-8998-4178-8412-421A02F6A6B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.Build.0 = Release|Any CPU + {89C5A160-FB85-4D56-AFD7-506CC6005080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89C5A160-FB85-4D56-AFD7-506CC6005080}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89C5A160-FB85-4D56-AFD7-506CC6005080}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89C5A160-FB85-4D56-AFD7-506CC6005080}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryFileImplement/Component.cs b/Confectionery/ConfectioneryFileImplement/Component.cs new file mode 100644 index 0000000..63e6867 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/Component.cs @@ -0,0 +1,60 @@ +using System.ComponentModel; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System.Xml.Linq; + +namespace ConfectioneryFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj b/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj new file mode 100644 index 0000000..54e27de --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs b/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs new file mode 100644 index 0000000..06fb502 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs @@ -0,0 +1,61 @@ +using ConfectioneryFileImplement.Models; +using System.Xml.Linq; + +namespace PastryShopFileImplement +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + + private readonly string ComponentFileName = "Component.xml"; + + private readonly string OrderFileName = "Order.xml"; + + private readonly string PastryFileName = "Pastry.xml"; + + public List Components { get; private set; } + + public List Orders { get; private set; } + + public List Pastrys { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + + public void SavePastrys() => SaveData(Pastrys, PastryFileName, "Pastrys", x => x.GetXElement); + + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/Confectionery/ConfectioneryFileImplement/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Pastry.cs new file mode 100644 index 0000000..20602d5 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/Pastry.cs @@ -0,0 +1,102 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; + + +namespace ConfectioneryFileImplement.Models +{ + public class Pastry : IPastryModel + { + public int Id { get; private set; } + public string PastryName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _PastryComponents = + null; + public Dictionary PastryComponents + { + get + { + if (_PastryComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _PastryComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _PastryComponents; + } + } + public static Pastry? Create(PastryBindingModel model) + { + if (model == null) + { + return null; + } + return new Pastry() + { + Id = model.Id, + PastryName = model.PastryName, + Price = model.Price, + Components = model.PastryComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Pastry? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Pastry() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PastryName = element.Element("PastryName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = +element.Element("PastryComponents")!.Elements("PastryComponent") + .ToDictionary(x => +Convert.ToInt32(x.Element("Key")?.Value), x => +Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(PastryBindingModel model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + Components = model.PastryComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _PastryComponents = null; + } + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryComponents = PastryComponents + }; + public XElement GetXElement => new("Pastry", + new XAttribute("Id", Id), + new XElement("PastryName", PastryName), + new XElement("Price", Price.ToString()), + new XElement("PastryComponents", Components.Select(x => + new XElement("PastryComponent", + + new XElement("Key", x.Key), + + new XElement("Value", x.Value))) + + .ToArray())); + + } +} diff --git a/Confectionery/ConfectioneryListImplement/Component.cs b/Confectionery/ConfectioneryListImplement/Component.cs index 9683495..0602b42 100644 --- a/Confectionery/ConfectioneryListImplement/Component.cs +++ b/Confectionery/ConfectioneryListImplement/Component.cs @@ -44,4 +44,4 @@ namespace ConfectioneryListImplement.Models }; } -} +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index 16fe46e..df0fee5 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -55,12 +55,12 @@ namespace ConfectioneryView try { int id = Convert.ToInt32(comboBoxPastry.SelectedValue); - var product = _logicP.ReadElement(new PastrySearchModel + var Pastry = _logicP.ReadElement(new PastrySearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + textBoxSum.Text = Math.Round(count * (Pastry?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } -- 2.25.1 From 0fda2353bc0074755b4c276550454d4ef4267939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 9 Mar 2024 14:59:05 +0400 Subject: [PATCH 10/14] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/Confectionery.sln | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 6079332..5b7648e 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryBusinessLogic" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{EE30482F-8998-4178-8412-421A02F6A6B4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryFileImplement", "ConfectioneryFileImplement\ConfectioneryFileImplement.csproj", "{89C5A160-FB85-4D56-AFD7-506CC6005080}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,10 +39,6 @@ Global {EE30482F-8998-4178-8412-421A02F6A6B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE30482F-8998-4178-8412-421A02F6A6B4}.Release|Any CPU.Build.0 = Release|Any CPU - {89C5A160-FB85-4D56-AFD7-506CC6005080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {89C5A160-FB85-4D56-AFD7-506CC6005080}.Debug|Any CPU.Build.0 = Debug|Any CPU - {89C5A160-FB85-4D56-AFD7-506CC6005080}.Release|Any CPU.ActiveCfg = Release|Any CPU - {89C5A160-FB85-4D56-AFD7-506CC6005080}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From 35d827619061bd8acfb4a7796ce2a58cf5c37fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 12 Mar 2024 21:04:18 +0400 Subject: [PATCH 11/14] =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectionaryContracts/ViewModels/OrderViewModel.cs | 2 +- .../ConfectionaryContracts/ViewModels/PastryViewModel.cs | 2 +- .../ConfectionaryDataModels/{ => Enums}/OrderStatus.cs | 0 Confectionery/ConfectionaryDataModels/Iid.cs | 2 +- .../ConfectionaryDataModels/{ => Models}/IComponentModel.cs | 2 +- .../ConfectionaryDataModels/{ => Models}/IOrderModel.cs | 2 +- .../ConfectionaryDataModels/{ => Models}/IPastryModel.cs | 2 +- .../{ => BusinessLogics}/ComponentLogic.cs | 0 .../{ => BusinessLogics}/OrderLogic.cs | 0 .../{ => BusinessLogics}/PastryLogic.cs | 0 .../{ => Implements}/ComponentStorage.cs | 0 .../{ => Implements}/OrderStorage.cs | 0 .../{ => Implements}/PastryStorage.cs | 0 .../ConfectioneryListImplement/{ => Models}/Component.cs | 0 .../ConfectioneryListImplement/{ => Models}/Order.cs | 2 +- .../ConfectioneryListImplement/{ => Models}/Pastry.cs | 0 Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs | 2 +- Confectionery/ConfectioneryView/FormCreateOrder.cs | 6 +++--- 18 files changed, 11 insertions(+), 11 deletions(-) rename Confectionery/ConfectionaryDataModels/{ => Enums}/OrderStatus.cs (100%) rename Confectionery/ConfectionaryDataModels/{ => Models}/IComponentModel.cs (85%) rename Confectionery/ConfectionaryDataModels/{ => Models}/IOrderModel.cs (91%) rename Confectionery/ConfectionaryDataModels/{ => Models}/IPastryModel.cs (88%) rename Confectionery/ConfectioneryBusinessLogic/{ => BusinessLogics}/ComponentLogic.cs (100%) rename Confectionery/ConfectioneryBusinessLogic/{ => BusinessLogics}/OrderLogic.cs (100%) rename Confectionery/ConfectioneryBusinessLogic/{ => BusinessLogics}/PastryLogic.cs (100%) rename Confectionery/ConfectioneryListImplement/{ => Implements}/ComponentStorage.cs (100%) rename Confectionery/ConfectioneryListImplement/{ => Implements}/OrderStorage.cs (100%) rename Confectionery/ConfectioneryListImplement/{ => Implements}/PastryStorage.cs (100%) rename Confectionery/ConfectioneryListImplement/{ => Models}/Component.cs (100%) rename Confectionery/ConfectioneryListImplement/{ => Models}/Order.cs (97%) rename Confectionery/ConfectioneryListImplement/{ => Models}/Pastry.cs (100%) diff --git a/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs index d0d6367..679b9f0 100644 --- a/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/ConfectionaryContracts/ViewModels/OrderViewModel.cs @@ -14,7 +14,7 @@ namespace ConfectioneryContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int PastryId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Выпечка")] public string PastryName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs index 4eea8da..11fc7c4 100644 --- a/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs +++ b/Confectionery/ConfectionaryContracts/ViewModels/PastryViewModel.cs @@ -11,7 +11,7 @@ namespace ConfectioneryContracts.ViewModels public class PastryViewModel : IPastryModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("Название визделия")] public string PastryName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } diff --git a/Confectionery/ConfectionaryDataModels/OrderStatus.cs b/Confectionery/ConfectionaryDataModels/Enums/OrderStatus.cs similarity index 100% rename from Confectionery/ConfectionaryDataModels/OrderStatus.cs rename to Confectionery/ConfectionaryDataModels/Enums/OrderStatus.cs diff --git a/Confectionery/ConfectionaryDataModels/Iid.cs b/Confectionery/ConfectionaryDataModels/Iid.cs index 1c4791e..fc8cada 100644 --- a/Confectionery/ConfectionaryDataModels/Iid.cs +++ b/Confectionery/ConfectionaryDataModels/Iid.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels { - public interface Iid + public interface IId { int Id { get; } } diff --git a/Confectionery/ConfectionaryDataModels/IComponentModel.cs b/Confectionery/ConfectionaryDataModels/Models/IComponentModel.cs similarity index 85% rename from Confectionery/ConfectionaryDataModels/IComponentModel.cs rename to Confectionery/ConfectionaryDataModels/Models/IComponentModel.cs index bfba2c6..534429e 100644 --- a/Confectionery/ConfectionaryDataModels/IComponentModel.cs +++ b/Confectionery/ConfectionaryDataModels/Models/IComponentModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IComponentModel : Iid + public interface IComponentModel : IId { string ComponentName { get; } double Cost { get; } diff --git a/Confectionery/ConfectionaryDataModels/IOrderModel.cs b/Confectionery/ConfectionaryDataModels/Models/IOrderModel.cs similarity index 91% rename from Confectionery/ConfectionaryDataModels/IOrderModel.cs rename to Confectionery/ConfectionaryDataModels/Models/IOrderModel.cs index fed83f2..40e889f 100644 --- a/Confectionery/ConfectionaryDataModels/IOrderModel.cs +++ b/Confectionery/ConfectionaryDataModels/Models/IOrderModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IOrderModel : Iid + public interface IOrderModel : IId { int PastryId { get; } int Count { get; } diff --git a/Confectionery/ConfectionaryDataModels/IPastryModel.cs b/Confectionery/ConfectionaryDataModels/Models/IPastryModel.cs similarity index 88% rename from Confectionery/ConfectionaryDataModels/IPastryModel.cs rename to Confectionery/ConfectionaryDataModels/Models/IPastryModel.cs index 7ac7324..004216d 100644 --- a/Confectionery/ConfectionaryDataModels/IPastryModel.cs +++ b/Confectionery/ConfectionaryDataModels/Models/IPastryModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IPastryModel : Iid + public interface IPastryModel : IId { string PastryName { get; } double Price { get; } diff --git a/Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs similarity index 100% rename from Confectionery/ConfectioneryBusinessLogic/ComponentLogic.cs rename to Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs similarity index 100% rename from Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs rename to Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs similarity index 100% rename from Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs rename to Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs diff --git a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs similarity index 100% rename from Confectionery/ConfectioneryListImplement/ComponentStorage.cs rename to Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs diff --git a/Confectionery/ConfectioneryListImplement/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs similarity index 100% rename from Confectionery/ConfectioneryListImplement/OrderStorage.cs rename to Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs diff --git a/Confectionery/ConfectioneryListImplement/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs similarity index 100% rename from Confectionery/ConfectioneryListImplement/PastryStorage.cs rename to Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs diff --git a/Confectionery/ConfectioneryListImplement/Component.cs b/Confectionery/ConfectioneryListImplement/Models/Component.cs similarity index 100% rename from Confectionery/ConfectioneryListImplement/Component.cs rename to Confectionery/ConfectioneryListImplement/Models/Component.cs diff --git a/Confectionery/ConfectioneryListImplement/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs similarity index 97% rename from Confectionery/ConfectioneryListImplement/Order.cs rename to Confectionery/ConfectioneryListImplement/Models/Order.cs index 7f0cb44..82d0fda 100644 --- a/Confectionery/ConfectioneryListImplement/Order.cs +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryListImplement +namespace ConfectioneryListImplement.Models { internal class Order : IOrderModel { diff --git a/Confectionery/ConfectioneryListImplement/Pastry.cs b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs similarity index 100% rename from Confectionery/ConfectioneryListImplement/Pastry.cs rename to Confectionery/ConfectioneryListImplement/Models/Pastry.cs diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs index 5ecf40e..eb66979 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -45,7 +45,7 @@ this.labelPastry.Name = "labelPastry"; this.labelPastry.Size = new System.Drawing.Size(71, 20); this.labelPastry.TabIndex = 0; - this.labelPastry.Text = "Изделие:"; + this.labelPastry.Text = "Выпечка:"; // // labelCount // diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index 16fe46e..a448d9b 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -55,12 +55,12 @@ namespace ConfectioneryView try { int id = Convert.ToInt32(comboBoxPastry.SelectedValue); - var product = _logicP.ReadElement(new PastrySearchModel + var pastry = _logicP.ReadElement(new PastrySearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + textBoxSum.Text = Math.Round(count * (pastry?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } @@ -91,7 +91,7 @@ namespace ConfectioneryView } if (comboBoxPastry.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", + MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } -- 2.25.1 From 851a875b0865cf7388d9deb33c5f933c4248ba78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 13 Mar 2024 10:15:47 +0400 Subject: [PATCH 12/14] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=87=D1=82=D0=BE-=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryFileImplement/Component.cs | 60 ----------- .../ConfectioneryFileImplement.csproj | 14 --- .../DataFileSilgleton.cs | 61 ----------- .../ConfectioneryFileImplement/Pastry.cs | 102 ------------------ 4 files changed, 237 deletions(-) delete mode 100644 Confectionery/ConfectioneryFileImplement/Component.cs delete mode 100644 Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj delete mode 100644 Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs delete mode 100644 Confectionery/ConfectioneryFileImplement/Pastry.cs diff --git a/Confectionery/ConfectioneryFileImplement/Component.cs b/Confectionery/ConfectioneryFileImplement/Component.cs deleted file mode 100644 index 63e6867..0000000 --- a/Confectionery/ConfectioneryFileImplement/Component.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.ComponentModel; -using ConfectioneryContracts.BindingModels; -using ConfectioneryContracts.ViewModels; -using ConfectioneryDataModels.Models; -using System.Xml.Linq; - -namespace ConfectioneryFileImplement.Models -{ - public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } - public static Component? Create(ComponentBindingModel model) - { - if (model == null) - { - return null; - } - return new Component() - { - Id = model.Id, - ComponentName = model.ComponentName, - Cost = model.Cost - }; - } - public static Component? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Component() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ComponentName = element.Element("ComponentName")!.Value, - Cost = Convert.ToDouble(element.Element("Cost")!.Value) - }; - } - public void Update(ComponentBindingModel model) - { - if (model == null) - { - return; - } - ComponentName = model.ComponentName; - Cost = model.Cost; - } - public ComponentViewModel GetViewModel => new() - { - Id = Id, - ComponentName = ComponentName, - Cost = Cost - }; - public XElement GetXElement => new("Component", - new XAttribute("Id", Id), - new XElement("ComponentName", ComponentName), - new XElement("Cost", Cost.ToString())); - } -} \ No newline at end of file diff --git a/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj b/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj deleted file mode 100644 index 54e27de..0000000 --- a/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - diff --git a/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs b/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs deleted file mode 100644 index 06fb502..0000000 --- a/Confectionery/ConfectioneryFileImplement/DataFileSilgleton.cs +++ /dev/null @@ -1,61 +0,0 @@ -using ConfectioneryFileImplement.Models; -using System.Xml.Linq; - -namespace PastryShopFileImplement -{ - internal class DataFileSingleton - { - private static DataFileSingleton? instance; - - private readonly string ComponentFileName = "Component.xml"; - - private readonly string OrderFileName = "Order.xml"; - - private readonly string PastryFileName = "Pastry.xml"; - - public List Components { get; private set; } - - public List Orders { get; private set; } - - public List Pastrys { get; private set; } - - public static DataFileSingleton GetInstance() - { - if (instance == null) - { - instance = new DataFileSingleton(); - } - return instance; - } - - public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - - public void SavePastrys() => SaveData(Pastrys, PastryFileName, "Pastrys", x => x.GetXElement); - - public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - - private DataFileSingleton() - { - Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; - Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } - - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) - { - if (File.Exists(filename)) - { - return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); - } - return new List(); - } - - private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) - { - if (data != null) - { - new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); - } - } - } -} diff --git a/Confectionery/ConfectioneryFileImplement/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Pastry.cs deleted file mode 100644 index 20602d5..0000000 --- a/Confectionery/ConfectioneryFileImplement/Pastry.cs +++ /dev/null @@ -1,102 +0,0 @@ -using ConfectioneryDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using ConfectioneryContracts.BindingModels; -using ConfectioneryContracts.ViewModels; - - -namespace ConfectioneryFileImplement.Models -{ - public class Pastry : IPastryModel - { - public int Id { get; private set; } - public string PastryName { get; private set; } = string.Empty; - public double Price { get; private set; } - public Dictionary Components { get; private set; } = new(); - private Dictionary? _PastryComponents = - null; - public Dictionary PastryComponents - { - get - { - if (_PastryComponents == null) - { - var source = DataFileSingleton.GetInstance(); - _PastryComponents = Components.ToDictionary(x => x.Key, y => - ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, - y.Value)); - } - return _PastryComponents; - } - } - public static Pastry? Create(PastryBindingModel model) - { - if (model == null) - { - return null; - } - return new Pastry() - { - Id = model.Id, - PastryName = model.PastryName, - Price = model.Price, - Components = model.PastryComponents.ToDictionary(x => x.Key, x - => x.Value.Item2) - }; - } - public static Pastry? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Pastry() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - PastryName = element.Element("PastryName")!.Value, - Price = Convert.ToDouble(element.Element("Price")!.Value), - Components = -element.Element("PastryComponents")!.Elements("PastryComponent") - .ToDictionary(x => -Convert.ToInt32(x.Element("Key")?.Value), x => -Convert.ToInt32(x.Element("Value")?.Value)) - }; - } - public void Update(PastryBindingModel model) - { - if (model == null) - { - return; - } - PastryName = model.PastryName; - Price = model.Price; - Components = model.PastryComponents.ToDictionary(x => x.Key, x => - x.Value.Item2); - _PastryComponents = null; - } - public PastryViewModel GetViewModel => new() - { - Id = Id, - PastryName = PastryName, - Price = Price, - PastryComponents = PastryComponents - }; - public XElement GetXElement => new("Pastry", - new XAttribute("Id", Id), - new XElement("PastryName", PastryName), - new XElement("Price", Price.ToString()), - new XElement("PastryComponents", Components.Select(x => - new XElement("PastryComponent", - - new XElement("Key", x.Key), - - new XElement("Value", x.Value))) - - .ToArray())); - - } -} -- 2.25.1 From 8a3ae4c156e4d3ea74389e02261d83dfbec3c9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 15:56:04 +0400 Subject: [PATCH 13/14] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/ConfectioneryView/FormComponent.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs index 417103e..821c06c 100644 --- a/Confectionery/ConfectioneryView/FormComponent.Designer.cs +++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs @@ -100,7 +100,7 @@ this.Controls.Add(this.labelCost); this.Controls.Add(this.labelName); this.Name = "FormComponent"; - this.Text = "FormComponent"; + this.Text = "Компонент"; this.Load += new System.EventHandler(this.FormComponent_Load); this.ResumeLayout(false); this.PerformLayout(); -- 2.25.1 From d23e3cc9f643caf097fa562491cb91fd41118fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 20 Apr 2024 16:52:17 +0400 Subject: [PATCH 14/14] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/ConfectioneryView/FormCreateOrder.cs | 4 ++-- Confectionery/ConfectioneryView/FormPastries.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index a448d9b..b903b1b 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -29,7 +29,7 @@ namespace ConfectioneryView private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Loading ice cream for order"); + _logger.LogInformation("Loading pastry for order"); try { var pastryList = _logicP.ReadList(null); @@ -43,7 +43,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Error during loading ice cream for order"); + _logger.LogError(ex, "Error during loading pastry for order"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs index 7932f5b..508f6cc 100644 --- a/Confectionery/ConfectioneryView/FormPastries.cs +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -86,7 +86,7 @@ namespace ConfectioneryView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Deletion of ice cream"); + _logger.LogInformation("Deletion of pastry"); try { if (!_logic.Delete(new PastryBindingModel { Id = id })) @@ -97,7 +97,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ice cream deletion error"); + _logger.LogError(ex, "Pastry deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } -- 2.25.1