From 67538380e35d9c72f536cc4a952b2ac7736023c9 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 4 Feb 2023 21:31:11 +0400 Subject: [PATCH 01/26] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B9=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractShopDataModels.sln | 25 ++++++++++++++++++ .../AbstractShopDataModels.csproj | 9 +++++++ .../AbstractShopDataModels/IComponentModel.cs | 12 +++++++++ .../AbstractShopDataModels/IId.cs | 8 ++++++ .../AbstractShopDataModels/IOrderModel.cs | 26 +++++++++++++++++++ .../AbstractShopDataModels/IProductModel.cs | 21 +++++++++++++++ .../AbstractShopDataModels/OrderStatus.cs | 16 ++++++++++++ 7 files changed, 117 insertions(+) create mode 100644 AbstractShopDataModels/AbstractShopDataModels.sln create mode 100644 AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj create mode 100644 AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs create mode 100644 AbstractShopDataModels/AbstractShopDataModels/IId.cs create mode 100644 AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs create mode 100644 AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs create mode 100644 AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs diff --git a/AbstractShopDataModels/AbstractShopDataModels.sln b/AbstractShopDataModels/AbstractShopDataModels.sln new file mode 100644 index 0000000..01b71de --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33103.184 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopDataModels", "AbstractShopDataModels\AbstractShopDataModels.csproj", "{7388459F-91DB-40D9-8999-500015301160}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7388459F-91DB-40D9-8999-500015301160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7388459F-91DB-40D9-8999-500015301160}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7388459F-91DB-40D9-8999-500015301160}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7388459F-91DB-40D9-8999-500015301160}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {60688C9E-4871-4357-A48F-63718AD0FA65} + EndGlobalSection +EndGlobal diff --git a/AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj b/AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs b/AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs new file mode 100644 index 0000000..163b553 --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs @@ -0,0 +1,12 @@ +namespace AbstractShopDataModels +{ + //интерфейс, отвечающий за компоненты + internal interface IComponentModel : IId + { + //название составляющей (изделие состоит из составляющих) + string ComponentName { get; } + + //цена составляющей + double Cost { get; } + } +} diff --git a/AbstractShopDataModels/AbstractShopDataModels/IId.cs b/AbstractShopDataModels/AbstractShopDataModels/IId.cs new file mode 100644 index 0000000..3107c32 --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/IId.cs @@ -0,0 +1,8 @@ +namespace AbstractShopDataModels +{ + //интерфейс, отвечающий за id у компонентов, продуктов и чеков + internal interface IId + { + int Id { get; } + } +} diff --git a/AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs b/AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs new file mode 100644 index 0000000..96b2fb4 --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs @@ -0,0 +1,26 @@ +using AbstractShopDataModels.Enums; + +namespace AbstractShopDataModels +{ + //интерфейс, отвечающий за чек + internal interface IOrderModel : IId + { + //id продукта + int ProductId { get; } + + //кол-во продуктов + int Count { get; } + + //суммарная стоимость продуктов + double Sum { get; } + + //статус заказа + OrderStatus Status { get; } + + //дата создания заказа + DateTime DateCreate { get; } + + //дата завершения заказа (не обязательна к указанию сразу) + DateTime? DateImplement { get; } + } +} diff --git a/AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs b/AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs new file mode 100644 index 0000000..dfd51f8 --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopDataModels +{ + //интерфейс, отвечающий за продукт + internal interface IProductModel : IId + { + //наименование изделия + string ProductName { get; } + + //цена изделия + double Price { get; } + + //словарь, хранящий пары кол-во + компонент и его цена + Dictionary ProductComponents { get; } + } +} diff --git a/AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs b/AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs new file mode 100644 index 0000000..863259d --- /dev/null +++ b/AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs @@ -0,0 +1,16 @@ +namespace AbstractShopDataModels.Enums +{ + //статус заказа + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} \ No newline at end of file -- 2.25.1 From 82f11ec29bc4ccdbac4a338d6460c929db2d1250 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 17:44:46 +0400 Subject: [PATCH 02/26] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractShopDataModels.sln | 25 ------------------- BlacksmithWorkshop/BlacksmithWorkshop.sln | 8 +++++- .../BlacksmithWorkshopDataModels.csproj | 0 .../IComponentModel.cs | 8 +++++- .../BlacksmithWorkshopDataModels}/IId.cs | 10 ++++++-- .../IOrderModel.cs | 9 +++++-- .../IProductModel.cs | 2 +- .../OrderStatus.cs | 8 +++++- 8 files changed, 37 insertions(+), 33 deletions(-) delete mode 100644 AbstractShopDataModels/AbstractShopDataModels.sln rename AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj => BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj (100%) rename {AbstractShopDataModels/AbstractShopDataModels => BlacksmithWorkshop/BlacksmithWorkshopDataModels}/IComponentModel.cs (69%) rename {AbstractShopDataModels/AbstractShopDataModels => BlacksmithWorkshop/BlacksmithWorkshopDataModels}/IId.cs (52%) rename {AbstractShopDataModels/AbstractShopDataModels => BlacksmithWorkshop/BlacksmithWorkshopDataModels}/IOrderModel.cs (76%) rename {AbstractShopDataModels/AbstractShopDataModels => BlacksmithWorkshop/BlacksmithWorkshopDataModels}/IProductModel.cs (93%) rename {AbstractShopDataModels/AbstractShopDataModels => BlacksmithWorkshop/BlacksmithWorkshopDataModels}/OrderStatus.cs (57%) diff --git a/AbstractShopDataModels/AbstractShopDataModels.sln b/AbstractShopDataModels/AbstractShopDataModels.sln deleted file mode 100644 index 01b71de..0000000 --- a/AbstractShopDataModels/AbstractShopDataModels.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33103.184 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopDataModels", "AbstractShopDataModels\AbstractShopDataModels.csproj", "{7388459F-91DB-40D9-8999-500015301160}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7388459F-91DB-40D9-8999-500015301160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7388459F-91DB-40D9-8999-500015301160}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7388459F-91DB-40D9-8999-500015301160}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7388459F-91DB-40D9-8999-500015301160}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {60688C9E-4871-4357-A48F-63718AD0FA65} - EndGlobalSection -EndGlobal diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 6d9e398..496ab40 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33103.184 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{FEF2DC94-D11E-4D77-9F59-5B89A09D0996}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{FEF2DC94-D11E-4D77-9F59-5B89A09D0996}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {FEF2DC94-D11E-4D77-9F59-5B89A09D0996}.Debug|Any CPU.Build.0 = Debug|Any CPU {FEF2DC94-D11E-4D77-9F59-5B89A09D0996}.Release|Any CPU.ActiveCfg = Release|Any CPU {FEF2DC94-D11E-4D77-9F59-5B89A09D0996}.Release|Any CPU.Build.0 = Release|Any CPU + {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj similarity index 100% rename from AbstractShopDataModels/AbstractShopDataModels/AbstractShopDataModels.csproj rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj diff --git a/AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs similarity index 69% rename from AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs index 163b553..ab386fb 100644 --- a/AbstractShopDataModels/AbstractShopDataModels/IComponentModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs @@ -1,4 +1,10 @@ -namespace AbstractShopDataModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels { //интерфейс, отвечающий за компоненты internal interface IComponentModel : IId diff --git a/AbstractShopDataModels/AbstractShopDataModels/IId.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs similarity index 52% rename from AbstractShopDataModels/AbstractShopDataModels/IId.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs index 3107c32..b6ba8b7 100644 --- a/AbstractShopDataModels/AbstractShopDataModels/IId.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs @@ -1,8 +1,14 @@ -namespace AbstractShopDataModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels { //интерфейс, отвечающий за id у компонентов, продуктов и чеков internal interface IId { int Id { get; } } -} +} \ No newline at end of file diff --git a/AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs similarity index 76% rename from AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs index 96b2fb4..5a9adb0 100644 --- a/AbstractShopDataModels/AbstractShopDataModels/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs @@ -1,6 +1,11 @@ -using AbstractShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopDataModels.Enums; -namespace AbstractShopDataModels +namespace BlacksmithWorkshopDataModels { //интерфейс, отвечающий за чек internal interface IOrderModel : IId diff --git a/AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs similarity index 93% rename from AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs index dfd51f8..93cf815 100644 --- a/AbstractShopDataModels/AbstractShopDataModels/IProductModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractShopDataModels +namespace BlacksmithWorkshopDataModels { //интерфейс, отвечающий за продукт internal interface IProductModel : IId diff --git a/AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/OrderStatus.cs similarity index 57% rename from AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/OrderStatus.cs index 863259d..293d304 100644 --- a/AbstractShopDataModels/AbstractShopDataModels/OrderStatus.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/OrderStatus.cs @@ -1,4 +1,10 @@ -namespace AbstractShopDataModels.Enums +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Enums { //статус заказа public enum OrderStatus -- 2.25.1 From bbc58f74820c672e5e43139db593e2ef8d73b60c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 21:00:26 +0400 Subject: [PATCH 03/26] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B0=20=D0=BF=D0=B0=D0=BF=D0=BE=D0=BA=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 6 ++++++ .../BindingModels/ComponentBindingModel.cs | 13 +++++++++++++ .../BlacksmithWorkshopContracts.csproj | 9 +++++++++ .../{ => Enums}/OrderStatus.cs | 0 .../BlacksmithWorkshopDataModels/IId.cs | 2 +- .../{ => Models}/IComponentModel.cs | 4 ++-- .../{ => Models}/IOrderModel.cs | 4 ++-- .../{ => Models}/IProductModel.cs | 4 ++-- 8 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/{ => Enums}/OrderStatus.cs (100%) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/{ => Models}/IComponentModel.cs (83%) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/{ => Models}/IOrderModel.cs (90%) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/{ => Models}/IProductModel.cs (85%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 496ab40..feccacf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshop", "Black EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Debug|Any CPU.Build.0 = Debug|Any CPU {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Release|Any CPU.ActiveCfg = Release|Any CPU {842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}.Release|Any CPU.Build.0 = Release|Any CPU + {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..d972681 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopDataModels; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + internal class ComponentBindingModel : IComponentModel + { + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/OrderStatus.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs index b6ba8b7..1804a4a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels { //интерфейс, отвечающий за id у компонентов, продуктов и чеков - internal interface IId + public interface IId { int Id { get; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs similarity index 83% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs index ab386fb..01c03ce 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IComponentModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs @@ -4,10 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BlacksmithWorkshopDataModels +namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за компоненты - internal interface IComponentModel : IId + public interface IComponentModel : IId { //название составляющей (изделие состоит из составляющих) string ComponentName { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs similarity index 90% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 5a9adb0..df8dd03 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -5,10 +5,10 @@ using System.Text; using System.Threading.Tasks; using BlacksmithWorkshopDataModels.Enums; -namespace BlacksmithWorkshopDataModels +namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за чек - internal interface IOrderModel : IId + public interface IOrderModel : IId { //id продукта int ProductId { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs similarity index 85% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs index 93cf815..f1d79df 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IProductModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs @@ -4,10 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BlacksmithWorkshopDataModels +namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за продукт - internal interface IProductModel : IId + public interface IProductModel : IId { //наименование изделия string ProductName { get; } -- 2.25.1 From 590a9901cedfb26a0ea0344fc69bad7765a8d2e5 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 21:10:11 +0400 Subject: [PATCH 04/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ComponentBindingModel.cs | 7 ++++- .../BindingModels/OrderBindingModel.cs | 27 +++++++++++++++++++ .../BindingModels/ProductBindingModel.cs | 20 ++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs index d972681..6c523d6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -3,11 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using BlacksmithWorkshopDataModels; +using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopContracts.BindingModels { internal class ComponentBindingModel : IComponentModel { + public int Id { get; set; } + + public double Cost { get; set; } + + public string ComponentName { get; set; } = string.Empty; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..dfea827 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + internal class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + + public int ProductId { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..f6a5c9e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs @@ -0,0 +1,20 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + internal class ProductBindingModel : IProductModel + { + public int Id { get; set; } + + public string ProductName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary ProductComponents { get; set; } = new(); + } +} -- 2.25.1 From 89c8a663d17ee3df6552c70b5a98f0a99551abf0 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 21:19:48 +0400 Subject: [PATCH 05/26] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ComponentBindingModel.cs | 3 ++- .../BindingModels/OrderBindingModel.cs | 3 ++- .../BindingModels/ProductBindingModel.cs | 3 ++- .../SearchModels/ComponentSearchModel.cs | 19 +++++++++++++++++++ .../SearchModels/OrderSearchModel.cs | 16 ++++++++++++++++ .../SearchModels/ProductSearchModel.cs | 18 ++++++++++++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs index 6c523d6..5dc4a58 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -7,7 +7,8 @@ using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopContracts.BindingModels { - internal class ComponentBindingModel : IComponentModel + //реализация сущности "Компонент" + public class ComponentBindingModel : IComponentModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index dfea827..641b634 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -8,7 +8,8 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { - internal class OrderBindingModel : IOrderModel + //реализация сущности "Заказ" + public class OrderBindingModel : IOrderModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs index f6a5c9e..f8f5ddd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs @@ -7,7 +7,8 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { - internal class ProductBindingModel : IProductModel + //реализация сущности "Продукт" + public class ProductBindingModel : IProductModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..c858c99 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + //модель для поиска сущности "Компонент" + public class ComponentSearchModel + { + //для поиска по идентификатору + public int? Id { get; set; } + + //для поиска по названию + public string? ComponentName { get; set; } + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..7c7f72e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + //для поиска сущности "Заказ" + public class OrderSearchModel + { + //для поиска по идентификатору + public int? Id { get; set; } + } + +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs new file mode 100644 index 0000000..647bb18 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + //модель для поиска компонента "Продукт" + public class ProductSearchModel + { + //для поиска по идентификатору + public int? Id { get; set; } + + //для поиска по названию + public string? ProductName { get; set; } + } +} -- 2.25.1 From af39ace4b7efa482fc0402eda5f12a8bfb115878 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 21:39:51 +0400 Subject: [PATCH 06/26] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20Vie?= =?UTF-8?q?wModel.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ComponentViewModel.cs | 22 +++++++++++ .../ViewModels/OrderViewModel.cs | 38 +++++++++++++++++++ .../ViewModels/ProductViewModel.cs | 24 ++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..39f6ebe --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c964335 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,38 @@ +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + //класс для отображения пользователю информации о заказах + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int ProductId { get; set; } + + [DisplayName("Изделие")] + public string ProductName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs new file mode 100644 index 0000000..9845e07 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs @@ -0,0 +1,24 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + //класс для отображения пользователю информаци о продуктах + public class ProductViewModel : IProductModel + { + public int Id { get; set; } + + [DisplayName("Навание изделия")] + public string ProductName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary ProductComponents { get; set; } = new(); + } +} -- 2.25.1 From 507df27f8f8fbb73a58b9acbf2146f593f354190 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 22:00:23 +0400 Subject: [PATCH 07/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81?= =?UTF-8?q?-=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IComponentLogic.cs | 25 +++++++++++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 25 +++++++++++++++++++ .../BusinessLogicsContracts/IProductLogic.cs | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..abd282a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,25 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..204cc77 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,25 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs new file mode 100644 index 0000000..a938007 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs @@ -0,0 +1,25 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + //бизнес-логика для продуктов + public interface IProductLogic + { + List? ReadList(ProductSearchModel? model); + + ProductViewModel? ReadProduct(ProductSearchModel model); + + bool Create(ProductBindingModel model); + + bool Update(ProductBindingModel model); + + bool Delete(ProductBindingModel model); + } +} -- 2.25.1 From f49c753a8dd92d5d66deecca7a3795e852bdd77f Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 5 Feb 2023 22:14:40 +0400 Subject: [PATCH 08/26] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/IComponentStorage.cs | 27 +++++++++++++++++++ .../StoragesContracts/IOrderStorage.cs | 27 +++++++++++++++++++ .../StoragesContracts/IProductStorage.cs | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..de56298 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..e0fc435 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //класс для хранилища заказов + public interface IOrderStorage + { + List GetFullList(); + + List GetFilteredList(OrderSearchModel model); + + OrderViewModel? GetElement(OrderSearchModel model); + + OrderViewModel? Insert(OrderBindingModel model); + + OrderViewModel? Update(OrderBindingModel model); + + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs new file mode 100644 index 0000000..aee63f5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //класс для хранилища продуктов + public interface IProductStorage + { + List GetFullList(); + + List GetFilteredList(ProductSearchModel model); + + ProductViewModel? GetElement(ProductSearchModel model); + + ProductViewModel? Insert(ProductBindingModel model); + + ProductViewModel? Update(ProductBindingModel model); + + ProductViewModel? Delete(ProductBindingModel model); + } +} -- 2.25.1 From ca54e7c5bcd6634f554e01eb424ac7c1b5e51e7a Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 6 Feb 2023 16:56:33 +0400 Subject: [PATCH 09/26] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 6 + .../BlacksmithWorkshopBusinessLogic.csproj | 9 ++ .../BusinessLogic/ComponentLogic.cs | 152 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index feccacf..6609d26 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModel EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBDA1A18-346F-4427-BC86-ED41C062A75B}.Release|Any CPU.Build.0 = Release|Any CPU + {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..4887f09 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,152 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogic +{ + //класс, реализующий логику для компонентов + 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); + + //list хранит весь список в случае, если model пришло со значением null на вход метода + 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:{Componentame}. 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); + + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + //проверка входного аргумента для методов Insert, Update и Delete + 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("Компонент с таким названием уже есть"); + } + } + } +} -- 2.25.1 From 97bb4fafac0ee76b479254650567ef43674d959c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 6 Feb 2023 16:58:28 +0400 Subject: [PATCH 10/26] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ComponentLogic.cs | 5 +++-- .../BusinessLogic/OrderLogic.cs | 12 ++++++++++++ .../BusinessLogic/ProductLogic.cs | 12 ++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs index 4887f09..27602c1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -125,7 +125,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка на наличие названия компонента - if (string.IsNullOrEmpty(model.ComponentName){ + if (string.IsNullOrEmpty(model.ComponentName)){ throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); } @@ -135,7 +135,8 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Цен компонента должна быть больше 0", nameof(model.Cost)); } - _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id); + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", + model.ComponentName, model.Cost, model.Id); //проверка на наличие такого же компонента в списке var element = _componentStorage.GetElement(new ComponentSearchModel diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..dd3a9a0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogic +{ + internal class OrderLogic + { + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs new file mode 100644 index 0000000..01086d0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogic +{ + internal class ProductLogic + { + } +} -- 2.25.1 From 9c8d9a0f2ae9294b354c523a7d412218eea4aaa1 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 6 Feb 2023 19:57:06 +0400 Subject: [PATCH 11/26] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ComponentLogic.cs | 2 +- .../BusinessLogic/ProductLogic.cs | 145 +++++++++++++++++- 2 files changed, 144 insertions(+), 3 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs index 27602c1..4daf480 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -132,7 +132,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //проверка на наличие нормальной цены у компонента if(model.Cost <= 0) { - throw new ArgumentNullException("Цен компонента должна быть больше 0", nameof(model.Cost)); + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); } _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs index 01086d0..f0d8dbf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -1,4 +1,10 @@ -using System; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +12,142 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - internal class ProductLogic + internal class ProductLogic : IProductLogic { + private readonly ILogger _logger; + + private readonly IProductStorage _productStorage; + + //конструктор + public ProductLogic(ILogger logger, IProductStorage productStorage) + { + _logger = logger; + _productStorage = productStorage; + } + + //вывод отфильтрованного списка + public List? ReadList(ProductSearchModel? model) + { + _logger.LogInformation("ReadList. ProductName:{ProductName}. Id:{Id}", model?.ProductName, model?.Id); + + //list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + //вывод конкретного продукта + public ProductViewModel? ReadProduct(ProductSearchModel model) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadProduct. ProductName:{ProductName}. Id:{Id}", model.ProductName, model.Id); + + var element = _productStorage.GetElement(model); + + if(element == null) + { + _logger.LogWarning("ReadProduct element not found"); + return null; + } + + _logger.LogInformation("ReadProduct find. Id:{Id}", model.Id); + + return element; + } + + //Создание продукта + public bool Create(ProductBindingModel model) + { + CheckModel(model); + + if(_productStorage.Insert(model) == null) + { + _logger.LogWarning("Create operation failed"); + return false; + } + + return true; + } + + //обновление продукта + public bool Update(ProductBindingModel model) + { + CheckModel(model); + + if(_productStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + //удаление продукта + public bool Delete(ProductBindingModel model) + { + CheckModel(model); + + if(_productStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + //проверка входного аргумента для методов Insert, Update и Delete + private void CheckModel(ProductBindingModel model, bool withParams = true) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + //если без параметров? + if (!withParams) + { + return; + } + + //проверка на наличие названия продукта + if (string.IsNullOrEmpty(model.ProductName)) + { + throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); + } + + //проверка на наличие нормальной цены у продукта + if(model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Product. ProductName:{ProductName}. Price:{Price}. Id:{Id}", + model.ProductName, model.Price, model.Id); + + //проверка на наличие такого же продукта в списке + var element = _productStorage.GetElement(new ProductSearchModel + { + ProductName = model.ProductName, + }); + + if(element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } } } -- 2.25.1 From 9a246b731155822c3006c1b0009a831c5a47f806 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 9 Feb 2023 23:32:49 +0400 Subject: [PATCH 12/26] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=81=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopBusinessLogic.csproj | 8 + .../BusinessLogic/OrderLogic.cs | 152 +++++++++++++++++- .../BlacksmithWorkshopContracts.csproj | 4 + 3 files changed, 162 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj index 132c02c..82a5881 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index dd3a9a0..cb24790 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,12 +1,160 @@ -using System; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - internal class OrderLogic + public class OrderLogic : IOrderLogic { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + //вывод отфильтрованного списка компонентов + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + + //list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + //создание чека + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if(model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed, incorrect order status"); + return false; + } + + model.Status = OrderStatus.Принят; + + if(_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + //проверка на пустоту входного параметра + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + //если без параметров? + if(!withParams) + { + return; + } + + //проверка на наличие товаров в заказе + if(model.Count <= 0) + { + throw new ArgumentNullException("В заказе не может быть 0 продуктов", nameof(model.Count)); + } + + //проверка на наличие нормальной суммарной стоимости чека + if(model.Sum <= 0) + { + throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + + //проверка корректности id у продуктов + if (model.ProductId < 0) + { + throw new ArgumentNullException("Некорректный id у продукта", nameof(model.ProductId)); + } + + //проверка корректности дат + if(model.DateCreate > model.DateImplement) + { + throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); + } + + _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ProductId:{Id}", model.Id, model.Sum, model.ProductId); + } + + //обновление статуса заказа + public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) + { + CheckModel(model); + + //проверка на возможность обновления статуса на следующий + if(model.Status + 1 != newOrderStatus) + { + _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + " incorrect"); + return false; + } + + model.Status = newOrderStatus; + + //проверка на выдачу + if(model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + //финальная проверка на возможность обновления + if(_orderStorage.Update(model) == null) + { + model.Status--; + + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index 132c02c..f685e06 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -6,4 +6,8 @@ enable + + + + -- 2.25.1 From 950263a842bd209deb1dc8563c65770ee887e31d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 10 Feb 2023 12:19:17 +0400 Subject: [PATCH 13/26] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B5=20?= =?UTF-8?q?DataModels.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ComponentLogic.cs | 14 +++++++------- .../BusinessLogic/OrderLogic.cs | 6 +++--- .../BusinessLogic/ProductLogic.cs | 14 +++++++------- .../BindingModels/ComponentBindingModel.cs | 4 ++-- .../BindingModels/OrderBindingModel.cs | 2 +- .../BindingModels/ProductBindingModel.cs | 6 +++--- .../SearchModels/ComponentSearchModel.cs | 2 +- .../SearchModels/ProductSearchModel.cs | 2 +- .../ViewModels/ComponentViewModel.cs | 4 ++-- .../ViewModels/OrderViewModel.cs | 4 ++-- .../ViewModels/ProductViewModel.cs | 6 +++--- .../Models/{IProductModel.cs => IArticleModel.cs} | 6 +++--- .../Models/IOrderModel.cs | 4 ++-- .../{IComponentModel.cs => IWorkPieceModel.cs} | 4 ++-- 14 files changed, 39 insertions(+), 39 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/{IProductModel.cs => IArticleModel.cs} (75%) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/{IComponentModel.cs => IWorkPieceModel.cs} (84%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs index 4daf480..9a73fda 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -29,7 +29,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //вывод отфильтрованного списка компонентов public List? ReadList(ComponentSearchModel? model) { - _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + _logger.LogInformation("ReadList. WorkPieceName:{WorkPieceName}. Id:{Id}", model?.WorkPieceName, model?.Id); //list хранит весь список в случае, если model пришло со значением null на вход метода var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); @@ -53,7 +53,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComponentName:{Componentame}. Id:{Id}", model.ComponentName, model.Id); + _logger.LogInformation("ReadElement. WorkPieceName:{Componentame}. Id:{Id}", model.WorkPieceName, model.Id); var element = _componentStorage.GetElement(model); @@ -125,8 +125,8 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка на наличие названия компонента - if (string.IsNullOrEmpty(model.ComponentName)){ - throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + if (string.IsNullOrEmpty(model.WorkPieceName)){ + throw new ArgumentNullException("Нет названия компонента", nameof(model.WorkPieceName)); } //проверка на наличие нормальной цены у компонента @@ -135,13 +135,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); } - _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", - model.ComponentName, model.Cost, model.Id); + _logger.LogInformation("Component. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}", + model.WorkPieceName, model.Cost, model.Id); //проверка на наличие такого же компонента в списке var element = _componentStorage.GetElement(new ComponentSearchModel { - ComponentName = model.ComponentName, + WorkPieceName = model.WorkPieceName, }); if(element != null && element.Id != model.Id) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index cb24790..f317b34 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -110,9 +110,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка корректности id у продуктов - if (model.ProductId < 0) + if (model.ArticleId < 0) { - throw new ArgumentNullException("Некорректный id у продукта", nameof(model.ProductId)); + throw new ArgumentNullException("Некорректный id у продукта", nameof(model.ArticleId)); } //проверка корректности дат @@ -121,7 +121,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); } - _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ProductId:{Id}", model.Id, model.Sum, model.ProductId); + _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ArticleId:{Id}", model.Id, model.Sum, model.ArticleId); } //обновление статуса заказа diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs index f0d8dbf..b885924 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -28,7 +28,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //вывод отфильтрованного списка public List? ReadList(ProductSearchModel? model) { - _logger.LogInformation("ReadList. ProductName:{ProductName}. Id:{Id}", model?.ProductName, model?.Id); + _logger.LogInformation("ReadList. ArticleName:{ArticleName}. Id:{Id}", model?.ArticleName, model?.Id); //list хранит весь список в случае, если model пришло со значением null на вход метода var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); @@ -52,7 +52,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadProduct. ProductName:{ProductName}. Id:{Id}", model.ProductName, model.Id); + _logger.LogInformation("ReadProduct. ArticleName:{ArticleName}. Id:{Id}", model.ArticleName, model.Id); var element = _productStorage.GetElement(model); @@ -124,9 +124,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка на наличие названия продукта - if (string.IsNullOrEmpty(model.ProductName)) + if (string.IsNullOrEmpty(model.ArticleName)) { - throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); + throw new ArgumentNullException("Нет названия продукта", nameof(model.ArticleName)); } //проверка на наличие нормальной цены у продукта @@ -135,13 +135,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Product. ProductName:{ProductName}. Price:{Price}. Id:{Id}", - model.ProductName, model.Price, model.Id); + _logger.LogInformation("Product. ArticleName:{ArticleName}. Price:{Price}. Id:{Id}", + model.ArticleName, model.Price, model.Id); //проверка на наличие такого же продукта в списке var element = _productStorage.GetElement(new ProductSearchModel { - ProductName = model.ProductName, + ArticleName = model.ArticleName, }); if(element != null && element.Id != model.Id) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs index 5dc4a58..9b6949f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -8,12 +8,12 @@ using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopContracts.BindingModels { //реализация сущности "Компонент" - public class ComponentBindingModel : IComponentModel + public class ComponentBindingModel : IWorkPieceModel { public int Id { get; set; } public double Cost { get; set; } - public string ComponentName { get; set; } = string.Empty; + public string WorkPieceName { get; set; } = string.Empty; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index 641b634..ec8912a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -13,7 +13,7 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } - public int ProductId { get; set; } + public int ArticleId { get; set; } public int Count { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs index f8f5ddd..48d689f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs @@ -8,14 +8,14 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { //реализация сущности "Продукт" - public class ProductBindingModel : IProductModel + public class ProductBindingModel : IArticleModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string ArticleName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents { get; set; } = new(); + public Dictionary ArticleWorkPiece { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs index c858c99..302941e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -13,7 +13,7 @@ namespace BlacksmithWorkshopContracts.SearchModels public int? Id { get; set; } //для поиска по названию - public string? ComponentName { get; set; } + public string? WorkPieceName { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs index 647bb18..561f80b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs @@ -13,6 +13,6 @@ namespace BlacksmithWorkshopContracts.SearchModels public int? Id { get; set; } //для поиска по названию - public string? ProductName { get; set; } + public string? ArticleName { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs index 39f6ebe..72e1ecd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { //класс для отображения пользователю данных о компонентах - public class ComponentViewModel : IComponentModel + public class ComponentViewModel : IWorkPieceModel { public int Id { get; set; } [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; + public string WorkPieceName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index c964335..8fe2993 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -15,10 +15,10 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int ArticleId { get; set; } [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public string ArticleName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs index 9845e07..d400fca 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs @@ -9,16 +9,16 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { //класс для отображения пользователю информаци о продуктах - public class ProductViewModel : IProductModel + public class ProductViewModel : IArticleModel { public int Id { get; set; } [DisplayName("Навание изделия")] - public string ProductName { get; set; } = string.Empty; + public string ArticleName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ProductComponents { get; set; } = new(); + public Dictionary ArticleWorkPiece { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs similarity index 75% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs index f1d79df..b4437a5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IProductModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs @@ -7,15 +7,15 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за продукт - public interface IProductModel : IId + public interface IArticleModel : IId { //наименование изделия - string ProductName { get; } + string ArticleName { get; } //цена изделия double Price { get; } //словарь, хранящий пары кол-во + компонент и его цена - Dictionary ProductComponents { get; } + Dictionary ArticleWorkPiece { get; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index df8dd03..601726f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -7,11 +7,11 @@ using BlacksmithWorkshopDataModels.Enums; namespace BlacksmithWorkshopDataModels.Models { - //интерфейс, отвечающий за чек + //интерфейс, отвечающий за заказ public interface IOrderModel : IId { //id продукта - int ProductId { get; } + int ArticleId { get; } //кол-во продуктов int Count { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IWorkPieceModel.cs similarity index 84% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IWorkPieceModel.cs index 01c03ce..18310ad 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IWorkPieceModel.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за компоненты - public interface IComponentModel : IId + public interface IWorkPieceModel : IId { //название составляющей (изделие состоит из составляющих) - string ComponentName { get; } + string WorkPieceName { get; } //цена составляющей double Cost { get; } -- 2.25.1 From fa5a6c35b736951d97dc5e7081f6ba5e889cfcfe Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 10 Feb 2023 12:29:17 +0400 Subject: [PATCH 14/26] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B5=20?= =?UTF-8?q?Contracts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ComponentLogic.cs | 20 +++++++------- .../BusinessLogic/ProductLogic.cs | 20 +++++++------- ...BindingModel.cs => ArticleBindingModel.cs} | 2 +- ...ndingModel.cs => WorkPieceBindingModel.cs} | 2 +- .../{IProductLogic.cs => IArticleLogic.cs} | 12 ++++----- ...{IComponentLogic.cs => IWorkPieceLogic.cs} | 12 ++++----- ...ctSearchModel.cs => ArticleSearchModel.cs} | 4 +-- ...SearchModel.cs => WorkPieceSearchModel.cs} | 4 +-- .../StoragesContracts/IArticleStorage.cs | 27 +++++++++++++++++++ .../StoragesContracts/IComponentStorage.cs | 27 ------------------- .../StoragesContracts/IProductStorage.cs | 27 ------------------- .../StoragesContracts/IWorkPieceStorage.cs | 27 +++++++++++++++++++ ...roductViewModel.cs => ArticleViewModel.cs} | 4 +-- ...nentViewModel.cs => WorkPieceViewModel.cs} | 6 ++--- 14 files changed, 97 insertions(+), 97 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/{ProductBindingModel.cs => ArticleBindingModel.cs} (90%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/{ComponentBindingModel.cs => WorkPieceBindingModel.cs} (88%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/{IProductLogic.cs => IArticleLogic.cs} (57%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/{IComponentLogic.cs => IWorkPieceLogic.cs} (57%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/{ProductSearchModel.cs => ArticleSearchModel.cs} (85%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/{ComponentSearchModel.cs => WorkPieceSearchModel.cs} (84%) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IWorkPieceStorage.cs rename BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/{ProductViewModel.cs => ArticleViewModel.cs} (84%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/{ComponentViewModel.cs => WorkPieceViewModel.cs} (72%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs index 9a73fda..a8bdd07 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -13,21 +13,21 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { //класс, реализующий логику для компонентов - public class ComponentLogic : IComponentLogic + public class ComponentLogic : IWorkPieceLogic { private readonly ILogger _logger; - private readonly IComponentStorage _componentStorage; + private readonly IWorkPieceStorage _componentStorage; //конструктор - public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + public ComponentLogic(ILogger logger, IWorkPieceStorage componentStorage) { _logger = logger; _componentStorage = componentStorage; } //вывод отфильтрованного списка компонентов - public List? ReadList(ComponentSearchModel? model) + public List? ReadList(WorkPieceSearchModel? model) { _logger.LogInformation("ReadList. WorkPieceName:{WorkPieceName}. Id:{Id}", model?.WorkPieceName, model?.Id); @@ -46,7 +46,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //вывод конкретного компонента - public ComponentViewModel? ReadElement(ComponentSearchModel model) + public WorkPieceViewModel? ReadElement(WorkPieceSearchModel model) { if(model == null) { @@ -69,7 +69,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //создание компонента - public bool Create(ComponentBindingModel model) + public bool Create(WorkPieceBindingModel model) { CheckModel(model); @@ -83,7 +83,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //обновление компонента - public bool Update(ComponentBindingModel model) + public bool Update(WorkPieceBindingModel model) { CheckModel(model); @@ -97,7 +97,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //удаление компонента - public bool Delete(ComponentBindingModel model) + public bool Delete(WorkPieceBindingModel model) { CheckModel(model); @@ -111,7 +111,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка входного аргумента для методов Insert, Update и Delete - private void CheckModel(ComponentBindingModel model, bool withParams = true) + private void CheckModel(WorkPieceBindingModel model, bool withParams = true) { if(model == null) { @@ -139,7 +139,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.WorkPieceName, model.Cost, model.Id); //проверка на наличие такого же компонента в списке - var element = _componentStorage.GetElement(new ComponentSearchModel + var element = _componentStorage.GetElement(new WorkPieceSearchModel { WorkPieceName = model.WorkPieceName, }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs index b885924..6ad6b30 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -12,21 +12,21 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - internal class ProductLogic : IProductLogic + internal class ProductLogic : IArticleLogic { private readonly ILogger _logger; - private readonly IProductStorage _productStorage; + private readonly IArticleStorage _productStorage; //конструктор - public ProductLogic(ILogger logger, IProductStorage productStorage) + public ProductLogic(ILogger logger, IArticleStorage productStorage) { _logger = logger; _productStorage = productStorage; } //вывод отфильтрованного списка - public List? ReadList(ProductSearchModel? model) + public List? ReadList(ArticleSearchModel? model) { _logger.LogInformation("ReadList. ArticleName:{ArticleName}. Id:{Id}", model?.ArticleName, model?.Id); @@ -45,7 +45,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //вывод конкретного продукта - public ProductViewModel? ReadProduct(ProductSearchModel model) + public ArticleViewModel? ReadProduct(ArticleSearchModel model) { if(model == null) { @@ -68,7 +68,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //Создание продукта - public bool Create(ProductBindingModel model) + public bool Create(ArticleBindingModel model) { CheckModel(model); @@ -82,7 +82,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //обновление продукта - public bool Update(ProductBindingModel model) + public bool Update(ArticleBindingModel model) { CheckModel(model); @@ -96,7 +96,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //удаление продукта - public bool Delete(ProductBindingModel model) + public bool Delete(ArticleBindingModel model) { CheckModel(model); @@ -110,7 +110,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка входного аргумента для методов Insert, Update и Delete - private void CheckModel(ProductBindingModel model, bool withParams = true) + private void CheckModel(ArticleBindingModel model, bool withParams = true) { if(model == null) { @@ -139,7 +139,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.ArticleName, model.Price, model.Id); //проверка на наличие такого же продукта в списке - var element = _productStorage.GetElement(new ProductSearchModel + var element = _productStorage.GetElement(new ArticleSearchModel { ArticleName = model.ArticleName, }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs similarity index 90% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs index 48d689f..60334e6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ProductBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { //реализация сущности "Продукт" - public class ProductBindingModel : IArticleModel + public class ArticleBindingModel : IArticleModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs similarity index 88% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs index 9b6949f..68b53da 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs @@ -8,7 +8,7 @@ using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopContracts.BindingModels { //реализация сущности "Компонент" - public class ComponentBindingModel : IWorkPieceModel + public class WorkPieceBindingModel : IWorkPieceModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs similarity index 57% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs index a938007..055d888 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs @@ -10,16 +10,16 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BusinessLogicsContracts { //бизнес-логика для продуктов - public interface IProductLogic + public interface IArticleLogic { - List? ReadList(ProductSearchModel? model); + List? ReadList(ArticleSearchModel? model); - ProductViewModel? ReadProduct(ProductSearchModel model); + ArticleViewModel? ReadProduct(ArticleSearchModel model); - bool Create(ProductBindingModel model); + bool Create(ArticleBindingModel model); - bool Update(ProductBindingModel model); + bool Update(ArticleBindingModel model); - bool Delete(ProductBindingModel model); + bool Delete(ArticleBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkPieceLogic.cs similarity index 57% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkPieceLogic.cs index abd282a..2aad689 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkPieceLogic.cs @@ -10,16 +10,16 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BusinessLogicsContracts { //бизнес-логика для компонентов - public interface IComponentLogic + public interface IWorkPieceLogic { - List? ReadList(ComponentSearchModel? model); + List? ReadList(WorkPieceSearchModel? model); - ComponentViewModel? ReadElement(ComponentSearchModel model); + WorkPieceViewModel? ReadElement(WorkPieceSearchModel model); - bool Create(ComponentBindingModel model); + bool Create(WorkPieceBindingModel model); - bool Update(ComponentBindingModel model); + bool Update(WorkPieceBindingModel model); - bool Delete(ComponentBindingModel model); + bool Delete(WorkPieceBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs similarity index 85% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs index 561f80b..23163cf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ProductSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.SearchModels { - //модель для поиска компонента "Продукт" - public class ProductSearchModel + //модель для поиска компонента "Продукт" (она же изделие) + public class ArticleSearchModel { //для поиска по идентификатору public int? Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/WorkPieceSearchModel.cs similarity index 84% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/WorkPieceSearchModel.cs index 302941e..45048bf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/WorkPieceSearchModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.SearchModels { - //модель для поиска сущности "Компонент" - public class ComponentSearchModel + //модель для поиска сущности "Компонент" (она же заготовка) + public class WorkPieceSearchModel { //для поиска по идентификатору public int? Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs new file mode 100644 index 0000000..e5e47d5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //класс для хранилища продуктов (изделий) + public interface IArticleStorage + { + List GetFullList(); + + List GetFilteredList(ArticleSearchModel model); + + ArticleViewModel? GetElement(ArticleSearchModel model); + + ArticleViewModel? Insert(ArticleBindingModel model); + + ArticleViewModel? Update(ArticleBindingModel model); + + ArticleViewModel? Delete(ArticleBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs deleted file mode 100644 index de56298..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs +++ /dev/null @@ -1,27 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs deleted file mode 100644 index aee63f5..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IProductStorage.cs +++ /dev/null @@ -1,27 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.StoragesContracts -{ - //класс для хранилища продуктов - public interface IProductStorage - { - List GetFullList(); - - List GetFilteredList(ProductSearchModel model); - - ProductViewModel? GetElement(ProductSearchModel model); - - ProductViewModel? Insert(ProductBindingModel model); - - ProductViewModel? Update(ProductBindingModel model); - - ProductViewModel? Delete(ProductBindingModel model); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IWorkPieceStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IWorkPieceStorage.cs new file mode 100644 index 0000000..0b0600e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IWorkPieceStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //класс хранилища компонентов (заготовок) + public interface IWorkPieceStorage + { + List GetFullList(); + + List GetFilteredList(WorkPieceSearchModel model); + + WorkPieceViewModel? GetElement(WorkPieceSearchModel model); + + WorkPieceViewModel? Insert(WorkPieceBindingModel model); + + WorkPieceViewModel? Update(WorkPieceBindingModel model); + + WorkPieceViewModel? Delete(WorkPieceBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs similarity index 84% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs index d400fca..492114b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ProductViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs @@ -8,8 +8,8 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { - //класс для отображения пользователю информаци о продуктах - public class ProductViewModel : IArticleModel + //класс для отображения пользователю информаци о продуктах (изделиях) + public class ArticleViewModel : IArticleModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs similarity index 72% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs index 72e1ecd..05c5e97 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs @@ -8,12 +8,12 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { - //класс для отображения пользователю данных о компонентах - public class ComponentViewModel : IWorkPieceModel + //класс для отображения пользователю данных о компонентах (заготовках) + public class WorkPieceViewModel : IWorkPieceModel { public int Id { get; set; } - [DisplayName("Название компонента")] + [DisplayName("Название заготовки")] public string WorkPieceName { get; set; } = string.Empty; [DisplayName("Цена")] -- 2.25.1 From 3b4adf60012d1ef04e57458f61c22768eb6908b7 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 10 Feb 2023 12:49:10 +0400 Subject: [PATCH 15/26] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B5=20?= =?UTF-8?q?BusinessLogic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ProductLogic.cs => ArticleLogic.cs} | 42 +++++++++---------- .../BusinessLogic/OrderLogic.cs | 6 +-- .../{ComponentLogic.cs => WorkPieceLogic.cs} | 38 ++++++++--------- .../SearchModels/ArticleSearchModel.cs | 2 +- .../ViewModels/WorkPieceViewModel.cs | 2 +- 5 files changed, 45 insertions(+), 45 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/{ProductLogic.cs => ArticleLogic.cs} (74%) rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/{ComponentLogic.cs => WorkPieceLogic.cs} (75%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs similarity index 74% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs index 6ad6b30..c95ec8f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs @@ -12,17 +12,17 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - internal class ProductLogic : IArticleLogic + internal class ArticleLogic : IArticleLogic { private readonly ILogger _logger; - private readonly IArticleStorage _productStorage; + private readonly IArticleStorage _articleStorage; //конструктор - public ProductLogic(ILogger logger, IArticleStorage productStorage) + public ArticleLogic(ILogger logger, IArticleStorage productStorage) { _logger = logger; - _productStorage = productStorage; + _articleStorage = productStorage; } //вывод отфильтрованного списка @@ -31,7 +31,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("ReadList. ArticleName:{ArticleName}. Id:{Id}", model?.ArticleName, model?.Id); //list хранит весь список в случае, если model пришло со значением null на вход метода - var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + var list = model == null ? _articleStorage.GetFullList() : _articleStorage.GetFilteredList(model); if(list == null) { @@ -44,7 +44,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return list; } - //вывод конкретного продукта + //вывод конкретного изделия public ArticleViewModel? ReadProduct(ArticleSearchModel model) { if(model == null) @@ -54,7 +54,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("ReadProduct. ArticleName:{ArticleName}. Id:{Id}", model.ArticleName, model.Id); - var element = _productStorage.GetElement(model); + var element = _articleStorage.GetElement(model); if(element == null) { @@ -67,12 +67,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return element; } - //Создание продукта + //Создание изделия public bool Create(ArticleBindingModel model) { CheckModel(model); - if(_productStorage.Insert(model) == null) + if(_articleStorage.Insert(model) == null) { _logger.LogWarning("Create operation failed"); return false; @@ -81,12 +81,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //обновление продукта + //обновление изделия public bool Update(ArticleBindingModel model) { CheckModel(model); - if(_productStorage.Update(model) == null) + if(_articleStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -95,12 +95,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //удаление продукта + //удаление изделия public bool Delete(ArticleBindingModel model) { CheckModel(model); - if(_productStorage.Delete(model) == null) + if(_articleStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -123,30 +123,30 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return; } - //проверка на наличие названия продукта + //проверка на наличие названия изделия if (string.IsNullOrEmpty(model.ArticleName)) { - throw new ArgumentNullException("Нет названия продукта", nameof(model.ArticleName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.ArticleName)); } - //проверка на наличие нормальной цены у продукта + //проверка на наличие нормальной цены у изделия if(model.Price <= 0) { - throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Product. ArticleName:{ArticleName}. Price:{Price}. Id:{Id}", + _logger.LogInformation("Article. ArticleName:{ArticleName}. Price:{Price}. Id:{Id}", model.ArticleName, model.Price, model.Id); - //проверка на наличие такого же продукта в списке - var element = _productStorage.GetElement(new ArticleSearchModel + //проверка на наличие такого же изделия в списке + var element = _articleStorage.GetElement(new ArticleSearchModel { ArticleName = model.ArticleName, }); if(element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Изделие с таким названием уже есть"); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index f317b34..aa8fa2e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -100,7 +100,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //проверка на наличие товаров в заказе if(model.Count <= 0) { - throw new ArgumentNullException("В заказе не может быть 0 продуктов", nameof(model.Count)); + throw new ArgumentNullException("В заказе не может быть 0 изделий", nameof(model.Count)); } //проверка на наличие нормальной суммарной стоимости чека @@ -109,10 +109,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); } - //проверка корректности id у продуктов + //проверка корректности id у изделий if (model.ArticleId < 0) { - throw new ArgumentNullException("Некорректный id у продукта", nameof(model.ArticleId)); + throw new ArgumentNullException("Некорректный id у изделия", nameof(model.ArticleId)); } //проверка корректности дат diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs similarity index 75% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs index a8bdd07..ff09e0a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs @@ -17,13 +17,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { private readonly ILogger _logger; - private readonly IWorkPieceStorage _componentStorage; + private readonly IWorkPieceStorage _workPieceStorage; //конструктор public ComponentLogic(ILogger logger, IWorkPieceStorage componentStorage) { _logger = logger; - _componentStorage = componentStorage; + _workPieceStorage = componentStorage; } //вывод отфильтрованного списка компонентов @@ -32,7 +32,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("ReadList. WorkPieceName:{WorkPieceName}. Id:{Id}", model?.WorkPieceName, model?.Id); //list хранит весь список в случае, если model пришло со значением null на вход метода - var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + var list = model == null ? _workPieceStorage.GetFullList() : _workPieceStorage.GetFilteredList(model); if(list == null) { @@ -45,7 +45,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return list; } - //вывод конкретного компонента + //вывод конкретного заготовки public WorkPieceViewModel? ReadElement(WorkPieceSearchModel model) { if(model == null) @@ -53,9 +53,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. WorkPieceName:{Componentame}. Id:{Id}", model.WorkPieceName, model.Id); + _logger.LogInformation("ReadElement. WorkPieceName:{WorkPieceName}. Id:{Id}", model.WorkPieceName, model.Id); - var element = _componentStorage.GetElement(model); + var element = _workPieceStorage.GetElement(model); if(element == null) { @@ -68,12 +68,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return element; } - //создание компонента + //создание заготовки public bool Create(WorkPieceBindingModel model) { CheckModel(model); - if(_componentStorage.Insert(model) == null) + if(_workPieceStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -82,12 +82,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //обновление компонента + //обновление заготовки public bool Update(WorkPieceBindingModel model) { CheckModel(model); - if(_componentStorage.Update(model) == null) + if(_workPieceStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -96,12 +96,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //удаление компонента + //удаление заготовки public bool Delete(WorkPieceBindingModel model) { CheckModel(model); - if (_componentStorage.Delete(model) == null) + if (_workPieceStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -124,29 +124,29 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return; } - //проверка на наличие названия компонента + //проверка на наличие названия заготовки if (string.IsNullOrEmpty(model.WorkPieceName)){ - throw new ArgumentNullException("Нет названия компонента", nameof(model.WorkPieceName)); + throw new ArgumentNullException("Нет названия заготовки", nameof(model.WorkPieceName)); } - //проверка на наличие нормальной цены у компонента + //проверка на наличие нормальной цены у заготовки if(model.Cost <= 0) { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Cost)); } _logger.LogInformation("Component. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}", model.WorkPieceName, model.Cost, model.Id); - //проверка на наличие такого же компонента в списке - var element = _componentStorage.GetElement(new WorkPieceSearchModel + //проверка на наличие такой же заготовки в списке + var element = _workPieceStorage.GetElement(new WorkPieceSearchModel { WorkPieceName = model.WorkPieceName, }); if(element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Заготовка с таким названием уже есть"); } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs index 23163cf..0a98f7c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.SearchModels { - //модель для поиска компонента "Продукт" (она же изделие) + //модель для поиска заготовки "Продукт" (она же изделие) public class ArticleSearchModel { //для поиска по идентификатору diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs index 05c5e97..c04bcdc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/WorkPieceViewModel.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { - //класс для отображения пользователю данных о компонентах (заготовках) + //класс для отображения пользователю данных о заготовких (заготовках) public class WorkPieceViewModel : IWorkPieceModel { public int Id { get; set; } -- 2.25.1 From cdcdfa9709286d5bf9763955b97d8b44a35054cc Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 10 Feb 2023 14:25:11 +0400 Subject: [PATCH 16/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=BE=D0=B2=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 12 ++- .../BlacksmithWorkshopListImplement.csproj | 9 +++ .../Models/Article.cs | 63 +++++++++++++++ .../Models/Order.cs | 77 +++++++++++++++++++ .../Models/WorkPiece.cs | 58 ++++++++++++++ 5 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/WorkPiece.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 6609d26..1c793e7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -5,11 +5,13 @@ VisualStudioVersion = 17.4.33103.184 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{FEF2DC94-D11E-4D77-9F59-5B89A09D0996}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.Build.0 = Release|Any CPU + {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs new file mode 100644 index 0000000..3fb18b4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs @@ -0,0 +1,63 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + //класс реализующий интерфейс модели изделия + public class Article : IArticleModel + { + //методы set делаем приватным, чтобы исключить неразрешённые манипуляции + public int Id { get; private set; } + + public string ArticleName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary ArticleWorkPiece { get; private set; } = new Dictionary(); + + //метод для создания объекта от класса-компонента на основе класса-BindingModel + public static Article? Create(ArticleBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Article() + { + Id = model.Id, + ArticleName = model.ArticleName, + Price = model.Price, + ArticleWorkPiece = model.ArticleWorkPiece + }; + } + + //метод изменения существующего объекта + public void Update(ArticleBindingModel? model) + { + if (model == null) + { + return; + } + + ArticleName = model.ArticleName; + Price = model.Price; + ArticleWorkPiece = model.ArticleWorkPiece; + } + + //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public ArticleViewModel GetViewModel() => new() + { + Id = Id, + ArticleName = ArticleName, + Price = Price, + ArticleWorkPiece = ArticleWorkPiece + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs new file mode 100644 index 0000000..13e02d6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -0,0 +1,77 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.PortableExecutable; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + //класс, реализующий интерфейс модели заказа + public class Order : IOrderModel + { + //методы set сделали приватными, чтобы исключить неразрешённые манипуляции + public int Id { get; private set; } + + public int ArticleId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Order() + { + ArticleId = model.ArticleId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, //а надо ли? + DateImplement = model.DateImplement //а надо ли? + }; + } + + //метод изменения существующего объекта + public void Update(OrderBindingModel? model) + { + if(model == null) + { + return; + } + + ArticleId = model.ArticleId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; //а надо ли? + DateImplement = model.DateImplement; //а надо ли? + } + + //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public OrderViewModel GetViewModel() => new() + { + ArticleId = ArticleId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, //а надо ли? + DateImplement = DateImplement //а надо ли? + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/WorkPiece.cs new file mode 100644 index 0000000..fdd1df1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/WorkPiece.cs @@ -0,0 +1,58 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + //реализация интерфейса модели заготовки + public class WorkPiece : IWorkPieceModel + { + //методы set делаем приватным, чтобы исключить неразрешённые манипуляции + public int Id { get; private set; } + + public string WorkPieceName { get; private set; } = string.Empty; + + public double Cost { get; private set; } + + //метод для создания объекта от класса-компонента на основе класса-BindingModel + public static WorkPiece? Create(WorkPieceBindingModel? model) + { + if(model == null) + { + return null; + } + + return new WorkPiece() + { + Id = model.Id, + WorkPieceName = model.WorkPieceName, + Cost = model.Cost + }; + } + + //метод изменения существующего объекта + public void Update(WorkPieceBindingModel? model) + { + if(model == null) + { + return; + } + + WorkPieceName = model.WorkPieceName; + Cost = model.Cost; + } + + //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public WorkPieceViewModel GetViewModel => new() + { + Id = Id, + WorkPieceName = WorkPieceName, + Cost = Cost + }; + } +} -- 2.25.1 From b93d5ff13fa82f441c0dbea8ea1b6d7534ad3fd9 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 11 Feb 2023 00:07:41 +0400 Subject: [PATCH 17/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=BE=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=D1=89.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopListImplement.csproj | 5 + .../DataListSingleton.cs | 41 ++++++ .../Implements/ArticleStorage.cs | 138 ++++++++++++++++++ .../Implements/OrderStorage.cs | 137 +++++++++++++++++ .../Implements/WorkPieceStorage.cs | 138 ++++++++++++++++++ .../Models/Article.cs | 2 +- .../Models/Order.cs | 2 +- 7 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/WorkPieceStorage.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj index 132c02c..b65badc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..b6da397 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -0,0 +1,41 @@ +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement +{ + //класс для списков, в которых будет храниться информация при работе приложения + public class DataListSingleton + { + private static DataListSingleton? _instance; + + //список для хранения заготовок + public List WorkPieces { get; set; } + + //список для хранения изделий + public List
Articles { get; set; } + + //список для хранения заказов + public List Orders { get; set; } + + public DataListSingleton() + { + WorkPieces = new List(); + Articles = new List
(); + Orders = new List(); + } + + public static DataListSingleton GetInstance() + { + if(_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs new file mode 100644 index 0000000..3e5eeb8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs @@ -0,0 +1,138 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + //класс, реализующий интерфейс хранилища изделий + public class ArticleStorage : IArticleStorage + { + //поле для работы со списком изделий + private readonly DataListSingleton _source; + + //получение в конструкторе объекта DataListSingleton + public ArticleStorage() + { + _source = DataListSingleton.GetInstance(); + } + + //получение полного списка изделий + public List GetFullList() + { + var result = new List(); + + foreach(var article in _source.Articles) + { + result.Add(article.GetViewModel); + } + + return result; + } + + //получение отфильтрованного списка изделий + public List GetFilteredList(ArticleSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ArticleName)) + { + return result; + } + + foreach(var article in _source.Articles) + { + if(article.ArticleName.Contains(model.ArticleName)) + { + result.Add(article.GetViewModel); + } + } + + return result; + } + + //получение элемента из списка изделий + public ArticleViewModel? GetElement(ArticleSearchModel model) + { + if(string.IsNullOrEmpty(model.ArticleName) && !model.Id.HasValue) + { + return null; + } + + foreach(var article in _source.Articles) + { + if((!string.IsNullOrEmpty(model.ArticleName) && article.ArticleName == model.ArticleName) || + (model.Id.HasValue && article.Id == model.Id)) + { + return article.GetViewModel; + } + } + + return null; + } + + //при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1 + public ArticleViewModel? Insert(ArticleBindingModel model) + { + model.Id = 1; + + foreach(var article in _source.Articles) + { + if(model.Id <= article.Id) + { + model.Id = article.Id + 1; + } + } + + var newArticle = Article.Create(model); + + if(newArticle == null) + { + return null; + } + + _source.Articles.Add(newArticle); + + return newArticle.GetViewModel; + } + + //обновление изделия + public ArticleViewModel? Update(ArticleBindingModel model) + { + foreach (var article in _source.Articles) + { + if (article.Id == model.Id) + { + article.Update(model); + + return article.GetViewModel; + } + } + + return null; + } + + //удаление изделия + public ArticleViewModel? Delete(ArticleBindingModel model) + { + for(int i = 0; i < _source.Articles.Count; ++i) + { + if (_source.Articles[i].Id == model.Id) + { + var element = _source.Articles[i]; + _source.Articles.RemoveAt(i); + + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..2d78549 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,137 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + //класс, реализующий интерфейс хранилища заказов + public class OrderStorage : IOrderStorage + { + //поле для работы со списком заказов + private readonly DataListSingleton _source; + + //получение в конструкторе объекта DataListSingleton + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + //получение полного списка заготовок + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + //получение отфильтрованного списка заказов + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + + return result; + } + + //получение элемента из списка заказов + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + + return null; + } + + //при создании заказа определяем для него новый id: ищем max id и прибавляем к нему 1 + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + //обновление заказа + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + + return order.GetViewModel; + } + } + + return null; + } + + //удаление заказа + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/WorkPieceStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/WorkPieceStorage.cs new file mode 100644 index 0000000..eacd079 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/WorkPieceStorage.cs @@ -0,0 +1,138 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + //класс, реализующий интерфейс хранилища заготовок + public class WorkPieceStorage : IWorkPieceStorage + { + //поле для работы со списком заготовок + private readonly DataListSingleton _source; + + //получение в конструкторе объекта DataListSingleton + public WorkPieceStorage() + { + _source = DataListSingleton.GetInstance(); + } + + //получение полного списка заготовок + public List GetFullList() + { + var result = new List(); + + foreach(var workPiece in _source.WorkPieces) + { + result.Add(workPiece.GetViewModel); + } + + return result; + } + + //получение отфильтрованного списка заготовок + public List GetFilteredList(WorkPieceSearchModel model) + { + var result = new List(); + + if(string.IsNullOrEmpty(model.WorkPieceName)) + { + return result; + } + + foreach(var workPiece in _source.WorkPieces) + { + if (workPiece.WorkPieceName.Contains(model.WorkPieceName)) + { + result.Add(workPiece.GetViewModel); + } + } + + return result; + } + + //получение элемента из списка заготовок + public WorkPieceViewModel? GetElement(WorkPieceSearchModel model) + { + if(string.IsNullOrEmpty(model.WorkPieceName) && !model.Id.HasValue) + { + return null; + } + + foreach(var workPiece in _source.WorkPieces) + { + if((!string.IsNullOrEmpty(model.WorkPieceName) && workPiece.WorkPieceName == model.WorkPieceName) || + (model.Id.HasValue && workPiece.Id == model.Id)) + { + return workPiece.GetViewModel; + } + } + + return null; + } + + //при создании заготовки определяем для него новый id: ищем max id и прибавляем к нему 1 + public WorkPieceViewModel? Insert(WorkPieceBindingModel model) + { + model.Id = 1; + + foreach(var workPiece in _source.WorkPieces) + { + if(model.Id <= workPiece.Id) + { + model.Id = workPiece.Id + 1; + } + } + + var newWorkPiece = WorkPiece.Create(model); + + if(newWorkPiece == null) + { + return null; + } + + _source.WorkPieces.Add(newWorkPiece); + + return newWorkPiece.GetViewModel; + } + + //обновление заготовки + public WorkPieceViewModel? Update(WorkPieceBindingModel model) + { + foreach(var workPiece in _source.WorkPieces) + { + if(workPiece.Id == model.Id) + { + workPiece.Update(model); + + return workPiece.GetViewModel; + } + } + + return null; + } + + //удаление заготовки + public WorkPieceViewModel? Delete(WorkPieceBindingModel model) + { + for(int i = 0; i < _source.WorkPieces.Count; ++i) + { + if (_source.WorkPieces[i].Id == model.Id) + { + var element = _source.WorkPieces[i]; + _source.WorkPieces.RemoveAt(i); + + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs index 3fb18b4..d8dd647 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs @@ -52,7 +52,7 @@ namespace BlacksmithWorkshopListImplement.Models } //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента - public ArticleViewModel GetViewModel() => new() + public ArticleViewModel GetViewModel => new() { Id = Id, ArticleName = ArticleName, diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 13e02d6..84272c5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -64,7 +64,7 @@ namespace BlacksmithWorkshopListImplement.Models } //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента - public OrderViewModel GetViewModel() => new() + public OrderViewModel GetViewModel => new() { ArticleId = ArticleId, Count = Count, -- 2.25.1 From d0b97a0dc93178be28274dd510bceeed1ff80146 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 17:05:47 +0400 Subject: [PATCH 18/26] =?UTF-8?q?=D0=93=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop.csproj | 6 + .../BlacksmithWorkshop/Form1.Designer.cs | 39 --- .../BlacksmithWorkshop/Form1.cs | 10 - .../BlacksmithWorkshop/Form1.resx | 120 --------- .../FormCreateOrder.Designer.cs | 144 ++++++++++ .../BlacksmithWorkshop/FormCreateOrder.cs | 130 +++++++++ .../BlacksmithWorkshop/FormCreateOrder.resx | 60 +++++ .../BlacksmithWorkshop/FormMain.Designer.cs | 247 ++++++++++++++++++ .../BlacksmithWorkshop/FormMain.cs | 163 ++++++++++++ .../BlacksmithWorkshop/FormMain.resx | 105 ++++++++ .../FormManufacture.Designer.cs | 221 ++++++++++++++++ .../BlacksmithWorkshop/FormManufacture.cs | 244 +++++++++++++++++ .../BlacksmithWorkshop/FormManufacture.resx | 66 +++++ .../FormManufactureWorkPiece.Designer.cs | 119 +++++++++ .../FormManufactureWorkPiece.cs | 88 +++++++ .../FormManufactureWorkPiece.resx | 60 +++++ .../FormManufactures.Designer.cs | 149 +++++++++++ .../BlacksmithWorkshop/FormManufactures.cs | 124 +++++++++ .../BlacksmithWorkshop/FormManufactures.resx | 60 +++++ .../FormWorkPiece.Designer.cs | 119 +++++++++ .../BlacksmithWorkshop/FormWorkPiece.cs | 103 ++++++++ .../BlacksmithWorkshop/FormWorkPiece.resx | 60 +++++ .../FormWorkPieces.Designer.cs | 149 +++++++++++ .../BlacksmithWorkshop/FormWorkPieces.cs | 127 +++++++++ .../BlacksmithWorkshop/FormWorkPieces.resx | 69 +++++ .../BlacksmithWorkshop/Program.cs | 45 +++- .../{ArticleLogic.cs => ManufactureLogic.cs} | 50 ++-- .../BusinessLogic/OrderLogic.cs | 6 +- .../BusinessLogic/WorkPieceLogic.cs | 8 +- ...ingModel.cs => ManufactureBindingModel.cs} | 6 +- .../BindingModels/OrderBindingModel.cs | 2 +- ...{IArticleLogic.cs => IManufactureLogic.cs} | 12 +- ...archModel.cs => ManufactureSearchModel.cs} | 4 +- .../StoragesContracts/IArticleStorage.cs | 27 -- .../StoragesContracts/IManufactureStorage.cs | 27 ++ ...leViewModel.cs => ManufactureViewModel.cs} | 6 +- .../ViewModels/OrderViewModel.cs | 4 +- ...{IArticleModel.cs => IManufactureModel.cs} | 6 +- .../Models/IOrderModel.cs | 2 +- .../DataListSingleton.cs | 4 +- .../Implements/ArticleStorage.cs | 138 ---------- .../Implements/ManufactureStorage.cs | 138 ++++++++++ .../Models/{Article.cs => Manufacture.cs} | 26 +- .../Models/Order.cs | 22 +- 44 files changed, 2899 insertions(+), 416 deletions(-) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/{ArticleLogic.cs => ManufactureLogic.cs} (63%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/{ArticleBindingModel.cs => ManufactureBindingModel.cs} (61%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/{IArticleLogic.cs => IManufactureLogic.cs} (53%) rename BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/{ArticleSearchModel.cs => ManufactureSearchModel.cs} (82%) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs rename BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/{ArticleViewModel.cs => ManufactureViewModel.cs} (71%) rename BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/{IArticleModel.cs => IManufactureModel.cs} (74%) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs rename BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/{Article.cs => Manufacture.cs} (63%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index b57c89e..b363b98 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -8,4 +8,10 @@ enable + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs deleted file mode 100644 index 6d3391d..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace BlacksmithWorkshop -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs deleted file mode 100644 index 6c3de35..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace BlacksmithWorkshop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..da2944a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace BlacksmithWorkshop +{ + 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.labelManufacture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxManufacture = 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(); + // + // labelManufacture + // + this.labelManufacture.AutoSize = true; + this.labelManufacture.Location = new System.Drawing.Point(24, 24); + this.labelManufacture.Name = "labelManufacture"; + this.labelManufacture.Size = new System.Drawing.Size(71, 20); + this.labelManufacture.TabIndex = 0; + this.labelManufacture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(24, 70); + 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(24, 113); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(58, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxManufacture + // + this.comboBoxManufacture.FormattingEnabled = true; + this.comboBoxManufacture.Location = new System.Drawing.Point(166, 21); + this.comboBoxManufacture.Name = "comboBoxManufacture"; + this.comboBoxManufacture.Size = new System.Drawing.Size(278, 28); + this.comboBoxManufacture.TabIndex = 3; + this.comboBoxManufacture.SelectedIndexChanged += new System.EventHandler(this.ComboBoxManufacture_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(166, 67); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(278, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(166, 110); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(278, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(230, 155); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(340, 155); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(479, 203); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxManufacture); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelManufacture); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelManufacture; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxManufacture; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs new file mode 100644 index 0000000..4295273 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -0,0 +1,130 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IManufactureLogic _logicA; + + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IManufactureLogic logicA, IOrderLogic logicO) + { + InitializeComponent(); + + _logger = logger; + _logicA = logicA; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + + //дописать логику + } + + private void CalcSum() + { + if (comboBoxManufacture.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); + + var manufacture = _logicA.ReadManufacture(new ManufactureSearchModel + { + Id = id + }); + + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (manufacture?.Price ?? 0), 2).ToString(); + + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void TextBoxCount_TextChanged(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 (comboBoxManufacture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + + _logger.LogInformation("Создание заказа"); + + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ManufactureId = Convert.ToInt32(comboBoxManufacture.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/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs new file mode 100644 index 0000000..1fe2054 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -0,0 +1,247 @@ +namespace BlacksmithWorkshop +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnSum = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnStatus = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnDateCreate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnDateImplement = new System.Windows.Forms.DataGridViewTextBoxColumn(); + 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 = 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnManufacture, + this.ColumnCount, + this.ColumnSum, + this.ColumnStatus, + this.ColumnDateCreate, + this.ColumnDateImplement}); + this.dataGridView.Location = new System.Drawing.Point(12, 36); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(937, 402); + this.dataGridView.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Номер"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.Width = 125; + // + // ColumnManufacture + // + this.ColumnManufacture.HeaderText = "Изделие"; + this.ColumnManufacture.MinimumWidth = 6; + this.ColumnManufacture.Name = "ColumnManufacture"; + this.ColumnManufacture.Width = 125; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // ColumnSum + // + this.ColumnSum.HeaderText = "Сумма"; + this.ColumnSum.MinimumWidth = 6; + this.ColumnSum.Name = "ColumnSum"; + this.ColumnSum.Width = 125; + // + // ColumnStatus + // + this.ColumnStatus.HeaderText = "Статус"; + this.ColumnStatus.MinimumWidth = 6; + this.ColumnStatus.Name = "ColumnStatus"; + this.ColumnStatus.Width = 125; + // + // ColumnDateCreate + // + this.ColumnDateCreate.HeaderText = "Дата создания"; + this.ColumnDateCreate.MinimumWidth = 6; + this.ColumnDateCreate.Name = "ColumnDateCreate"; + this.ColumnDateCreate.Width = 125; + // + // ColumnDateImplement + // + this.ColumnDateImplement.HeaderText = "Дата выполнения"; + this.ColumnDateImplement.MinimumWidth = 6; + this.ColumnDateImplement.Name = "ColumnDateImplement"; + this.ColumnDateImplement.Width = 125; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 66); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(235, 29); + this.buttonCreateOrder.TabIndex = 1; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1014, 143); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(235, 29); + this.buttonTakeOrderInWork.TabIndex = 2; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(1014, 220); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(235, 29); + this.buttonOrderReady.TabIndex = 3; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(1014, 296); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(235, 29); + this.buttonIssuedOrder.TabIndex = 4; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1014, 369); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(235, 29); + this.buttonRef.TabIndex = 5; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // 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(1297, 28); + this.menuStrip1.TabIndex = 6; + 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(162, 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(162, 26); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1297, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Абстрактный магазин"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private MenuStrip menuStrip1; + private ToolStripMenuItem toolStripMenuItem; + private ToolStripMenuItem заготовкиToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnManufacture; + private DataGridViewTextBoxColumn ColumnCount; + private DataGridViewTextBoxColumn ColumnSum; + private DataGridViewTextBoxColumn ColumnStatus; + private DataGridViewTextBoxColumn ColumnDateCreate; + private DataGridViewTextBoxColumn ColumnDateImplement; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs new file mode 100644 index 0000000..ac32701 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -0,0 +1,163 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + 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(FormWorkPieces)); + + if(service is FormWorkPieces 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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx new file mode 100644 index 0000000..eb63604 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs new file mode 100644 index 0000000..0a4a273 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs @@ -0,0 +1,221 @@ +namespace BlacksmithWorkshop +{ + partial class FormManufacture + { + /// + /// 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.groupBoxWorkPiece = 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnWorkPiece = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxWorkPiece.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(23, 30); + 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(23, 84); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(86, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(133, 27); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(332, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(133, 81); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(196, 27); + this.textBoxCost.TabIndex = 3; + // + // groupBoxWorkPiece + // + this.groupBoxWorkPiece.Controls.Add(this.buttonRef); + this.groupBoxWorkPiece.Controls.Add(this.buttonDel); + this.groupBoxWorkPiece.Controls.Add(this.buttonUpd); + this.groupBoxWorkPiece.Controls.Add(this.buttonAdd); + this.groupBoxWorkPiece.Controls.Add(this.dataGridView); + this.groupBoxWorkPiece.Location = new System.Drawing.Point(23, 126); + this.groupBoxWorkPiece.Name = "groupBoxWorkPiece"; + this.groupBoxWorkPiece.Size = new System.Drawing.Size(567, 300); + this.groupBoxWorkPiece.TabIndex = 4; + this.groupBoxWorkPiece.TabStop = false; + this.groupBoxWorkPiece.Text = "Заготовки"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(454, 196); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(454, 145); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(454, 95); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(454, 43); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnWorkPiece, + this.ColumnCount}); + 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(416, 268); + this.dataGridView.TabIndex = 0; + // + // ColumnWorkPiece + // + this.ColumnWorkPiece.HeaderText = "Заготовка"; + this.ColumnWorkPiece.MinimumWidth = 6; + this.ColumnWorkPiece.Name = "ColumnWorkPiece"; + this.ColumnWorkPiece.Width = 125; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(340, 448); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(95, 29); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(458, 448); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormManufacture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(619, 500); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxWorkPiece); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormManufacture"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormManufacture_Load); + this.groupBoxWorkPiece.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private GroupBox groupBoxWorkPiece; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnWorkPiece; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs new file mode 100644 index 0000000..af32e51 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -0,0 +1,244 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class FormManufacture : Form + { + private readonly ILogger _logger; + + private readonly IManufactureLogic _logic; + + private int? _id; + + private Dictionary _manufactureWorkPieces; + + public int Id { set { _id = value; } } + + public FormManufacture(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + _manufactureWorkPieces = new Dictionary(); + } + + private void FormManufacture_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + + try + { + var view = _logic.ReadManufacture(new ManufactureSearchModel { Id = _id.Value }); + + if(view != null) + { + textBoxName.Text = view.ManufactureName; + textBoxCost.Text = view.Price.ToString(); + _manufactureWorkPieces = view.ManufactureWorkPieces ?? new Dictionary(); + LoadData(); + } + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заготовок для изделия"); + + try + { + if(_manufactureWorkPieces != null) + { + dataGridView.Rows.Clear(); + + foreach(var awp in _manufactureWorkPieces) + { + dataGridView.Rows.Add(new object[] { awp.Key, awp.Value.Item1.WorkPieceName, awp.Value.Item2 }); + } + + textBoxCost.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(FormManufactureWorkPiece)); + if (service is FormManufactureWorkPiece form) + if (form.ShowDialog() == DialogResult.OK) + { + if (form.WorkPieceModel == null) + { + return; + } + _logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); + + if (_manufactureWorkPieces.ContainsKey(form.Id)) + { + _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); + } + else + { + _manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count)); + } + + LoadData(); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece)); + + if (service is FormManufactureWorkPiece form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _manufactureWorkPieces[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.WorkPieceModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента:{ComponentName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); + _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, 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("Удаление заготовки:{WorkPieceName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _manufactureWorkPieces?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + + if (string.IsNullOrEmpty(textBoxCost.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + + if (_manufactureWorkPieces == null || _manufactureWorkPieces.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + + _logger.LogInformation("Сохранение изделия"); + + try + { + var model = new ManufactureBindingModel + { + Id = _id ?? 0, + ManufactureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxCost.Text), + ManufactureWorkPieces = _manufactureWorkPieces + }; + + 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 _manufactureWorkPieces) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx new file mode 100644 index 0000000..be598c0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs new file mode 100644 index 0000000..82b10ad --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs @@ -0,0 +1,119 @@ +namespace BlacksmithWorkshop +{ + partial class FormManufactureWorkPiece + { + /// + /// 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.labelWorkPiece = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxWorkPiece = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelWorkPiece + // + this.labelWorkPiece.AutoSize = true; + this.labelWorkPiece.Location = new System.Drawing.Point(31, 33); + this.labelWorkPiece.Name = "labelWorkPiece"; + this.labelWorkPiece.Size = new System.Drawing.Size(81, 20); + this.labelWorkPiece.TabIndex = 0; + this.labelWorkPiece.Text = "Заготовка:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(31, 79); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxWorkPiece + // + this.comboBoxWorkPiece.FormattingEnabled = true; + this.comboBoxWorkPiece.Location = new System.Drawing.Point(156, 30); + this.comboBoxWorkPiece.Name = "comboBoxWorkPiece"; + this.comboBoxWorkPiece.Size = new System.Drawing.Size(320, 28); + this.comboBoxWorkPiece.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(156, 76); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(320, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(235, 118); + 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(353, 118); + 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); + // + // FormManufactureWorkPiece + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(526, 168); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxWorkPiece); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelWorkPiece); + this.Name = "FormManufactureWorkPiece"; + this.Text = "Заготовки для изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelWorkPiece; + private Label labelCount; + private ComboBox comboBoxWorkPiece; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs new file mode 100644 index 0000000..f367911 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs @@ -0,0 +1,88 @@ +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class FormManufactureWorkPiece : Form + { + private readonly List? _list; + + public int Id { get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); } + set { comboBoxWorkPiece.SelectedValue = value; } } + + public IWorkPieceModel? WorkPieceModel + { + 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 FormManufactureWorkPiece(IWorkPieceLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + + if(_list != null) + { + comboBoxWorkPiece.DisplayMember = "WorkPieceName"; + comboBoxWorkPiece.ValueMember = "Id"; + comboBoxWorkPiece.DataSource = _list; + comboBoxWorkPiece.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + if (comboBoxWorkPiece.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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs new file mode 100644 index 0000000..9bbdb92 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs @@ -0,0 +1,149 @@ +namespace BlacksmithWorkshop +{ + partial class FormManufactures + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(653, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(653, 92); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(653, 151); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(94, 29); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(653, 203); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCost}); + 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(604, 426); + this.dataGridView.TabIndex = 4; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Width = 125; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.ColumnName.HeaderText = "Название"; + this.ColumnName.MinimumWidth = 6; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + this.ColumnName.Width = 301; + // + // ColumnCost + // + this.ColumnCost.HeaderText = "Стоимость"; + this.ColumnCost.MinimumWidth = 6; + this.ColumnCost.Name = "ColumnCost"; + this.ColumnCost.Width = 125; + // + // formManufactures + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(781, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Name = "formManufactures"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormManufactures_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDelete; + private Button buttonRef; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCost; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs new file mode 100644 index 0000000..e0dad9e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -0,0 +1,124 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormManufactures : Form + { + private readonly ILogger _logger; + + private readonly IManufactureLogic _logic; + + public FormManufactures(ILogger logger, IManufactureLogic logic) + { + + InitializeComponent(); + + _logger = logger; + _logic = logic; + } + + private void FormManufactures_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["ColumnName"].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(FormManufacture)); + if (service is FormManufacture 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(FormManufacture)); + + if (service is FormManufacture form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление компонента"); + + try + { + if (!_logic.Delete(new ManufactureBindingModel + { + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.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/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs new file mode 100644 index 0000000..020f587 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs @@ -0,0 +1,119 @@ +namespace BlacksmithWorkshop +{ + partial class FormWorkPiece + { + /// + /// 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.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(30, 24); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(30, 65); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(48, 20); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(127, 21); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(293, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(127, 62); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(179, 27); + this.textBoxPrice.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(326, 104); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(212, 104); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormWorkPiece + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 153); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormWorkPiece"; + this.Text = "Заготовка"; + this.Load += new System.EventHandler(this.FormWorkPiece_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs new file mode 100644 index 0000000..c5a3e7d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs @@ -0,0 +1,103 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshop +{ + // "" + public partial class FormWorkPiece : System.Windows.Forms.Form + { + private readonly ILogger _logger; + + private readonly IWorkPieceLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + // + public FormWorkPiece(ILogger logger, IWorkPieceLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + // + private void FormWorkPiece_Load(object sender, EventArgs e) + { + // id. , + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + + var view = _logic.ReadElement(new WorkPieceSearchModel { Id = _id.Value }); + + if(view != null) + { + textBoxName.Text = view.WorkPieceName; + textBoxPrice.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 WorkPieceBindingModel + { + Id = _id ?? 0, + WorkPieceName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxPrice.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception(" . ."); + } + + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + + Close(); + } + catch(Exception ex ) + { + _logger.LogError(ex, " "); + + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + // . + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.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/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs new file mode 100644 index 0000000..250fce1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs @@ -0,0 +1,149 @@ +namespace BlacksmithWorkshop +{ + partial class FormWorkPieces + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(653, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(653, 92); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(653, 151); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(94, 29); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(653, 203); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCost}); + 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(604, 426); + this.dataGridView.TabIndex = 4; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Width = 125; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.ColumnName.HeaderText = "Название"; + this.ColumnName.MinimumWidth = 6; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + this.ColumnName.Width = 301; + // + // ColumnCost + // + this.ColumnCost.HeaderText = "Стоимость"; + this.ColumnCost.MinimumWidth = 6; + this.ColumnCost.Name = "ColumnCost"; + this.ColumnCost.Width = 125; + // + // FormWorkPieces + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(781, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Name = "FormWorkPieces"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormWorkPiece_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDelete; + private Button buttonRef; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCost; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs new file mode 100644 index 0000000..8943400 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs @@ -0,0 +1,127 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormWorkPieces : Form + { + private readonly ILogger _logger; + + private readonly IManufactureLogic _logic; + + public FormWorkPieces(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormWorkPiece_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + //растягиваем колонку Название на всю ширину, колонку Id скрываем + if(list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ManufactureName"].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(FormWorkPieces)); + + if (service is FormWorkPieces 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(FormWorkPiece)); + + if (service is FormWorkPiece form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + //проверяем наличие выделенной строки + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление компонента"); + + try + { + if (!_logic.Delete(new ManufactureBindingModel + { + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx new file mode 100644 index 0000000..7bec10e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 1d7fc1e..8f7a4c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,17 +1,56 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +using System.Drawing; + namespace BlacksmithWorkshop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, + // To customize application configuration such as set high DPI settings or default font; // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs similarity index 63% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs index c95ec8f..84a3287 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs @@ -12,26 +12,26 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - internal class ArticleLogic : IArticleLogic + public class ManufactureLogic : IManufactureLogic { private readonly ILogger _logger; - private readonly IArticleStorage _articleStorage; + private readonly IManufactureStorage _manufactureStorage; //конструктор - public ArticleLogic(ILogger logger, IArticleStorage productStorage) + public ManufactureLogic(ILogger logger, IManufactureStorage productStorage) { _logger = logger; - _articleStorage = productStorage; + _manufactureStorage = productStorage; } //вывод отфильтрованного списка - public List? ReadList(ArticleSearchModel? model) + public List? ReadList(ManufactureSearchModel? model) { - _logger.LogInformation("ReadList. ArticleName:{ArticleName}. Id:{Id}", model?.ArticleName, model?.Id); + _logger.LogInformation("ReadList. ManufactureName:{ManufactureName}. Id:{Id}", model?.ManufactureName, model?.Id); //list хранит весь список в случае, если model пришло со значением null на вход метода - var list = model == null ? _articleStorage.GetFullList() : _articleStorage.GetFilteredList(model); + var list = model == null ? _manufactureStorage.GetFullList() : _manufactureStorage.GetFilteredList(model); if(list == null) { @@ -45,34 +45,34 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //вывод конкретного изделия - public ArticleViewModel? ReadProduct(ArticleSearchModel model) + public ManufactureViewModel? ReadManufacture(ManufactureSearchModel model) { if(model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadProduct. ArticleName:{ArticleName}. Id:{Id}", model.ArticleName, model.Id); + _logger.LogInformation("ReadManufacture. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id); - var element = _articleStorage.GetElement(model); + var element = _manufactureStorage.GetElement(model); if(element == null) { - _logger.LogWarning("ReadProduct element not found"); + _logger.LogWarning("ReadManufacture element not found"); return null; } - _logger.LogInformation("ReadProduct find. Id:{Id}", model.Id); + _logger.LogInformation("ReadManufacture find. Id:{Id}", model.Id); return element; } //Создание изделия - public bool Create(ArticleBindingModel model) + public bool Create(ManufactureBindingModel model) { CheckModel(model); - if(_articleStorage.Insert(model) == null) + if(_manufactureStorage.Insert(model) == null) { _logger.LogWarning("Create operation failed"); return false; @@ -82,11 +82,11 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //обновление изделия - public bool Update(ArticleBindingModel model) + public bool Update(ManufactureBindingModel model) { CheckModel(model); - if(_articleStorage.Update(model) == null) + if(_manufactureStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -96,11 +96,11 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //удаление изделия - public bool Delete(ArticleBindingModel model) + public bool Delete(ManufactureBindingModel model) { CheckModel(model); - if(_articleStorage.Delete(model) == null) + if(_manufactureStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -110,7 +110,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка входного аргумента для методов Insert, Update и Delete - private void CheckModel(ArticleBindingModel model, bool withParams = true) + private void CheckModel(ManufactureBindingModel model, bool withParams = true) { if(model == null) { @@ -124,9 +124,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка на наличие названия изделия - if (string.IsNullOrEmpty(model.ArticleName)) + if (string.IsNullOrEmpty(model.ManufactureName)) { - throw new ArgumentNullException("Нет названия изделия", nameof(model.ArticleName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.ManufactureName)); } //проверка на наличие нормальной цены у изделия @@ -135,13 +135,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Article. ArticleName:{ArticleName}. Price:{Price}. Id:{Id}", - model.ArticleName, model.Price, model.Id); + _logger.LogInformation("Manufacture. ManufactureName:{ManufactureName}. Price:{Price}. Id:{Id}", + model.ManufactureName, model.Price, model.Id); //проверка на наличие такого же изделия в списке - var element = _articleStorage.GetElement(new ArticleSearchModel + var element = _manufactureStorage.GetElement(new ManufactureSearchModel { - ArticleName = model.ArticleName, + ManufactureName = model.ManufactureName, }); if(element != null && element.Id != model.Id) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index aa8fa2e..3bf131f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -110,9 +110,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //проверка корректности id у изделий - if (model.ArticleId < 0) + if (model.ManufactureId < 0) { - throw new ArgumentNullException("Некорректный id у изделия", nameof(model.ArticleId)); + throw new ArgumentNullException("Некорректный id у изделия", nameof(model.ManufactureId)); } //проверка корректности дат @@ -121,7 +121,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); } - _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ArticleId:{Id}", model.Id, model.Sum, model.ArticleId); + _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}", model.Id, model.Sum, model.ManufactureId); } //обновление статуса заказа diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs index ff09e0a..30bcbaf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs @@ -13,17 +13,17 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { //класс, реализующий логику для компонентов - public class ComponentLogic : IWorkPieceLogic + public class WorkPieceLogic : IWorkPieceLogic { private readonly ILogger _logger; private readonly IWorkPieceStorage _workPieceStorage; //конструктор - public ComponentLogic(ILogger logger, IWorkPieceStorage componentStorage) + public WorkPieceLogic(ILogger logger, IWorkPieceStorage workPieceStorage) { _logger = logger; - _workPieceStorage = componentStorage; + _workPieceStorage = workPieceStorage; } //вывод отфильтрованного списка компонентов @@ -135,7 +135,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Cost)); } - _logger.LogInformation("Component. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}", + _logger.LogInformation("WorkPiece. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}", model.WorkPieceName, model.Cost, model.Id); //проверка на наличие такой же заготовки в списке diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs similarity index 61% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs index 60334e6..84ed77d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs @@ -8,14 +8,14 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { //реализация сущности "Продукт" - public class ArticleBindingModel : IArticleModel + public class ManufactureBindingModel : IManufactureModel { public int Id { get; set; } - public string ArticleName { get; set; } = string.Empty; + public string ManufactureName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ArticleWorkPiece { get; set; } = new(); + public Dictionary ManufactureWorkPieces { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index ec8912a..5ab83dc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -13,7 +13,7 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } - public int ArticleId { get; set; } + public int ManufactureId { get; set; } public int Count { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs similarity index 53% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs index 055d888..43b6b6e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -10,16 +10,16 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BusinessLogicsContracts { //бизнес-логика для продуктов - public interface IArticleLogic + public interface IManufactureLogic { - List? ReadList(ArticleSearchModel? model); + List? ReadList(ManufactureSearchModel? model); - ArticleViewModel? ReadProduct(ArticleSearchModel model); + ManufactureViewModel? ReadManufacture(ManufactureSearchModel model); - bool Create(ArticleBindingModel model); + bool Create(ManufactureBindingModel model); - bool Update(ArticleBindingModel model); + bool Update(ManufactureBindingModel model); - bool Delete(ArticleBindingModel model); + bool Delete(ManufactureBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs similarity index 82% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs index 0a98f7c..d077a1b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs @@ -7,12 +7,12 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.SearchModels { //модель для поиска заготовки "Продукт" (она же изделие) - public class ArticleSearchModel + public class ManufactureSearchModel { //для поиска по идентификатору public int? Id { get; set; } //для поиска по названию - public string? ArticleName { get; set; } + public string? ManufactureName { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs deleted file mode 100644 index e5e47d5..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs +++ /dev/null @@ -1,27 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.StoragesContracts -{ - //класс для хранилища продуктов (изделий) - public interface IArticleStorage - { - List GetFullList(); - - List GetFilteredList(ArticleSearchModel model); - - ArticleViewModel? GetElement(ArticleSearchModel model); - - ArticleViewModel? Insert(ArticleBindingModel model); - - ArticleViewModel? Update(ArticleBindingModel model); - - ArticleViewModel? Delete(ArticleBindingModel model); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs new file mode 100644 index 0000000..fedf71d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs @@ -0,0 +1,27 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + //класс для хранилища продуктов (изделий) + public interface IManufactureStorage + { + List GetFullList(); + + List GetFilteredList(ManufactureSearchModel model); + + ManufactureViewModel? GetElement(ManufactureSearchModel model); + + ManufactureViewModel? Insert(ManufactureBindingModel model); + + ManufactureViewModel? Update(ManufactureBindingModel model); + + ManufactureViewModel? Delete(ManufactureBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs similarity index 71% rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index 492114b..6dca595 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -9,16 +9,16 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.ViewModels { //класс для отображения пользователю информаци о продуктах (изделиях) - public class ArticleViewModel : IArticleModel + public class ManufactureViewModel : IManufactureModel { public int Id { get; set; } [DisplayName("Навание изделия")] - public string ArticleName { get; set; } = string.Empty; + public string ManufactureName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ArticleWorkPiece { get; set; } = new(); + public Dictionary ManufactureWorkPieces { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 8fe2993..2101bed 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -15,10 +15,10 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } - public int ArticleId { get; set; } + public int ManufactureId { get; set; } [DisplayName("Изделие")] - public string ArticleName { get; set; } = string.Empty; + public string ManufactureName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs similarity index 74% rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs index b4437a5..0fcb4f0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs @@ -7,15 +7,15 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels.Models { //интерфейс, отвечающий за продукт - public interface IArticleModel : IId + public interface IManufactureModel : IId { //наименование изделия - string ArticleName { get; } + string ManufactureName { get; } //цена изделия double Price { get; } //словарь, хранящий пары кол-во + компонент и его цена - Dictionary ArticleWorkPiece { get; } + Dictionary ManufactureWorkPieces { get; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 601726f..c36654a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -11,7 +11,7 @@ namespace BlacksmithWorkshopDataModels.Models public interface IOrderModel : IId { //id продукта - int ArticleId { get; } + int ManufactureId { get; } //кол-во продуктов int Count { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index b6da397..e2b2a4c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -16,7 +16,7 @@ namespace BlacksmithWorkshopListImplement public List WorkPieces { get; set; } //список для хранения изделий - public List
Articles { get; set; } + public List Manufactures { get; set; } //список для хранения заказов public List Orders { get; set; } @@ -24,7 +24,7 @@ namespace BlacksmithWorkshopListImplement public DataListSingleton() { WorkPieces = new List(); - Articles = new List
(); + Manufactures = new List(); Orders = new List(); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs deleted file mode 100644 index 3e5eeb8..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs +++ /dev/null @@ -1,138 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopListImplement.Implements -{ - //класс, реализующий интерфейс хранилища изделий - public class ArticleStorage : IArticleStorage - { - //поле для работы со списком изделий - private readonly DataListSingleton _source; - - //получение в конструкторе объекта DataListSingleton - public ArticleStorage() - { - _source = DataListSingleton.GetInstance(); - } - - //получение полного списка изделий - public List GetFullList() - { - var result = new List(); - - foreach(var article in _source.Articles) - { - result.Add(article.GetViewModel); - } - - return result; - } - - //получение отфильтрованного списка изделий - public List GetFilteredList(ArticleSearchModel model) - { - var result = new List(); - - if (string.IsNullOrEmpty(model.ArticleName)) - { - return result; - } - - foreach(var article in _source.Articles) - { - if(article.ArticleName.Contains(model.ArticleName)) - { - result.Add(article.GetViewModel); - } - } - - return result; - } - - //получение элемента из списка изделий - public ArticleViewModel? GetElement(ArticleSearchModel model) - { - if(string.IsNullOrEmpty(model.ArticleName) && !model.Id.HasValue) - { - return null; - } - - foreach(var article in _source.Articles) - { - if((!string.IsNullOrEmpty(model.ArticleName) && article.ArticleName == model.ArticleName) || - (model.Id.HasValue && article.Id == model.Id)) - { - return article.GetViewModel; - } - } - - return null; - } - - //при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1 - public ArticleViewModel? Insert(ArticleBindingModel model) - { - model.Id = 1; - - foreach(var article in _source.Articles) - { - if(model.Id <= article.Id) - { - model.Id = article.Id + 1; - } - } - - var newArticle = Article.Create(model); - - if(newArticle == null) - { - return null; - } - - _source.Articles.Add(newArticle); - - return newArticle.GetViewModel; - } - - //обновление изделия - public ArticleViewModel? Update(ArticleBindingModel model) - { - foreach (var article in _source.Articles) - { - if (article.Id == model.Id) - { - article.Update(model); - - return article.GetViewModel; - } - } - - return null; - } - - //удаление изделия - public ArticleViewModel? Delete(ArticleBindingModel model) - { - for(int i = 0; i < _source.Articles.Count; ++i) - { - if (_source.Articles[i].Id == model.Id) - { - var element = _source.Articles[i]; - _source.Articles.RemoveAt(i); - - return element.GetViewModel; - } - } - - return null; - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..0c27f61 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,138 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + //класс, реализующий интерфейс хранилища изделий + public class ManufactureStorage : IManufactureStorage + { + //поле для работы со списком изделий + private readonly DataListSingleton _source; + + //получение в конструкторе объекта DataListSingleton + public ManufactureStorage() + { + _source = DataListSingleton.GetInstance(); + } + + //получение полного списка изделий + public List GetFullList() + { + var result = new List(); + + foreach(var manufacture in _source.Manufactures) + { + result.Add(manufacture.GetViewModel); + } + + return result; + } + + //получение отфильтрованного списка изделий + public List GetFilteredList(ManufactureSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return result; + } + + foreach(var manufacture in _source.Manufactures) + { + if(manufacture.ManufactureName.Contains(model.ManufactureName)) + { + result.Add(manufacture.GetViewModel); + } + } + + return result; + } + + //получение элемента из списка изделий + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if(string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + + foreach(var manufacture in _source.Manufactures) + { + if((!string.IsNullOrEmpty(model.ManufactureName) && manufacture.ManufactureName == model.ManufactureName) || + (model.Id.HasValue && manufacture.Id == model.Id)) + { + return manufacture.GetViewModel; + } + } + + return null; + } + + //при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1 + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = 1; + + foreach(var manufacture in _source.Manufactures) + { + if(model.Id <= manufacture.Id) + { + model.Id = manufacture.Id + 1; + } + } + + var newManufacture = Manufacture.Create(model); + + if(newManufacture == null) + { + return null; + } + + _source.Manufactures.Add(newManufacture); + + return newManufacture.GetViewModel; + } + + //обновление изделия + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + foreach (var manufacture in _source.Manufactures) + { + if (manufacture.Id == model.Id) + { + manufacture.Update(model); + + return manufacture.GetViewModel; + } + } + + return null; + } + + //удаление изделия + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + for(int i = 0; i < _source.Manufactures.Count; ++i) + { + if (_source.Manufactures[i].Id == model.Id) + { + var element = _source.Manufactures[i]; + _source.Manufactures.RemoveAt(i); + + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs similarity index 63% rename from BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs rename to BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs index d8dd647..ed71631 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs @@ -10,54 +10,54 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopListImplement.Models { //класс реализующий интерфейс модели изделия - public class Article : IArticleModel + public class Manufacture : IManufactureModel { //методы set делаем приватным, чтобы исключить неразрешённые манипуляции public int Id { get; private set; } - public string ArticleName { get; private set; } = string.Empty; + public string ManufactureName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary ArticleWorkPiece { get; private set; } = new Dictionary(); + public Dictionary ManufactureWorkPieces { get; private set; } = new Dictionary(); //метод для создания объекта от класса-компонента на основе класса-BindingModel - public static Article? Create(ArticleBindingModel? model) + public static Manufacture? Create(ManufactureBindingModel? model) { if (model == null) { return null; } - return new Article() + return new Manufacture() { Id = model.Id, - ArticleName = model.ArticleName, + ManufactureName = model.ManufactureName, Price = model.Price, - ArticleWorkPiece = model.ArticleWorkPiece + ManufactureWorkPieces = model.ManufactureWorkPieces }; } //метод изменения существующего объекта - public void Update(ArticleBindingModel? model) + public void Update(ManufactureBindingModel? model) { if (model == null) { return; } - ArticleName = model.ArticleName; + ManufactureName = model.ManufactureName; Price = model.Price; - ArticleWorkPiece = model.ArticleWorkPiece; + ManufactureWorkPieces = model.ManufactureWorkPieces; } //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента - public ArticleViewModel GetViewModel => new() + public ManufactureViewModel GetViewModel => new() { Id = Id, - ArticleName = ArticleName, + ManufactureName = ManufactureName, Price = Price, - ArticleWorkPiece = ArticleWorkPiece + ManufactureWorkPieces = ManufactureWorkPieces }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 84272c5..2f5c338 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -17,7 +17,7 @@ namespace BlacksmithWorkshopListImplement.Models //методы set сделали приватными, чтобы исключить неразрешённые манипуляции public int Id { get; private set; } - public int ArticleId { get; private set; } + public int ManufactureId { get; private set; } public int Count { get; private set; } @@ -25,7 +25,7 @@ namespace BlacksmithWorkshopListImplement.Models public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } + public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } @@ -38,12 +38,12 @@ namespace BlacksmithWorkshopListImplement.Models return new Order() { - ArticleId = model.ArticleId, + ManufactureId = model.ManufactureId, Count = model.Count, Sum = model.Sum, Status = model.Status, - DateCreate = model.DateCreate, //а надо ли? - DateImplement = model.DateImplement //а надо ли? + DateCreate = model.DateCreate, + DateImplement = model.DateImplement }; } @@ -55,23 +55,23 @@ namespace BlacksmithWorkshopListImplement.Models return; } - ArticleId = model.ArticleId; + ManufactureId = model.ManufactureId; Count = model.Count; Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; //а надо ли? - DateImplement = model.DateImplement; //а надо ли? + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; } //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента public OrderViewModel GetViewModel => new() { - ArticleId = ArticleId, + ManufactureId = ManufactureId, Count = Count, Sum = Sum, Status = Status, - DateCreate = DateCreate, //а надо ли? - DateImplement = DateImplement //а надо ли? + DateCreate = DateCreate, + DateImplement = DateImplement }; } } -- 2.25.1 From 5d37351d2256784dceca4425cfa6f8fa94c702f0 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 21:59:33 +0400 Subject: [PATCH 19/26] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=BE=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop.csproj | 6 +++++ .../BlacksmithWorkshop/FormCreateOrder.cs | 2 +- .../BlacksmithWorkshop/FormManufacture.cs | 2 +- .../BlacksmithWorkshop/Program.cs | 1 + .../BusinessLogic/ManufactureLogic.cs | 23 ++++++++++++------- .../BusinessLogic/OrderLogic.cs | 5 ++-- .../BusinessLogic/WorkPieceLogic.cs | 13 ++++++++--- .../BindingModels/ManufactureBindingModel.cs | 2 +- .../BindingModels/WorkPieceBindingModel.cs | 4 ++-- .../IManufactureLogic.cs | 2 +- .../ViewModels/OrderViewModel.cs | 4 ++-- 11 files changed, 43 insertions(+), 21 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index b363b98..8844615 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -8,6 +8,12 @@ enable + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index 4295273..c988e63 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -46,7 +46,7 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); - var manufacture = _logicA.ReadManufacture(new ManufactureSearchModel + var manufacture = _logicA.ReadElement(new ManufactureSearchModel { Id = id }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index af32e51..70119b1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -44,7 +44,7 @@ namespace BlacksmithWorkshop try { - var view = _logic.ReadManufacture(new ManufactureSearchModel { Id = _id.Value }); + var view = _logic.ReadElement(new ManufactureSearchModel { Id = _id.Value }); if(view != null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 8f7a4c9..f0537ce 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -49,6 +49,7 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs index 84a3287..78b61a1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs @@ -19,10 +19,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic private readonly IManufactureStorage _manufactureStorage; //конструктор - public ManufactureLogic(ILogger logger, IManufactureStorage productStorage) + public ManufactureLogic(ILogger logger, IManufactureStorage manufactureStorage) { _logger = logger; - _manufactureStorage = productStorage; + _manufactureStorage = manufactureStorage; } //вывод отфильтрованного списка @@ -36,6 +36,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(list == null) { _logger.LogWarning("ReadList return null list"); + return null; } @@ -45,24 +46,25 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //вывод конкретного изделия - public ManufactureViewModel? ReadManufacture(ManufactureSearchModel model) + public ManufactureViewModel? ReadElement(ManufactureSearchModel model) { if(model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadManufacture. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id); + _logger.LogInformation("ReadElement. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id); var element = _manufactureStorage.GetElement(model); if(element == null) { - _logger.LogWarning("ReadManufacture element not found"); + _logger.LogWarning("ReadElement element not found"); + return null; } - _logger.LogInformation("ReadManufacture find. Id:{Id}", model.Id); + _logger.LogInformation("ReadElement find. Id:{Id}", model.Id); return element; } @@ -75,6 +77,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_manufactureStorage.Insert(model) == null) { _logger.LogWarning("Create operation failed"); + return false; } @@ -98,11 +101,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //удаление изделия public bool Delete(ManufactureBindingModel model) { - CheckModel(model); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); if(_manufactureStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); + return false; } @@ -117,7 +123,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? + //так как при удалении параметром withParams передаём false if (!withParams) { return; @@ -144,6 +150,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic ManufactureName = model.ManufactureName, }); + //если элемент найден и его Id не совпадает с Id объекта, переданного на вход if(element != null && element.Id != model.Id) { throw new InvalidOperationException("Изделие с таким названием уже есть"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index 3bf131f..d1b08bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -37,6 +37,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(list == null) { _logger.LogWarning("ReadList return null list"); + return null; } @@ -91,8 +92,8 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? - if(!withParams) + //так как при удалении параметром withParams передаём false + if (!withParams) { return; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs index 30bcbaf..d9dd9b8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - //класс, реализующий логику для компонентов + //класс, реализующий логику для заготовок public class WorkPieceLogic : IWorkPieceLogic { private readonly ILogger _logger; @@ -60,6 +60,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(element == null) { _logger.LogWarning("ReadElement element not found"); + return null; } @@ -76,6 +77,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_workPieceStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); + return false; } @@ -90,6 +92,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_workPieceStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); + return false; } @@ -99,11 +102,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //удаление заготовки public bool Delete(WorkPieceBindingModel model) { - CheckModel(model); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_workPieceStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); + return false; } @@ -118,7 +124,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? + //так как при удалении передаём как параметр false if (!withParams) { return; @@ -144,6 +150,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic WorkPieceName = model.WorkPieceName, }); + //если элемент найден и его Id не совпадает с Id переданного объекта if(element != null && element.Id != model.Id) { throw new InvalidOperationException("Заготовка с таким названием уже есть"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs index 84ed77d..73ad4bd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { - //реализация сущности "Продукт" + //реализация сущности "Изделие" public class ManufactureBindingModel : IManufactureModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs index 68b53da..bbb7056 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs @@ -12,8 +12,8 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } - public double Cost { get; set; } - public string WorkPieceName { get; set; } = string.Empty; + + public double Cost { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs index 43b6b6e..b607c8d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -14,7 +14,7 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts { List? ReadList(ManufactureSearchModel? model); - ManufactureViewModel? ReadManufacture(ManufactureSearchModel model); + ManufactureViewModel? ReadElement(ManufactureSearchModel model); bool Create(ManufactureBindingModel model); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 2101bed..c7a3f78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -27,10 +27,10 @@ namespace BlacksmithWorkshopContracts.ViewModels public double Sum { get; set; } [DisplayName("Статус")] - public OrderStatus Status { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } + public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } -- 2.25.1 From e5a9b72a7602a96ef0cb8bbf5270107798633804 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 22:37:47 +0400 Subject: [PATCH 20/26] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=BA=D0=BE=D0=B4=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormCreateOrder.cs | 22 ++++++++--------- .../FormManufacture.Designer.cs | 16 ++++++------- .../BlacksmithWorkshop/FormManufacture.cs | 24 ++++++++++--------- .../BlacksmithWorkshop/FormManufacture.resx | 6 +++++ .../FormManufactureWorkPiece.cs | 1 + .../BlacksmithWorkshop/FormManufactures.cs | 6 ++--- .../FormWorkPiece.Designer.cs | 16 ++++++------- .../BlacksmithWorkshop/FormWorkPiece.cs | 7 +++--- .../BlacksmithWorkshop/FormWorkPieces.cs | 19 +++++++-------- 9 files changed, 62 insertions(+), 55 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index c988e63..b9559a3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -18,16 +18,16 @@ namespace BlacksmithWorkshop { private readonly ILogger _logger; - private readonly IManufactureLogic _logicA; + private readonly IManufactureLogic _logicM; private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IManufactureLogic logicA, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IManufactureLogic logicM, IOrderLogic logicO) { InitializeComponent(); _logger = logger; - _logicA = logicA; + _logicM = logicM; _logicO = logicO; } @@ -46,12 +46,13 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); - var manufacture = _logicA.ReadElement(new ManufactureSearchModel + var manufacture = _logicM.ReadElement(new ManufactureSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (manufacture?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); @@ -64,12 +65,12 @@ namespace BlacksmithWorkshop } } - private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) + private void TextBoxCount_TextChanged(object sender, EventArgs e) { CalcSum(); } - private void TextBoxCount_TextChanged(object sender, EventArgs e) + private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) { CalcSum(); } @@ -78,16 +79,14 @@ namespace BlacksmithWorkshop { if (string.IsNullOrEmpty(textBoxCount.Text)) { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxManufacture.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } @@ -108,8 +107,7 @@ namespace BlacksmithWorkshop throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs index 0a4a273..b1cad83 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs @@ -31,7 +31,7 @@ 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.textBoxPrice = new System.Windows.Forms.TextBox(); this.groupBoxWorkPiece = new System.Windows.Forms.GroupBox(); this.buttonRef = new System.Windows.Forms.Button(); this.buttonDel = new System.Windows.Forms.Button(); @@ -71,12 +71,12 @@ this.textBoxName.Size = new System.Drawing.Size(332, 27); this.textBoxName.TabIndex = 2; // - // textBoxCost + // textBoxPrice // - this.textBoxCost.Location = new System.Drawing.Point(133, 81); - this.textBoxCost.Name = "textBoxCost"; - this.textBoxCost.Size = new System.Drawing.Size(196, 27); - this.textBoxCost.TabIndex = 3; + this.textBoxPrice.Location = new System.Drawing.Point(133, 81); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(196, 27); + this.textBoxPrice.TabIndex = 3; // // groupBoxWorkPiece // @@ -187,7 +187,7 @@ this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.groupBoxWorkPiece); - this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxPrice); this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelCost); this.Controls.Add(this.labelName); @@ -206,7 +206,7 @@ private Label labelName; private Label labelCost; private TextBox textBoxName; - private TextBox textBoxCost; + private TextBox textBoxPrice; private GroupBox groupBoxWorkPiece; private Button buttonRef; private Button buttonDel; diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index 70119b1..1aed36c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -49,7 +49,7 @@ namespace BlacksmithWorkshop if(view != null) { textBoxName.Text = view.ManufactureName; - textBoxCost.Text = view.Price.ToString(); + textBoxPrice.Text = view.Price.ToString(); _manufactureWorkPieces = view.ManufactureWorkPieces ?? new Dictionary(); LoadData(); } @@ -77,7 +77,7 @@ namespace BlacksmithWorkshop dataGridView.Rows.Add(new object[] { awp.Key, awp.Value.Item1.WorkPieceName, awp.Value.Item2 }); } - textBoxCost.Text = CalcPrice().ToString(); + textBoxPrice.Text = CalcPrice().ToString(); } } catch(Exception ex) @@ -90,13 +90,16 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece)); + if (service is FormManufactureWorkPiece form) + { if (form.ShowDialog() == DialogResult.OK) { if (form.WorkPieceModel == null) { return; } + _logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); if (_manufactureWorkPieces.ContainsKey(form.Id)) @@ -110,6 +113,7 @@ namespace BlacksmithWorkshop LoadData(); } + } } private void ButtonUpd_Click(object sender, EventArgs e) @@ -131,7 +135,7 @@ namespace BlacksmithWorkshop return; } - _logger.LogInformation("Изменение компонента:{ComponentName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); + _logger.LogInformation("Изменение компонента:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count); _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count); LoadData(); @@ -144,8 +148,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { @@ -154,8 +157,7 @@ namespace BlacksmithWorkshop } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); @@ -177,7 +179,7 @@ namespace BlacksmithWorkshop return; } - if (string.IsNullOrEmpty(textBoxCost.Text)) + if (string.IsNullOrEmpty(textBoxPrice.Text)) { MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -199,12 +201,11 @@ namespace BlacksmithWorkshop { Id = _id ?? 0, ManufactureName = textBoxName.Text, - Price = Convert.ToDouble(textBoxCost.Text), + Price = Convert.ToDouble(textBoxPrice.Text), ManufactureWorkPieces = _manufactureWorkPieces }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { @@ -229,6 +230,7 @@ namespace BlacksmithWorkshop Close(); } + //в конце умножить на 1.1, так как прибавляем к итоговой стоимости некоторый процент (в данном случае 10%) private double CalcPrice() { double price = 0; diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx index be598c0..28b295d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx @@ -63,4 +63,10 @@ True + + True + + + True + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs index f367911..867351a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs @@ -68,6 +68,7 @@ namespace BlacksmithWorkshop return; } + if (comboBoxWorkPiece.SelectedValue == null) { MessageBox.Show("Выберите заготовку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index e0dad9e..cb2c552 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -46,11 +46,11 @@ namespace BlacksmithWorkshop dataGridView.Columns["ColumnName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки изделий"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -93,7 +93,7 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); + _logger.LogInformation("Удаление изделия"); try { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs index 020f587..c508b2a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs @@ -31,7 +31,7 @@ this.labelName = new System.Windows.Forms.Label(); this.labelPrice = new System.Windows.Forms.Label(); this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); this.SuspendLayout(); @@ -61,12 +61,12 @@ this.textBoxName.Size = new System.Drawing.Size(293, 27); this.textBoxName.TabIndex = 2; // - // textBoxPrice + // textBoxCost // - this.textBoxPrice.Location = new System.Drawing.Point(127, 62); - this.textBoxPrice.Name = "textBoxPrice"; - this.textBoxPrice.Size = new System.Drawing.Size(179, 27); - this.textBoxPrice.TabIndex = 3; + this.textBoxCost.Location = new System.Drawing.Point(127, 62); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(179, 27); + this.textBoxCost.TabIndex = 3; // // buttonCancel // @@ -95,7 +95,7 @@ this.ClientSize = new System.Drawing.Size(464, 153); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxCost); this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelPrice); this.Controls.Add(this.labelName); @@ -112,7 +112,7 @@ private Label labelName; private Label labelPrice; private TextBox textBoxName; - private TextBox textBoxPrice; + private TextBox textBoxCost; private Button buttonCancel; private Button buttonSave; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs index c5a3e7d..94bce93 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace BlacksmithWorkshop { // "" - public partial class FormWorkPiece : System.Windows.Forms.Form + public partial class FormWorkPiece : Form { private readonly ILogger _logger; @@ -20,6 +20,7 @@ namespace BlacksmithWorkshop public FormWorkPiece(ILogger logger, IWorkPieceLogic logic) { InitializeComponent(); + _logger = logger; _logic = logic; } @@ -39,7 +40,7 @@ namespace BlacksmithWorkshop if(view != null) { textBoxName.Text = view.WorkPieceName; - textBoxPrice.Text = view.Cost.ToString(); + textBoxCost.Text = view.Cost.ToString(); } } catch(Exception ex) @@ -70,7 +71,7 @@ namespace BlacksmithWorkshop { Id = _id ?? 0, WorkPieceName = textBoxName.Text, - Cost = Convert.ToDouble(textBoxPrice.Text) + Cost = Convert.ToDouble(textBoxCost.Text) }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs index 8943400..0007c92 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs @@ -17,9 +17,9 @@ namespace BlacksmithWorkshop { private readonly ILogger _logger; - private readonly IManufactureLogic _logic; + private readonly IWorkPieceLogic _logic; - public FormWorkPieces(ILogger logger, IManufactureLogic logic) + public FormWorkPieces(ILogger logger, IWorkPieceLogic logic) { InitializeComponent(); _logger = logger; @@ -42,14 +42,14 @@ namespace BlacksmithWorkshop { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkPieceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка заготовок"); } catch(Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки заготовок"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -57,9 +57,9 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkPieces)); + var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece)); - if (service is FormWorkPieces form) + if (service is FormWorkPiece form) { if (form.ShowDialog() == DialogResult.OK) { @@ -99,7 +99,7 @@ namespace BlacksmithWorkshop try { - if (!_logic.Delete(new ManufactureBindingModel + if (!_logic.Delete(new WorkPieceBindingModel { Id = id })) @@ -112,8 +112,7 @@ namespace BlacksmithWorkshop catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } -- 2.25.1 From 51d367dbc395b4d044645ef735f9bf2f503e381d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 22:48:22 +0400 Subject: [PATCH 21/26] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormCreateOrder.cs | 22 ++++++++++++++-- .../BlacksmithWorkshop/FormMain.cs | 25 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index b9559a3..2a0ffa7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -1,6 +1,7 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,8 +35,25 @@ namespace BlacksmithWorkshop private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - - //дописать логику + + try + { + var list = _logicM.ReadList(null); + + if (list != null) + { + comboBoxManufacture.DisplayMember = "ManufactureName"; + comboBoxManufacture.ValueMember = "Id"; + comboBoxManufacture.DataSource = list; + comboBoxManufacture.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index ac32701..6468768 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -36,7 +36,23 @@ namespace BlacksmithWorkshop { _logger.LogInformation("Загрузка заказов"); - //прописать логику + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ManufactureId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void ЗаготовкиToolStripMenuItem_Click(object sender, EventArgs e) @@ -51,7 +67,12 @@ namespace BlacksmithWorkshop private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - //прописать логику + var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + + if (service is FormManufactures form) + { + form.ShowDialog(); + } } private void ButtonCreateOrder_Click(object sender, EventArgs e) -- 2.25.1 From 2dde084ba1215f89a94e67dcf073d91fa846c5e2 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 22:59:29 +0400 Subject: [PATCH 22/26] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=D1=85=20=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BB=D0=B1=D1=86=D0=BE=D0=B2=20=D0=B2=D0=BE=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=D1=85=20DataGrid.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 71 ------------------- .../BlacksmithWorkshop/FormMain.resx | 42 ----------- .../FormManufacture.Designer.cs | 21 ------ .../BlacksmithWorkshop/FormManufacture.resx | 12 ---- .../FormManufactures.Designer.cs | 38 +--------- .../FormWorkPieces.Designer.cs | 34 --------- .../BlacksmithWorkshop/FormWorkPieces.resx | 9 --- 7 files changed, 2 insertions(+), 225 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 1fe2054..b200bf0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -29,13 +29,6 @@ private void InitializeComponent() { this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnSum = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnStatus = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnDateCreate = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnDateImplement = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); @@ -52,14 +45,6 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.ColumnManufacture, - this.ColumnCount, - this.ColumnSum, - this.ColumnStatus, - this.ColumnDateCreate, - this.ColumnDateImplement}); this.dataGridView.Location = new System.Drawing.Point(12, 36); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; @@ -67,55 +52,6 @@ this.dataGridView.Size = new System.Drawing.Size(937, 402); this.dataGridView.TabIndex = 0; // - // ColumnId - // - this.ColumnId.HeaderText = "Номер"; - this.ColumnId.MinimumWidth = 6; - this.ColumnId.Name = "ColumnId"; - this.ColumnId.Width = 125; - // - // ColumnManufacture - // - this.ColumnManufacture.HeaderText = "Изделие"; - this.ColumnManufacture.MinimumWidth = 6; - this.ColumnManufacture.Name = "ColumnManufacture"; - this.ColumnManufacture.Width = 125; - // - // ColumnCount - // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.MinimumWidth = 6; - this.ColumnCount.Name = "ColumnCount"; - this.ColumnCount.Width = 125; - // - // ColumnSum - // - this.ColumnSum.HeaderText = "Сумма"; - this.ColumnSum.MinimumWidth = 6; - this.ColumnSum.Name = "ColumnSum"; - this.ColumnSum.Width = 125; - // - // ColumnStatus - // - this.ColumnStatus.HeaderText = "Статус"; - this.ColumnStatus.MinimumWidth = 6; - this.ColumnStatus.Name = "ColumnStatus"; - this.ColumnStatus.Width = 125; - // - // ColumnDateCreate - // - this.ColumnDateCreate.HeaderText = "Дата создания"; - this.ColumnDateCreate.MinimumWidth = 6; - this.ColumnDateCreate.Name = "ColumnDateCreate"; - this.ColumnDateCreate.Width = 125; - // - // ColumnDateImplement - // - this.ColumnDateImplement.HeaderText = "Дата выполнения"; - this.ColumnDateImplement.MinimumWidth = 6; - this.ColumnDateImplement.Name = "ColumnDateImplement"; - this.ColumnDateImplement.Width = 125; - // // buttonCreateOrder // this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 66); @@ -236,12 +172,5 @@ private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem заготовкиToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnManufacture; - private DataGridViewTextBoxColumn ColumnCount; - private DataGridViewTextBoxColumn ColumnSum; - private DataGridViewTextBoxColumn ColumnStatus; - private DataGridViewTextBoxColumn ColumnDateCreate; - private DataGridViewTextBoxColumn ColumnDateImplement; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx index eb63604..938108a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx @@ -57,48 +57,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - 17, 17 diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs index b1cad83..dc55b46 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs @@ -38,8 +38,6 @@ this.buttonUpd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnWorkPiece = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxWorkPiece.SuspendLayout(); @@ -135,9 +133,6 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnWorkPiece, - this.ColumnCount}); this.dataGridView.Location = new System.Drawing.Point(6, 26); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; @@ -145,20 +140,6 @@ this.dataGridView.Size = new System.Drawing.Size(416, 268); this.dataGridView.TabIndex = 0; // - // ColumnWorkPiece - // - this.ColumnWorkPiece.HeaderText = "Заготовка"; - this.ColumnWorkPiece.MinimumWidth = 6; - this.ColumnWorkPiece.Name = "ColumnWorkPiece"; - this.ColumnWorkPiece.Width = 125; - // - // ColumnCount - // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.MinimumWidth = 6; - this.ColumnCount.Name = "ColumnCount"; - this.ColumnCount.Width = 125; - // // buttonSave // this.buttonSave.Location = new System.Drawing.Point(340, 448); @@ -215,7 +196,5 @@ private DataGridView dataGridView; private Button buttonSave; private Button buttonCancel; - private DataGridViewTextBoxColumn ColumnWorkPiece; - private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx index 28b295d..f298a7b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx @@ -57,16 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs index 9bbdb92..010505c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs @@ -33,9 +33,6 @@ this.buttonDelete = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -82,10 +79,6 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.ColumnName, - this.ColumnCost}); this.dataGridView.Location = new System.Drawing.Point(12, 12); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; @@ -93,31 +86,7 @@ this.dataGridView.Size = new System.Drawing.Size(604, 426); this.dataGridView.TabIndex = 4; // - // ColumnId - // - this.ColumnId.HeaderText = "Id"; - this.ColumnId.MinimumWidth = 6; - this.ColumnId.Name = "ColumnId"; - this.ColumnId.ReadOnly = true; - this.ColumnId.Width = 125; - // - // ColumnName - // - this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; - this.ColumnName.HeaderText = "Название"; - this.ColumnName.MinimumWidth = 6; - this.ColumnName.Name = "ColumnName"; - this.ColumnName.ReadOnly = true; - this.ColumnName.Width = 301; - // - // ColumnCost - // - this.ColumnCost.HeaderText = "Стоимость"; - this.ColumnCost.MinimumWidth = 6; - this.ColumnCost.Name = "ColumnCost"; - this.ColumnCost.Width = 125; - // - // formManufactures + // FormManufactures // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -127,7 +96,7 @@ this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonUpd); this.Controls.Add(this.buttonAdd); - this.Name = "formManufactures"; + this.Name = "FormManufactures"; this.Text = "Изделия"; this.Load += new System.EventHandler(this.FormManufactures_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); @@ -142,8 +111,5 @@ private Button buttonDelete; private Button buttonRef; private DataGridView dataGridView; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnName; - private DataGridViewTextBoxColumn ColumnCost; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs index 250fce1..4c90cfd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs @@ -33,9 +33,6 @@ this.buttonDelete = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -82,10 +79,6 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.ColumnName, - this.ColumnCost}); this.dataGridView.Location = new System.Drawing.Point(12, 12); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; @@ -93,30 +86,6 @@ this.dataGridView.Size = new System.Drawing.Size(604, 426); this.dataGridView.TabIndex = 4; // - // ColumnId - // - this.ColumnId.HeaderText = "Id"; - this.ColumnId.MinimumWidth = 6; - this.ColumnId.Name = "ColumnId"; - this.ColumnId.ReadOnly = true; - this.ColumnId.Width = 125; - // - // ColumnName - // - this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; - this.ColumnName.HeaderText = "Название"; - this.ColumnName.MinimumWidth = 6; - this.ColumnName.Name = "ColumnName"; - this.ColumnName.ReadOnly = true; - this.ColumnName.Width = 301; - // - // ColumnCost - // - this.ColumnCost.HeaderText = "Стоимость"; - this.ColumnCost.MinimumWidth = 6; - this.ColumnCost.Name = "ColumnCost"; - this.ColumnCost.Width = 125; - // // FormWorkPieces // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -142,8 +111,5 @@ private Button buttonDelete; private Button buttonRef; private DataGridView dataGridView; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnName; - private DataGridViewTextBoxColumn ColumnCost; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx index 7bec10e..f298a7b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx @@ -57,13 +57,4 @@ 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 09ca448bb04e45191fb81bc9b77ae051305ac608 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 12 Feb 2023 23:06:37 +0400 Subject: [PATCH 23/26] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 6468768..5d90425 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -67,9 +67,9 @@ namespace BlacksmithWorkshop private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); - if (service is FormManufactures form) + if (service is FormManufacture form) { form.ShowDialog(); } -- 2.25.1 From 52e276b9bd5776b63346e0f64668246cf43c234c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 13 Feb 2023 21:53:02 +0400 Subject: [PATCH 24/26] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 32 ++++++++--------- .../BlacksmithWorkshop/FormMain.cs | 6 ++-- .../FormManufacture.Designer.cs | 34 ++++++++++++++++++- .../BlacksmithWorkshop/FormManufacture.resx | 9 +++++ .../FormWorkPieces.Designer.cs | 2 +- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index b200bf0..fbe5a08 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -36,8 +36,8 @@ this.buttonRef = new System.Windows.Forms.Button(); 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.workPieceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.manufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -116,25 +116,25 @@ // toolStripMenuItem // this.toolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.заготовкиToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.workPieceToolStripMenuItem, + this.manufactureToolStripMenuItem}); this.toolStripMenuItem.Name = "toolStripMenuItem"; this.toolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.toolStripMenuItem.Text = "Справочники"; // - // заготовкиToolStripMenuItem + // workPieceToolStripMenuItem // - this.заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; - this.заготовкиToolStripMenuItem.Size = new System.Drawing.Size(162, 26); - this.заготовкиToolStripMenuItem.Text = "Заготовки"; - this.заготовкиToolStripMenuItem.Click += new System.EventHandler(this.ЗаготовкиToolStripMenuItem_Click); + this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; + this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.workPieceToolStripMenuItem.Text = "Заготовки"; + this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click); // - // изделияToolStripMenuItem + // manufactureToolStripMenuItem // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(162, 26); - this.изделияToolStripMenuItem.Text = "Изделия"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + this.manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem"; + this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.manufactureToolStripMenuItem.Text = "Изделия"; + this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click); // // FormMain // @@ -170,7 +170,7 @@ private Button buttonRef; private MenuStrip menuStrip1; private ToolStripMenuItem toolStripMenuItem; - private ToolStripMenuItem заготовкиToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem workPieceToolStripMenuItem; + private ToolStripMenuItem manufactureToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 5d90425..cef0744 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -55,17 +55,17 @@ namespace BlacksmithWorkshop } } - private void ЗаготовкиToolStripMenuItem_Click(object sender, EventArgs e) + private void WorkPieceToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormWorkPieces)); - if(service is FormWorkPieces form) + if (service is FormWorkPieces form) { form.ShowDialog(); } } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + private void ManufactureToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs index dc55b46..916f3d3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs @@ -40,6 +40,9 @@ this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBoxWorkPiece.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -133,11 +136,15 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnID, + this.ColumnName, + this.ColumnPrice}); 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(416, 268); + this.dataGridView.Size = new System.Drawing.Size(436, 268); this.dataGridView.TabIndex = 0; // // buttonSave @@ -160,6 +167,28 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // ColumnID + // + this.ColumnID.HeaderText = "Id"; + this.ColumnID.MinimumWidth = 6; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + this.ColumnID.Width = 125; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnName.HeaderText = "Название"; + this.ColumnName.MinimumWidth = 6; + this.ColumnName.Name = "ColumnName"; + // + // ColumnPrice + // + this.ColumnPrice.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnPrice.HeaderText = "Количество"; + this.ColumnPrice.MinimumWidth = 6; + this.ColumnPrice.Name = "ColumnPrice"; + // // FormManufacture // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -196,5 +225,8 @@ private DataGridView dataGridView; private Button buttonSave; private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnPrice; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx index f298a7b..fb971ef 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.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 diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs index 4c90cfd..be21959 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs @@ -97,7 +97,7 @@ this.Controls.Add(this.buttonUpd); this.Controls.Add(this.buttonAdd); this.Name = "FormWorkPieces"; - this.Text = "Компоненты"; + this.Text = "Заготовки"; this.Load += new System.EventHandler(this.FormWorkPiece_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); -- 2.25.1 From 3cd62dec9ed05cd684dab083a55256bda6d75c0c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 13 Feb 2023 23:06:34 +0400 Subject: [PATCH 25/26] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 6 ++-- .../BlacksmithWorkshop/FormMain.cs | 32 ++++++++++++++----- .../BlacksmithWorkshop/FormManufactures.cs | 4 ++- .../Implements/OrderStorage.cs | 30 +++++++++++++---- .../Models/Order.cs | 7 ++-- 5 files changed, 56 insertions(+), 23 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index fbe5a08..018e907 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -125,14 +125,14 @@ // workPieceToolStripMenuItem // this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; - this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(162, 26); this.workPieceToolStripMenuItem.Text = "Заготовки"; this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click); // // manufactureToolStripMenuItem // this.manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem"; - this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(162, 26); this.manufactureToolStripMenuItem.Text = "Изделия"; this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click); // @@ -150,7 +150,7 @@ this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "FormMain"; - this.Text = "Абстрактный магазин"; + this.Text = "Кузнечная мастерская"; this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index cef0744..37a970d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -67,9 +68,9 @@ namespace BlacksmithWorkshop private void ManufactureToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); - if (service is FormManufacture form) + if (service is FormManufactures form) { form.ShowDialog(); } @@ -97,8 +98,13 @@ namespace BlacksmithWorkshop try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) }); if (!operationResult) @@ -126,8 +132,13 @@ namespace BlacksmithWorkshop try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) }); if (!operationResult) @@ -155,8 +166,13 @@ namespace BlacksmithWorkshop try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) }); if (!operationResult) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index cb2c552..00d71a4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -43,7 +43,8 @@ namespace BlacksmithWorkshop { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ColumnName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ManufactureWorkPieces"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка изделий"); @@ -58,6 +59,7 @@ namespace BlacksmithWorkshop private void ButtonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + if (service is FormManufacture form) { if (form.ShowDialog() == DialogResult.OK) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 2d78549..10fc34a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -30,7 +30,7 @@ namespace BlacksmithWorkshopListImplement.Implements foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; @@ -50,7 +50,7 @@ namespace BlacksmithWorkshopListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } @@ -69,13 +69,31 @@ namespace BlacksmithWorkshopListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetViewModel(order); } } return null; } + //метод для записи названия изделия на форме с заказами + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + foreach (var manufactures in _source.Manufactures) + { + if (manufactures.Id == order.ManufactureId) + { + viewModel.ManufactureName = manufactures.ManufactureName; + + break; + } + } + + return viewModel; + } + //при создании заказа определяем для него новый id: ищем max id и прибавляем к нему 1 public OrderViewModel? Insert(OrderBindingModel model) { @@ -98,7 +116,7 @@ namespace BlacksmithWorkshopListImplement.Implements _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } //обновление заказа @@ -110,7 +128,7 @@ namespace BlacksmithWorkshopListImplement.Implements { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } @@ -127,7 +145,7 @@ namespace BlacksmithWorkshopListImplement.Implements var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 2f5c338..dbcc42d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -38,6 +38,7 @@ namespace BlacksmithWorkshopListImplement.Models return new Order() { + Id = model.Id, ManufactureId = model.ManufactureId, Count = model.Count, Sum = model.Sum, @@ -54,18 +55,14 @@ namespace BlacksmithWorkshopListImplement.Models { return; } - - ManufactureId = model.ManufactureId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } //метод для создания объекта класса ViewModel на основе данных объекта класса-компонента public OrderViewModel GetViewModel => new() { + Id = Id, ManufactureId = ManufactureId, Count = Count, Sum = Sum, -- 2.25.1 From b187f20196f6b74cb74532c7f5964454f584bc7b Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Feb 2023 11:49:17 +0400 Subject: [PATCH 26/26] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 21 +++---------------- .../BusinessLogic/OrderLogic.cs | 18 +++++++++++++--- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 37a970d..a8faa65 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,12 +99,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) @@ -133,12 +128,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) @@ -167,12 +157,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index d1b08bb..ad0169d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -128,10 +128,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //обновление статуса заказа public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + //если не смогли найти указанный заказ по его Id + if(viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } //проверка на возможность обновления статуса на следующий - if(model.Status + 1 != newOrderStatus) + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + " incorrect"); return false; @@ -144,9 +150,15 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { model.DateImplement = DateTime.Now; } + else + { + model.DateImplement = viewModel.DateImplement; + } + + CheckModel(model, false); //финальная проверка на возможность обновления - if(_orderStorage.Update(model) == null) + if (_orderStorage.Update(model) == null) { model.Status--; -- 2.25.1