From 6f33a1199f8579b490fde99e916df45f1c96e0d7 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 17:40:39 +0400 Subject: [PATCH 01/21] 1 --- .../AbstractJewelryStoreModels.csproj | 9 +++++++++ AbstractShopDataModels/Enums/OrderStatus.cs | 12 ++++++++++++ AbstractShopDataModels/IId.cs | 7 +++++++ JewelryStore/JewelryStore.sln | 8 +++++++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 AbstractShopDataModels/AbstractJewelryStoreModels.csproj create mode 100644 AbstractShopDataModels/Enums/OrderStatus.cs create mode 100644 AbstractShopDataModels/IId.cs diff --git a/AbstractShopDataModels/AbstractJewelryStoreModels.csproj b/AbstractShopDataModels/AbstractJewelryStoreModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/AbstractShopDataModels/AbstractJewelryStoreModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/AbstractShopDataModels/Enums/OrderStatus.cs b/AbstractShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..8a79b8a --- /dev/null +++ b/AbstractShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractJewelryStoreModels.Enums +{ + internal class OrderStatus + { + } +} diff --git a/AbstractShopDataModels/IId.cs b/AbstractShopDataModels/IId.cs new file mode 100644 index 0000000..1c7b0a7 --- /dev/null +++ b/AbstractShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace AbstractShopDataModels +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index e6cc653..76431b5 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractJewelryStoreModels", "..\AbstractShopDataModels\AbstractJewelryStoreModels.csproj", "{BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.Build.0 = Release|Any CPU + {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From 1c086e4d643f8b5d9f668fc236bbdaf049349096 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 17:41:50 +0400 Subject: [PATCH 02/21] 1 --- .../AbstractJewelryStoreModels.csproj | 6 +++++- AbstractShopDataModels/Enums/OrderStatus.cs | 17 ++++++++--------- AbstractShopDataModels/IId.cs | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/AbstractShopDataModels/AbstractJewelryStoreModels.csproj b/AbstractShopDataModels/AbstractJewelryStoreModels.csproj index 132c02c..962b8f6 100644 --- a/AbstractShopDataModels/AbstractJewelryStoreModels.csproj +++ b/AbstractShopDataModels/AbstractJewelryStoreModels.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,4 +6,8 @@ enable + + + + diff --git a/AbstractShopDataModels/Enums/OrderStatus.cs b/AbstractShopDataModels/Enums/OrderStatus.cs index 8a79b8a..9d31f15 100644 --- a/AbstractShopDataModels/Enums/OrderStatus.cs +++ b/AbstractShopDataModels/Enums/OrderStatus.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractJewelryStoreModels.Enums +namespace AbstractShopDataModels.Enums { - internal class OrderStatus + public enum OrderStatus { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 } -} +} \ No newline at end of file diff --git a/AbstractShopDataModels/IId.cs b/AbstractShopDataModels/IId.cs index 1c7b0a7..2fd8bde 100644 --- a/AbstractShopDataModels/IId.cs +++ b/AbstractShopDataModels/IId.cs @@ -1,7 +1,7 @@ namespace AbstractShopDataModels { - public class Class1 + public interface IId { - + int Id { get; } } -} \ No newline at end of file +} -- 2.25.1 From 2e3b7f66358d3c3767fe06c28d4ef9470bf7b054 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 17:43:06 +0400 Subject: [PATCH 03/21] 1 --- .../AbstractJewelryStoreModels.csproj | 0 .../Enums/OrderStatus.cs | 0 {AbstractShopDataModels => AbstractJewelryStoreModels}/IId.cs | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {AbstractShopDataModels => AbstractJewelryStoreModels}/AbstractJewelryStoreModels.csproj (100%) rename {AbstractShopDataModels => AbstractJewelryStoreModels}/Enums/OrderStatus.cs (100%) rename {AbstractShopDataModels => AbstractJewelryStoreModels}/IId.cs (100%) diff --git a/AbstractShopDataModels/AbstractJewelryStoreModels.csproj b/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj similarity index 100% rename from AbstractShopDataModels/AbstractJewelryStoreModels.csproj rename to AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj diff --git a/AbstractShopDataModels/Enums/OrderStatus.cs b/AbstractJewelryStoreModels/Enums/OrderStatus.cs similarity index 100% rename from AbstractShopDataModels/Enums/OrderStatus.cs rename to AbstractJewelryStoreModels/Enums/OrderStatus.cs diff --git a/AbstractShopDataModels/IId.cs b/AbstractJewelryStoreModels/IId.cs similarity index 100% rename from AbstractShopDataModels/IId.cs rename to AbstractJewelryStoreModels/IId.cs -- 2.25.1 From ec9e160673154b547820246440026865f246d846 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 17:58:46 +0400 Subject: [PATCH 04/21] =?UTF-8?q?=D0=91=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractJewelryStoreModels.csproj | 13 ------------- AbstractJewelryStoreModels/Enums/OrderStatus.cs | 11 ----------- AbstractJewelryStoreModels/IId.cs | 7 ------- JewelryStore/JewelryStore.sln | 10 +++++----- 4 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj delete mode 100644 AbstractJewelryStoreModels/Enums/OrderStatus.cs delete mode 100644 AbstractJewelryStoreModels/IId.cs diff --git a/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj b/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj deleted file mode 100644 index 962b8f6..0000000 --- a/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - diff --git a/AbstractJewelryStoreModels/Enums/OrderStatus.cs b/AbstractJewelryStoreModels/Enums/OrderStatus.cs deleted file mode 100644 index 9d31f15..0000000 --- a/AbstractJewelryStoreModels/Enums/OrderStatus.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace AbstractShopDataModels.Enums -{ - public enum OrderStatus - { - Неизвестен = -1, - Принят = 0, - Выполняется = 1, - Готов = 2, - Выдан = 3 - } -} \ No newline at end of file diff --git a/AbstractJewelryStoreModels/IId.cs b/AbstractJewelryStoreModels/IId.cs deleted file mode 100644 index 2fd8bde..0000000 --- a/AbstractJewelryStoreModels/IId.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace AbstractShopDataModels -{ - public interface IId - { - int Id { get; } - } -} diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index 76431b5..d5c6d00 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractJewelryStoreModels", "..\AbstractShopDataModels\AbstractJewelryStoreModels.csproj", "{BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractJewelryStoreModels", "..\..\..\..\..\..\Users\60652\Downloads\AbstractJewelryStoreModels\AbstractJewelryStoreModels.csproj", "{95570735-2DC2-4EF7-9CCB-D6A99E21E97F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +17,10 @@ Global {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.Build.0 = Release|Any CPU - {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BAB8D63E-1A60-4125-B7F7-D85D0FBA9ED0}.Release|Any CPU.Build.0 = Release|Any CPU + {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From e1c0c1942e30a41e1f2bf9c6cb0cfbc8d717652e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 18:01:09 +0400 Subject: [PATCH 05/21] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20?= =?UTF-8?q?=D1=81=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractJewelryStoreModels.csproj | 9 +++++++++ .../Enums/OrderStatus.cs | 11 ++++++++++ AbstractJewelryStoreModels/IId.cs | 7 +++++++ .../Models/IComponentModel.cs | 14 +++++++++++++ .../Models/IOrderModel.cs | 20 +++++++++++++++++++ .../Models/IProductModel.cs | 16 +++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj create mode 100644 AbstractJewelryStoreModels/Enums/OrderStatus.cs create mode 100644 AbstractJewelryStoreModels/IId.cs create mode 100644 AbstractJewelryStoreModels/Models/IComponentModel.cs create mode 100644 AbstractJewelryStoreModels/Models/IOrderModel.cs create mode 100644 AbstractJewelryStoreModels/Models/IProductModel.cs diff --git a/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj b/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/AbstractJewelryStoreModels/Enums/OrderStatus.cs b/AbstractJewelryStoreModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..158ca89 --- /dev/null +++ b/AbstractJewelryStoreModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace AbstractJewelryStoreModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/AbstractJewelryStoreModels/IId.cs b/AbstractJewelryStoreModels/IId.cs new file mode 100644 index 0000000..1fe2397 --- /dev/null +++ b/AbstractJewelryStoreModels/IId.cs @@ -0,0 +1,7 @@ +namespace AbstractJewelryStoreModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/AbstractJewelryStoreModels/Models/IComponentModel.cs b/AbstractJewelryStoreModels/Models/IComponentModel.cs new file mode 100644 index 0000000..c935902 --- /dev/null +++ b/AbstractJewelryStoreModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractJewelryStoreModels.Models +{ + internal class IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/AbstractJewelryStoreModels/Models/IOrderModel.cs b/AbstractJewelryStoreModels/Models/IOrderModel.cs new file mode 100644 index 0000000..4b792ce --- /dev/null +++ b/AbstractJewelryStoreModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using AbstractJewelryStoreModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractJewelryStoreModels.Models +{ + internal class IOrderModel : IId + { + int ProductId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/AbstractJewelryStoreModels/Models/IProductModel.cs b/AbstractJewelryStoreModels/Models/IProductModel.cs new file mode 100644 index 0000000..c131dfc --- /dev/null +++ b/AbstractJewelryStoreModels/Models/IProductModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractJewelryStoreModels.Models +{ + internal class IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + + } +} -- 2.25.1 From 226ebea6742c9db782ad794d18cd337ceb6a65df Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 18:55:08 +0400 Subject: [PATCH 06/21] Contracts --- .../AbstractJewelryStoreDataModels.csproj | 2 +- .../Enums/OrderStatus.cs | 17 ++++++++++ AbstractJewelryStoreDataModels/IId.cs | 8 +++++ .../Models/IComponentModel.cs | 5 +-- .../Models/IOrderModel.cs | 8 ++--- .../Models/IProductModel.cs | 5 ++- JewelryStore/JewelryStore.sln | 16 ++++++--- .../BindingModels/ComponentBindingModel.cs | 17 ++++++++++ .../BindingModels/JewelBindingModel.cs | 17 ++++++++++ .../BindingModels/OrderBindingModel.cs | 22 +++++++++++++ .../IComponentLogic.cs | 21 ++++++++++++ .../BusinessLogicsContracts/IJewelLogic.cs | 23 +++++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 +++++++++++ .../JewelryStoreContracts.csproj | 13 ++++++++ .../SearchModels/ComponentSearchModel.cs | 14 ++++++++ .../SearchModels/JewelSearchModel.cs | 14 ++++++++ .../SearchModels/OrderSearchModel.cs | 13 ++++++++ .../StoragesContracts/IComponentStorage.cs | 22 +++++++++++++ .../StoragesContracts/IJewelStorage.cs | 23 +++++++++++++ .../StoragesContracts/IOrderStorage.cs | 22 +++++++++++++ .../ViewModels/ComponentViewModel.cs | 19 +++++++++++ .../ViewModels/JewelViewModel.cs | 25 ++++++++++++++ .../ViewModels/OrderViewModel.cs | 33 +++++++++++++++++++ .../Enums/OrderStatus.cs | 10 ++++-- .../IId.cs | 4 +-- .../JewelryStoreDataModels.csproj | 9 +++++ .../Models/IComponentModel.cs | 16 +++++++++ JewelryStoreDataModels/Models/IJewelModel.cs | 16 +++++++++ JewelryStoreDataModels/Models/IOrderModel.cs | 21 ++++++++++++ 29 files changed, 436 insertions(+), 19 deletions(-) rename AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj => AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj (82%) create mode 100644 AbstractJewelryStoreDataModels/Enums/OrderStatus.cs create mode 100644 AbstractJewelryStoreDataModels/IId.cs rename {AbstractJewelryStoreModels => AbstractJewelryStoreDataModels}/Models/IComponentModel.cs (68%) rename {AbstractJewelryStoreModels => AbstractJewelryStoreDataModels}/Models/IOrderModel.cs (71%) rename {AbstractJewelryStoreModels => AbstractJewelryStoreDataModels}/Models/IProductModel.cs (75%) create mode 100644 JewelryStoreContracts/BindingModels/ComponentBindingModel.cs create mode 100644 JewelryStoreContracts/BindingModels/JewelBindingModel.cs create mode 100644 JewelryStoreContracts/BindingModels/OrderBindingModel.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 JewelryStoreContracts/JewelryStoreContracts.csproj create mode 100644 JewelryStoreContracts/SearchModels/ComponentSearchModel.cs create mode 100644 JewelryStoreContracts/SearchModels/JewelSearchModel.cs create mode 100644 JewelryStoreContracts/SearchModels/OrderSearchModel.cs create mode 100644 JewelryStoreContracts/StoragesContracts/IComponentStorage.cs create mode 100644 JewelryStoreContracts/StoragesContracts/IJewelStorage.cs create mode 100644 JewelryStoreContracts/StoragesContracts/IOrderStorage.cs create mode 100644 JewelryStoreContracts/ViewModels/ComponentViewModel.cs create mode 100644 JewelryStoreContracts/ViewModels/JewelViewModel.cs create mode 100644 JewelryStoreContracts/ViewModels/OrderViewModel.cs rename {AbstractJewelryStoreModels => JewelryStoreDataModels}/Enums/OrderStatus.cs (53%) rename {AbstractJewelryStoreModels => JewelryStoreDataModels}/IId.cs (60%) create mode 100644 JewelryStoreDataModels/JewelryStoreDataModels.csproj create mode 100644 JewelryStoreDataModels/Models/IComponentModel.cs create mode 100644 JewelryStoreDataModels/Models/IJewelModel.cs create mode 100644 JewelryStoreDataModels/Models/IOrderModel.cs diff --git a/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj b/AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj similarity index 82% rename from AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj rename to AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj index 27ac386..132c02c 100644 --- a/AbstractJewelryStoreModels/AbstractJewelryStoreModels.csproj +++ b/AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs b/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..49a4111 --- /dev/null +++ b/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractJewelryStoreDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/AbstractJewelryStoreDataModels/IId.cs b/AbstractJewelryStoreDataModels/IId.cs new file mode 100644 index 0000000..e17c9ae --- /dev/null +++ b/AbstractJewelryStoreDataModels/IId.cs @@ -0,0 +1,8 @@ +namespace AbstractJewelryStoreDataModels +{ + public interface IId + { + int Id { get; } + } + +} \ No newline at end of file diff --git a/AbstractJewelryStoreModels/Models/IComponentModel.cs b/AbstractJewelryStoreDataModels/Models/IComponentModel.cs similarity index 68% rename from AbstractJewelryStoreModels/Models/IComponentModel.cs rename to AbstractJewelryStoreDataModels/Models/IComponentModel.cs index c935902..626d531 100644 --- a/AbstractJewelryStoreModels/Models/IComponentModel.cs +++ b/AbstractJewelryStoreDataModels/Models/IComponentModel.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractJewelryStoreModels.Models +namespace AbstractJewelryStoreDataModels.Models { - internal class IComponentModel : IId + public interface IComponentModel : IId { string ComponentName { get; } double Cost { get; } } + } diff --git a/AbstractJewelryStoreModels/Models/IOrderModel.cs b/AbstractJewelryStoreDataModels/Models/IOrderModel.cs similarity index 71% rename from AbstractJewelryStoreModels/Models/IOrderModel.cs rename to AbstractJewelryStoreDataModels/Models/IOrderModel.cs index 4b792ce..7be5bea 100644 --- a/AbstractJewelryStoreModels/Models/IOrderModel.cs +++ b/AbstractJewelryStoreDataModels/Models/IOrderModel.cs @@ -1,13 +1,13 @@ -using AbstractJewelryStoreModels.Enums; +using AbstractJewelryStoreDataModels.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractJewelryStoreModels.Models +namespace AbstractJewelryStoreDataModels.Models { - internal class IOrderModel : IId + public interface IOrderModel : IId { int ProductId { get; } int Count { get; } @@ -15,6 +15,6 @@ namespace AbstractJewelryStoreModels.Models OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } - } + } diff --git a/AbstractJewelryStoreModels/Models/IProductModel.cs b/AbstractJewelryStoreDataModels/Models/IProductModel.cs similarity index 75% rename from AbstractJewelryStoreModels/Models/IProductModel.cs rename to AbstractJewelryStoreDataModels/Models/IProductModel.cs index c131dfc..31fb59f 100644 --- a/AbstractJewelryStoreModels/Models/IProductModel.cs +++ b/AbstractJewelryStoreDataModels/Models/IProductModel.cs @@ -4,13 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractJewelryStoreModels.Models +namespace AbstractJewelryStoreDataModels.Models { - internal class IProductModel : IId + public interface IProductModel : IId { string ProductName { get; } double Price { get; } Dictionary ProductComponents { get; } - } } diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index d5c6d00..537b67b 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractJewelryStoreModels", "..\..\..\..\..\..\Users\60652\Downloads\AbstractJewelryStoreModels\AbstractJewelryStoreModels.csproj", "{95570735-2DC2-4EF7-9CCB-D6A99E21E97F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +19,14 @@ Global {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.Build.0 = Release|Any CPU - {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {95570735-2DC2-4EF7-9CCB-D6A99E21E97F}.Release|Any CPU.Build.0 = Release|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Release|Any CPU.Build.0 = Release|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs b/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..f2f424e --- /dev/null +++ b/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } + +} diff --git a/JewelryStoreContracts/BindingModels/JewelBindingModel.cs b/JewelryStoreContracts/BindingModels/JewelBindingModel.cs new file mode 100644 index 0000000..cb6965c --- /dev/null +++ b/JewelryStoreContracts/BindingModels/JewelBindingModel.cs @@ -0,0 +1,17 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class JewelBindingModel : IJewelModel + { + public int Id { get; set; } + public string JewelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary JewelComponents { get; set;} = new(); + } +} diff --git a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..be96d50 --- /dev/null +++ b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int JewelId { 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/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..17cc2cd --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs new file mode 100644 index 0000000..8a67266 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs @@ -0,0 +1,23 @@ +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreContracts.BindingModels; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IJewelLogic + { + List? ReadList(JewelSearchModel? model); + JewelViewModel? ReadElement(JewelSearchModel model); + bool Create(JewelBindingModel model); + bool Update(JewelBindingModel model); + + bool Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..a403f30 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStoreContracts/JewelryStoreContracts.csproj new file mode 100644 index 0000000..3c67a42 --- /dev/null +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs b/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..7c626d0 --- /dev/null +++ b/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/JewelryStoreContracts/SearchModels/JewelSearchModel.cs b/JewelryStoreContracts/SearchModels/JewelSearchModel.cs new file mode 100644 index 0000000..568af39 --- /dev/null +++ b/JewelryStoreContracts/SearchModels/JewelSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class JewelSearchModel + { + public int? Id { get; set; } + public string? JewelName { get; set; } + } +} diff --git a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..14133ed --- /dev/null +++ b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs b/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..2fd9c29 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs b/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs new file mode 100644 index 0000000..16fef58 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IJewelStorage + { + List GetFullList(); + List GetFilteredList(JewelSearchModel model); + JewelViewModel? GetElement(JewelSearchModel model); + JewelViewModel? Insert(JewelBindingModel model); + JewelViewModel? Update(JewelBindingModel model); + JewelViewModel? Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs b/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..3fb94e2 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/ViewModels/ComponentViewModel.cs b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..dcd3252 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/JewelryStoreContracts/ViewModels/JewelViewModel.cs new file mode 100644 index 0000000..f09420f --- /dev/null +++ b/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -0,0 +1,25 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class JewelViewModel : IJewelModel + { + public int Id { get; set; } + [DisplayName("Название драгоценности")] + public string JewelName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary JewelComponents + { + get; + set; + } = new(); + } + +} diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..ed81bd4 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,33 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int JewelId { get; set; } + + [DisplayName("Драгоценность")] + public string JewelName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } + +} diff --git a/AbstractJewelryStoreModels/Enums/OrderStatus.cs b/JewelryStoreDataModels/Enums/OrderStatus.cs similarity index 53% rename from AbstractJewelryStoreModels/Enums/OrderStatus.cs rename to JewelryStoreDataModels/Enums/OrderStatus.cs index 158ca89..7dd5f25 100644 --- a/AbstractJewelryStoreModels/Enums/OrderStatus.cs +++ b/JewelryStoreDataModels/Enums/OrderStatus.cs @@ -1,4 +1,10 @@ -namespace AbstractJewelryStoreModels.Enums +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Enums { public enum OrderStatus { @@ -8,4 +14,4 @@ Готов = 2, Выдан = 3 } -} \ No newline at end of file +} diff --git a/AbstractJewelryStoreModels/IId.cs b/JewelryStoreDataModels/IId.cs similarity index 60% rename from AbstractJewelryStoreModels/IId.cs rename to JewelryStoreDataModels/IId.cs index 1fe2397..0c72069 100644 --- a/AbstractJewelryStoreModels/IId.cs +++ b/JewelryStoreDataModels/IId.cs @@ -1,7 +1,7 @@ -namespace AbstractJewelryStoreModels +namespace JewelryStoreDataModels { public interface IId { int Id { get; } } -} +} \ No newline at end of file diff --git a/JewelryStoreDataModels/JewelryStoreDataModels.csproj b/JewelryStoreDataModels/JewelryStoreDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/JewelryStoreDataModels/JewelryStoreDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/JewelryStoreDataModels/Models/IComponentModel.cs b/JewelryStoreDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..99b9ee7 --- /dev/null +++ b/JewelryStoreDataModels/Models/IComponentModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } + +} diff --git a/JewelryStoreDataModels/Models/IJewelModel.cs b/JewelryStoreDataModels/Models/IJewelModel.cs new file mode 100644 index 0000000..f4922b6 --- /dev/null +++ b/JewelryStoreDataModels/Models/IJewelModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IJewelModel : IId + { + string JewelName { get; } + double Price { get; } + Dictionary JewelComponents { get; } + } +} diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..b7b8c70 --- /dev/null +++ b/JewelryStoreDataModels/Models/IOrderModel.cs @@ -0,0 +1,21 @@ +using JewelryStoreDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IOrderModel : IId + { + int JewelId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } + +} -- 2.25.1 From 8906aac95b54eddbdf46cb99d89b3f578bf7d6bb Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 18:55:49 +0400 Subject: [PATCH 07/21] deleted --- .../AbstractJewelryStoreDataModels.csproj | 9 --------- .../Enums/OrderStatus.cs | 17 ---------------- AbstractJewelryStoreDataModels/IId.cs | 8 -------- .../Models/IComponentModel.cs | 15 -------------- .../Models/IOrderModel.cs | 20 ------------------- .../Models/IProductModel.cs | 15 -------------- 6 files changed, 84 deletions(-) delete mode 100644 AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj delete mode 100644 AbstractJewelryStoreDataModels/Enums/OrderStatus.cs delete mode 100644 AbstractJewelryStoreDataModels/IId.cs delete mode 100644 AbstractJewelryStoreDataModels/Models/IComponentModel.cs delete mode 100644 AbstractJewelryStoreDataModels/Models/IOrderModel.cs delete mode 100644 AbstractJewelryStoreDataModels/Models/IProductModel.cs diff --git a/AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj b/AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj deleted file mode 100644 index 132c02c..0000000 --- a/AbstractJewelryStoreDataModels/AbstractJewelryStoreDataModels.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs b/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs deleted file mode 100644 index 49a4111..0000000 --- a/AbstractJewelryStoreDataModels/Enums/OrderStatus.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractJewelryStoreDataModels.Enums -{ - public enum OrderStatus - { - Неизвестен = -1, - Принят = 0, - Выполняется = 1, - Готов = 2, - Выдан = 3 - } -} diff --git a/AbstractJewelryStoreDataModels/IId.cs b/AbstractJewelryStoreDataModels/IId.cs deleted file mode 100644 index e17c9ae..0000000 --- a/AbstractJewelryStoreDataModels/IId.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace AbstractJewelryStoreDataModels -{ - public interface IId - { - int Id { get; } - } - -} \ No newline at end of file diff --git a/AbstractJewelryStoreDataModels/Models/IComponentModel.cs b/AbstractJewelryStoreDataModels/Models/IComponentModel.cs deleted file mode 100644 index 626d531..0000000 --- a/AbstractJewelryStoreDataModels/Models/IComponentModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractJewelryStoreDataModels.Models -{ - public interface IComponentModel : IId - { - string ComponentName { get; } - double Cost { get; } - } - -} diff --git a/AbstractJewelryStoreDataModels/Models/IOrderModel.cs b/AbstractJewelryStoreDataModels/Models/IOrderModel.cs deleted file mode 100644 index 7be5bea..0000000 --- a/AbstractJewelryStoreDataModels/Models/IOrderModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AbstractJewelryStoreDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractJewelryStoreDataModels.Models -{ - public interface IOrderModel : IId - { - int ProductId { get; } - int Count { get; } - double Sum { get; } - OrderStatus Status { get; } - DateTime DateCreate { get; } - DateTime? DateImplement { get; } - } - -} diff --git a/AbstractJewelryStoreDataModels/Models/IProductModel.cs b/AbstractJewelryStoreDataModels/Models/IProductModel.cs deleted file mode 100644 index 31fb59f..0000000 --- a/AbstractJewelryStoreDataModels/Models/IProductModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbstractJewelryStoreDataModels.Models -{ - public interface IProductModel : IId - { - string ProductName { get; } - double Price { get; } - Dictionary ProductComponents { get; } - } -} -- 2.25.1 From fb52c6768261d1cb27f4124e3420e7e41d9fbde8 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 19:24:53 +0400 Subject: [PATCH 08/21] Business Logic --- JewelryStore/JewelryStore.sln | 12 ++ .../BusinessLogics/ComponentLogic.cs | 117 ++++++++++++++++++ .../BusinessLogics/JewelLogic.cs | 40 ++++++ .../BusinessLogics/OrderLogic.cs | 45 +++++++ .../JewelryStoreBusinessLogic.csproj | 17 +++ JewelryStoreListImplement/Class1.cs | 7 ++ .../JewelryStoreListImplement.csproj | 9 ++ 7 files changed, 247 insertions(+) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj create mode 100644 JewelryStoreListImplement/Class1.cs create mode 100644 JewelryStoreListImplement/JewelryStoreListImplement.csproj diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index 537b67b..08fec75 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", ".. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.Build.0 = Debug|Any CPU {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.ActiveCfg = Release|Any CPU {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.Build.0 = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.Build.0 = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..ea507ce --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,117 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() :_componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } + +} diff --git a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs new file mode 100644 index 0000000..66fe1fa --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -0,0 +1,40 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic + { + public bool Create(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? ReadElement(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(JewelSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(JewelBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..f3a90c2 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,45 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class OrderLogic : IOrderLogic //TODO реализовать интерфейс + { +// Класс с логикой для заказов будет отвечать за получение списка заказов, +//создания заказа и смены его статусов.Следует учитывать, что у заказа можно +//менять статус на новый, если его текущий статус предшествует новому +//(например, в статус «Готов» можно переводить, если заказ находится в статусе +//«Выполняется»). + public bool CreateOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool FinishOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(OrderSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj new file mode 100644 index 0000000..7e1df35 --- /dev/null +++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/JewelryStoreListImplement/Class1.cs b/JewelryStoreListImplement/Class1.cs new file mode 100644 index 0000000..cdbf310 --- /dev/null +++ b/JewelryStoreListImplement/Class1.cs @@ -0,0 +1,7 @@ +namespace JewelryStoreListImplement +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + -- 2.25.1 From 92bee445c3a0592a9f443d43627375ad7e35e42c Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 19:55:32 +0400 Subject: [PATCH 09/21] ListImplements --- JewelryStoreListImplement/Class1.cs | 7 --- .../DataListSingleton.cs | 31 +++++++++++ .../Implements/ComponentStorage .cs | 12 +++++ .../Implements/JewelStorage.cs | 12 +++++ .../Implements/OrderStorage.cs | 12 +++++ .../JewelryStoreListImplement.csproj | 5 ++ JewelryStoreListImplement/Models/Component.cs | 12 +++++ JewelryStoreListImplement/Models/Jewel.cs | 53 +++++++++++++++++++ JewelryStoreListImplement/Models/Order.cs | 12 +++++ 9 files changed, 149 insertions(+), 7 deletions(-) delete mode 100644 JewelryStoreListImplement/Class1.cs create mode 100644 JewelryStoreListImplement/DataListSingleton.cs create mode 100644 JewelryStoreListImplement/Implements/ComponentStorage .cs create mode 100644 JewelryStoreListImplement/Implements/JewelStorage.cs create mode 100644 JewelryStoreListImplement/Implements/OrderStorage.cs create mode 100644 JewelryStoreListImplement/Models/Component.cs create mode 100644 JewelryStoreListImplement/Models/Jewel.cs create mode 100644 JewelryStoreListImplement/Models/Order.cs diff --git a/JewelryStoreListImplement/Class1.cs b/JewelryStoreListImplement/Class1.cs deleted file mode 100644 index cdbf310..0000000 --- a/JewelryStoreListImplement/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace JewelryStoreListImplement -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b280c4 --- /dev/null +++ b/JewelryStoreListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Jewels { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Jewels = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/JewelryStoreListImplement/Implements/ComponentStorage .cs b/JewelryStoreListImplement/Implements/ComponentStorage .cs new file mode 100644 index 0000000..aaffee8 --- /dev/null +++ b/JewelryStoreListImplement/Implements/ComponentStorage .cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + internal class ComponentStorage + { + } +} diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..57e8b90 --- /dev/null +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + internal class JewelStorage + { + } +} diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d13c73f --- /dev/null +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + internal class OrderStorage + { + } +} diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj index 132c02c..783cc4d 100644 --- a/JewelryStoreListImplement/JewelryStoreListImplement.csproj +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/JewelryStoreListImplement/Models/Component.cs b/JewelryStoreListImplement/Models/Component.cs new file mode 100644 index 0000000..6ad51d8 --- /dev/null +++ b/JewelryStoreListImplement/Models/Component.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + internal class Component + { + } +} diff --git a/JewelryStoreListImplement/Models/Jewel.cs b/JewelryStoreListImplement/Models/Jewel.cs new file mode 100644 index 0000000..11d77df --- /dev/null +++ b/JewelryStoreListImplement/Models/Jewel.cs @@ -0,0 +1,53 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Jewel: IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary JewelComponents + { + get; + private set; + } = new Dictionary(); + public static Jewel? Create(JewelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + JewelComponents = model.JewelComponents + }; + } + public void Update(JewelBindingModel? model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + JewelComponents = model.JewelComponents; + } + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + + } +} diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs new file mode 100644 index 0000000..d982fe3 --- /dev/null +++ b/JewelryStoreListImplement/Models/Order.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + internal class Order + { + } +} -- 2.25.1 From d3d8f5d7e7dbd242c8b9b832e0f3e6e666da2864 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 19:55:48 +0400 Subject: [PATCH 10/21] ListImplements --- .../Implements/ComponentStorage .cs | 100 +++++++++++++++++- .../Implements/JewelStorage.cs | 37 ++++++- .../Implements/OrderStorage.cs | 37 ++++++- JewelryStoreListImplement/Models/Component.cs | 39 ++++++- JewelryStoreListImplement/Models/Jewel.cs | 2 + JewelryStoreListImplement/Models/Order.cs | 19 +++- 6 files changed, 224 insertions(+), 10 deletions(-) diff --git a/JewelryStoreListImplement/Implements/ComponentStorage .cs b/JewelryStoreListImplement/Implements/ComponentStorage .cs index aaffee8..b6270b0 100644 --- a/JewelryStoreListImplement/Implements/ComponentStorage .cs +++ b/JewelryStoreListImplement/Implements/ComponentStorage .cs @@ -1,4 +1,9 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +11,98 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class ComponentStorage + public class ComponentStorage : IComponentStorage { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } } } diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs index 57e8b90..8b2fd87 100644 --- a/JewelryStoreListImplement/Implements/JewelStorage.cs +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -1,4 +1,8 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,36 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class JewelStorage + internal class JewelStorage : IJewelStorage // TODO реализовать интерфейс { + public JewelViewModel? Delete(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? Update(JewelBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs index d13c73f..abcb051 100644 --- a/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -1,4 +1,8 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,36 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class OrderStorage + internal class OrderStorage : IOrderStorage // TODO реализовать интерфейс { + public OrderViewModel? Delete(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/JewelryStoreListImplement/Models/Component.cs b/JewelryStoreListImplement/Models/Component.cs index 6ad51d8..be9adee 100644 --- a/JewelryStoreListImplement/Models/Component.cs +++ b/JewelryStoreListImplement/Models/Component.cs @@ -1,4 +1,7 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +9,39 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Models { - internal class Component + public class Component : IComponentModel { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; } + } diff --git a/JewelryStoreListImplement/Models/Jewel.cs b/JewelryStoreListImplement/Models/Jewel.cs index 11d77df..2ba83ef 100644 --- a/JewelryStoreListImplement/Models/Jewel.cs +++ b/JewelryStoreListImplement/Models/Jewel.cs @@ -1,9 +1,11 @@ using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; namespace JewelryStoreListImplement.Models { diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs index d982fe3..dc1ef36 100644 --- a/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStoreListImplement/Models/Order.cs @@ -1,4 +1,6 @@ -using System; +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,20 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Models { - internal class Order + public class Order : IOrderModel // TODO Класс для модели сущности «Заказ» разработать самостоятельно { + public int JewelId => throw new NotImplementedException(); + + public int Count => throw new NotImplementedException(); + + public double Sum => throw new NotImplementedException(); + + public OrderStatus Status => throw new NotImplementedException(); + + public DateTime DateCreate => throw new NotImplementedException(); + + public DateTime? DateImplement => throw new NotImplementedException(); + + public int Id => throw new NotImplementedException(); } } -- 2.25.1 From cfb7d9086c72535e5cb120027e7cbf0257163ec7 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 20:14:00 +0400 Subject: [PATCH 11/21] FormComponent --- JewelryStore/Form1.Designer.cs | 39 -------- JewelryStore/Form1.cs | 10 --- JewelryStore/Form1.resx | 120 ------------------------- JewelryStore/FormComponent.Designer.cs | 119 ++++++++++++++++++++++++ JewelryStore/FormComponent.cs | 92 +++++++++++++++++++ JewelryStore/FormComponent.resx | 60 +++++++++++++ JewelryStore/JewelryStore.csproj | 8 ++ JewelryStore/Program.cs | 1 - 8 files changed, 279 insertions(+), 170 deletions(-) delete mode 100644 JewelryStore/Form1.Designer.cs delete mode 100644 JewelryStore/Form1.cs delete mode 100644 JewelryStore/Form1.resx create mode 100644 JewelryStore/FormComponent.Designer.cs create mode 100644 JewelryStore/FormComponent.cs create mode 100644 JewelryStore/FormComponent.resx diff --git a/JewelryStore/Form1.Designer.cs b/JewelryStore/Form1.Designer.cs deleted file mode 100644 index d1c38a9..0000000 --- a/JewelryStore/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace JewelryStore -{ - 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/JewelryStore/Form1.cs b/JewelryStore/Form1.cs deleted file mode 100644 index f3212bd..0000000 --- a/JewelryStore/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace JewelryStore -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/JewelryStore/Form1.resx b/JewelryStore/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/JewelryStore/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/JewelryStore/FormComponent.Designer.cs b/JewelryStore/FormComponent.Designer.cs new file mode 100644 index 0000000..759487b --- /dev/null +++ b/JewelryStore/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(554, 353); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(676, 353); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(90, 113); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(90, 160); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(57, 25); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(212, 113); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(150, 31); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(212, 160); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(150, 31); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponent.cs b/JewelryStore/FormComponent.cs new file mode 100644 index 0000000..7495460 --- /dev/null +++ b/JewelryStore/FormComponent.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; + + +namespace JewelryStore +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + + } + +} \ No newline at end of file diff --git a/JewelryStore/FormComponent.resx b/JewelryStore/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/JewelryStore/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index b57c89e..74fe05f 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -8,4 +8,12 @@ enable + + + + + + + + \ No newline at end of file diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index c4650cd..666baa8 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -11,7 +11,6 @@ namespace JewelryStore // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); } } } \ No newline at end of file -- 2.25.1 From 4bc34bb8dff6c4f8190e3398b5b60b0cf6eede97 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 20:58:56 +0400 Subject: [PATCH 12/21] form components --- JewelryStore/FormComponents.Designer.cs | 116 +++++++++++++++++++++++ JewelryStore/FormComponents.cs | 121 ++++++++++++++++++++++++ JewelryStore/FormComponents.resx | 120 +++++++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 JewelryStore/FormComponents.Designer.cs create mode 100644 JewelryStore/FormComponents.cs create mode 100644 JewelryStore/FormComponents.resx diff --git a/JewelryStore/FormComponents.Designer.cs b/JewelryStore/FormComponents.Designer.cs new file mode 100644 index 0000000..5a76842 --- /dev/null +++ b/JewelryStore/FormComponents.Designer.cs @@ -0,0 +1,116 @@ +namespace FurnitureAssemblyView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(459, 488); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(480, 25); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(481, 67); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(481, 107); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(481, 147); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 488); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs new file mode 100644 index 0000000..0df5b91 --- /dev/null +++ b/JewelryStore/FormComponents.cs @@ -0,0 +1,121 @@ + +using JewelryStore; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.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 FurnitureAssemblyView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + 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 ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponents.resx b/JewelryStore/FormComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From 4af686a56b54014e6ae49e4502f1b7e3a8a7cb0c Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 21:06:29 +0400 Subject: [PATCH 13/21] FormJewelComponent --- JewelryStore/FormComponents.Designer.cs | 2 +- JewelryStore/FormComponents.cs | 2 +- JewelryStore/FormJewelComponent.Designer.cs | 119 ++++++++++++++++++++ JewelryStore/FormJewelComponent.cs | 92 +++++++++++++++ JewelryStore/FormJewelComponent.resx | 60 ++++++++++ 5 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 JewelryStore/FormJewelComponent.Designer.cs create mode 100644 JewelryStore/FormJewelComponent.cs create mode 100644 JewelryStore/FormJewelComponent.resx diff --git a/JewelryStore/FormComponents.Designer.cs b/JewelryStore/FormComponents.Designer.cs index 5a76842..7156e1f 100644 --- a/JewelryStore/FormComponents.Designer.cs +++ b/JewelryStore/FormComponents.Designer.cs @@ -1,4 +1,4 @@ -namespace FurnitureAssemblyView +namespace JewelryStore { partial class FormComponents { diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs index 0df5b91..76cf58a 100644 --- a/JewelryStore/FormComponents.cs +++ b/JewelryStore/FormComponents.cs @@ -13,7 +13,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace FurnitureAssemblyView +namespace JewelryStore { public partial class FormComponents : Form { diff --git a/JewelryStore/FormJewelComponent.Designer.cs b/JewelryStore/FormJewelComponent.Designer.cs new file mode 100644 index 0000000..7283393 --- /dev/null +++ b/JewelryStore/FormJewelComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + partial class FormJewelComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(148, 10); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(182, 33); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 53); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(150, 31); + this.textBoxCount.TabIndex = 1; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(16, 18); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(103, 25); + this.labelComponent.TabIndex = 2; + this.labelComponent.Text = "Компонент"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(16, 57); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(112, 25); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество "; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(75, 99); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(206, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormJewelComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(426, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Name = "FormJewelComponent"; + this.Text = "Компонент драгоценности"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewelComponent.cs b/JewelryStore/FormJewelComponent.cs new file mode 100644 index 0000000..1ec6c3b --- /dev/null +++ b/JewelryStore/FormJewelComponent.cs @@ -0,0 +1,92 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormJewelComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormJewelComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/JewelryStore/FormJewelComponent.resx b/JewelryStore/FormJewelComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/JewelryStore/FormJewelComponent.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 -- 2.25.1 From 2a1538068a8c8be57449f92f677d4e05147248c7 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 21:19:21 +0400 Subject: [PATCH 14/21] form jewel --- JewelryStore/FormJewel.Designer.cs | 221 +++++++++++++++++++++++++++ JewelryStore/FormJewel.cs | 229 ++++++++++++++++++++++++++++ JewelryStore/FormJewel.resx | 120 +++++++++++++++ JewelryStore/FormJewels.Designer.cs | 39 +++++ JewelryStore/FormJewels.cs | 20 +++ JewelryStore/FormJewels.resx | 120 +++++++++++++++ 6 files changed, 749 insertions(+) create mode 100644 JewelryStore/FormJewel.Designer.cs create mode 100644 JewelryStore/FormJewel.cs create mode 100644 JewelryStore/FormJewel.resx create mode 100644 JewelryStore/FormJewels.Designer.cs create mode 100644 JewelryStore/FormJewels.cs create mode 100644 JewelryStore/FormJewels.resx diff --git a/JewelryStore/FormJewel.Designer.cs b/JewelryStore/FormJewel.Designer.cs new file mode 100644 index 0000000..ffaa849 --- /dev/null +++ b/JewelryStore/FormJewel.Designer.cs @@ -0,0 +1,221 @@ +namespace JewelryStore +{ + partial class FormJewel + { + /// + /// 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.groupBoxComponent = new System.Windows.Forms.GroupBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.groupBoxComponent.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(19, 19); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(19, 59); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(108, 25); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(119, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(340, 31); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(119, 53); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(150, 31); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponent + // + this.groupBoxComponent.Controls.Add(this.buttonUpdate); + this.groupBoxComponent.Controls.Add(this.buttonDelete); + this.groupBoxComponent.Controls.Add(this.buttonChange); + this.groupBoxComponent.Controls.Add(this.buttonAdd); + this.groupBoxComponent.Controls.Add(this.dataGridView); + this.groupBoxComponent.Location = new System.Drawing.Point(14, 108); + this.groupBoxComponent.Name = "groupBoxComponent"; + this.groupBoxComponent.Size = new System.Drawing.Size(763, 330); + this.groupBoxComponent.TabIndex = 4; + this.groupBoxComponent.TabStop = false; + this.groupBoxComponent.Text = "Компоненты"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(431, 452); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(562, 454); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(25, 30); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(554, 281); + this.dataGridView.TabIndex = 0; + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.MinimumWidth = 8; + this.ColumnComponent.Name = "ColumnComponent"; + this.ColumnComponent.Width = 150; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 8; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 150; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(602, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(602, 81); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(604, 124); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(604, 164); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // FormJewel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 495); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxComponent); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormJewel"; + this.Text = "Драгоценность"; + this.Load += new System.EventHandler(this.FormJewel_Load); + this.groupBoxComponent.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponent; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewel.cs b/JewelryStore/FormJewel.cs new file mode 100644 index 0000000..a54a46c --- /dev/null +++ b/JewelryStore/FormJewel.cs @@ -0,0 +1,229 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreDataModels.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 JewelryStore +{ + public partial class FormJewel : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + private int? _id; + private Dictionary _JewelComponents; + public int Id { set { _id = value; } } + public FormJewel(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _JewelComponents = new Dictionary(); + } + + private void FormJewel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка драгоценности"); + try + { + var view = _logic.ReadElement(new JewelSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.JewelName; + textBoxPrice.Text = view.Price.ToString(); + _JewelComponents = view.JewelComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки драгоценности"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент драгоценности"); + try + { + if (_JewelComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _JewelComponents) + { + dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент драгоценности"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_JewelComponents.ContainsKey(form.Id)) + { + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _JewelComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(JewelComponentForm)); + if (service is JewelComponentForm form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _JewelComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _JewelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_JewelComponents == null || _JewelComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение драгоценности"); + try + { + var model = new JewelBindingModel + { + Id = _id ?? 0, + JewelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + JewelComponents = _JewelComponents + }; + 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 _JewelComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/JewelryStore/FormJewel.resx b/JewelryStore/FormJewel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormJewel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormJewels.Designer.cs b/JewelryStore/FormJewels.Designer.cs new file mode 100644 index 0000000..1f178f8 --- /dev/null +++ b/JewelryStore/FormJewels.Designer.cs @@ -0,0 +1,39 @@ +namespace JewelryStore +{ + partial class FormJewels + { + /// + /// 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 = "FormJewels"; + } + + #endregion + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs new file mode 100644 index 0000000..411c317 --- /dev/null +++ b/JewelryStore/FormJewels.cs @@ -0,0 +1,20 @@ +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 JewelryStore +{ + public partial class FormJewels : Form + { + public FormJewels() + { + InitializeComponent(); + } + } +} diff --git a/JewelryStore/FormJewels.resx b/JewelryStore/FormJewels.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormJewels.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From 8fa564fd6d2bc331ecb6f989822875a15d1f6f0e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 21:33:15 +0400 Subject: [PATCH 15/21] Form create Order --- JewelryStore/FormCreateOrder.Designer.cs | 144 ++++++++++++++++++ JewelryStore/FormCreateOrder.cs | 127 +++++++++++++++ JewelryStore/FormCreateOrder.resx | 120 +++++++++++++++ JewelryStore/FormJewel.cs | 4 +- JewelryStore/FormJewels.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 1 + 6 files changed, 395 insertions(+), 3 deletions(-) create mode 100644 JewelryStore/FormCreateOrder.Designer.cs create mode 100644 JewelryStore/FormCreateOrder.cs create mode 100644 JewelryStore/FormCreateOrder.resx diff --git a/JewelryStore/FormCreateOrder.Designer.cs b/JewelryStore/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..57c334d --- /dev/null +++ b/JewelryStore/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace JewelryStore +{ + 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.comboBoxJewel = new System.Windows.Forms.ComboBox(); + this.labelJewel = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + 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(); + // + // comboBoxJewel + // + this.comboBoxJewel.FormattingEnabled = true; + this.comboBoxJewel.Location = new System.Drawing.Point(115, 14); + this.comboBoxJewel.Name = "comboBoxJewel"; + this.comboBoxJewel.Size = new System.Drawing.Size(250, 33); + this.comboBoxJewel.TabIndex = 0; + // + // labelJewel + // + this.labelJewel.AutoSize = true; + this.labelJewel.Location = new System.Drawing.Point(12, 22); + this.labelJewel.Name = "labelJewel"; + this.labelJewel.Size = new System.Drawing.Size(80, 25); + this.labelJewel.TabIndex = 1; + this.labelJewel.Text = "Изделие"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 67); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(107, 25); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 118); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(67, 25); + this.labelSum.TabIndex = 3; + this.labelSum.Text = "Сумма"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 64); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(250, 31); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(115, 115); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(250, 31); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(31, 161); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(253, 161); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + 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(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(401, 207); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelJewel); + this.Controls.Add(this.comboBoxJewel); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.OrderForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxJewel; + private Label labelJewel; + private Label labelCount; + private Label labelSum; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormCreateOrder.cs b/JewelryStore/FormCreateOrder.cs new file mode 100644 index 0000000..b6c1d21 --- /dev/null +++ b/JewelryStore/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.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 JewelryStore +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IJewelLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void OrderForm_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка драгоценностей для заказа"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxJewel.DisplayMember = "Драгоценность"; + comboBoxJewel.ValueMember = "Id"; + comboBoxJewel.DataSource = list.Select(c => c.JewelName).ToList(); + comboBoxJewel.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка драгоценностей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxJewel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1; + var Jewel = _logicP.ReadElement(new JewelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Jewel?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxJewel.SelectedValue == null) + { + MessageBox.Show("Выберите драгоценность", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + JewelId = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1, + JewelName = comboBoxJewel.SelectedValue.ToString(), + 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/JewelryStore/FormCreateOrder.resx b/JewelryStore/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormJewel.cs b/JewelryStore/FormJewel.cs index a54a46c..c820b68 100644 --- a/JewelryStore/FormJewel.cs +++ b/JewelryStore/FormJewel.cs @@ -112,8 +112,8 @@ namespace JewelryStore { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(JewelComponentForm)); - if (service is JewelComponentForm form) + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index 411c317..dc4f263 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -10,7 +10,7 @@ using System.Windows.Forms; namespace JewelryStore { - public partial class FormJewels : Form + public partial class FormJewels : Form //TODO { public FormJewels() { diff --git a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs index be96d50..37e87a9 100644 --- a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs +++ b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace JewelryStoreContracts.BindingModels { public int Id { get; set; } public int JewelId { get; set; } + public string JewelName { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; -- 2.25.1 From 385a43b84995623303e27118606fdd494d5a3fbd Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 5 Feb 2023 21:54:36 +0400 Subject: [PATCH 16/21] without tasks --- JewelryStore/FormMain.Designer.cs | 176 ++++++++++++++++ JewelryStore/FormMain.cs | 193 ++++++++++++++++++ JewelryStore/FormMain.resx | 120 +++++++++++ JewelryStore/JewelryStore.csproj | 3 + JewelryStore/Program.cs | 48 ++++- .../BusinessLogics/JewelLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 2 +- .../Implements/JewelStorage.cs | 2 +- .../Implements/OrderStorage.cs | 2 +- 9 files changed, 540 insertions(+), 8 deletions(-) create mode 100644 JewelryStore/FormMain.Designer.cs create mode 100644 JewelryStore/FormMain.cs create mode 100644 JewelryStore/FormMain.resx diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs new file mode 100644 index 0000000..4729020 --- /dev/null +++ b/JewelryStore/FormMain.Designer.cs @@ -0,0 +1,176 @@ +namespace JewelryStore +{ + 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() + { + System.Windows.Forms.Button buttonReady; + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonToWork = new System.Windows.Forms.Button(); + this.buttonPut = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + buttonReady = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + buttonReady.Location = new System.Drawing.Point(1273, 225); + buttonReady.Name = "buttonReady"; + buttonReady.Size = new System.Drawing.Size(215, 34); + buttonReady.TabIndex = 3; + buttonReady.Text = "Заказ готов"; + buttonReady.UseVisualStyleBackColor = true; + buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(9, 52); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(1227, 386); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(1273, 52); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(215, 34); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать заказ"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonToWork + // + this.buttonToWork.Location = new System.Drawing.Point(1273, 137); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(215, 34); + this.buttonToWork.TabIndex = 2; + this.buttonToWork.Text = "Отдать на выполнение"; + this.buttonToWork.UseVisualStyleBackColor = true; + this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); + // + // buttonPut + // + this.buttonPut.Location = new System.Drawing.Point(1273, 308); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(215, 34); + this.buttonPut.TabIndex = 4; + this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.UseVisualStyleBackColor = true; + this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(215, 34); + this.buttonRefresh.TabIndex = 5; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1530, 33); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "драгоценностиToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.изделияToolStripMenuItem.Text = "Драгоценности"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1530, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + this.Controls.Add(buttonReady); + this.Controls.Add(this.buttonToWork); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Сборка мебели"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreate; + private Button buttonToWork; + private Button buttonPut; + private Button buttonRefresh; + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + } +} \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs new file mode 100644 index 0000000..284076e --- /dev/null +++ b/JewelryStore/FormMain.cs @@ -0,0 +1,193 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreDataModels.Enums; +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 JewelryStore +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["JewelId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + + if (service is FormJewel form) + { + form.ShowDialog(); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonToWork_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + 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) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void buttonReady_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + 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) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void buttonPut_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + 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) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/JewelryStore/FormMain.resx b/JewelryStore/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index 74fe05f..90bafab 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -10,10 +10,13 @@ + + + \ No newline at end of file diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 666baa8..4a4a47e 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -1,16 +1,56 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreBusinessLogic.BusinessLogics; +using JewelryStoreListImplement.Implements; + +using Microsoft.Extensions.DependencyInjection; +using System.Drawing; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + + namespace JewelryStore { 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, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); + // To customize application configuration such as set high DPI + //settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } } \ No newline at end of file diff --git a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs index 66fe1fa..e1f1efa 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.BusinessLogics { - internal class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic + public class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic { public bool Create(JewelBindingModel model) { diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index f3a90c2..f2c4576 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.BusinessLogics { - internal class OrderLogic : IOrderLogic //TODO реализовать интерфейс + public class OrderLogic : IOrderLogic //TODO реализовать интерфейс { // Класс с логикой для заказов будет отвечать за получение списка заказов, //создания заказа и смены его статусов.Следует учитывать, что у заказа можно diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs index 8b2fd87..3d6c331 100644 --- a/JewelryStoreListImplement/Implements/JewelStorage.cs +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class JewelStorage : IJewelStorage // TODO реализовать интерфейс + public class JewelStorage : IJewelStorage // TODO реализовать интерфейс { public JewelViewModel? Delete(JewelBindingModel model) { diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs index abcb051..ade07d9 100644 --- a/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace JewelryStoreListImplement.Implements { - internal class OrderStorage : IOrderStorage // TODO реализовать интерфейс + public class OrderStorage : IOrderStorage // TODO реализовать интерфейс { public OrderViewModel? Delete(OrderBindingModel model) { -- 2.25.1 From 311bcca65f76122f880234c14eab797718843578 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Feb 2023 15:27:10 +0400 Subject: [PATCH 17/21] JewelLogic_1 --- .../BusinessLogics/JewelLogic.cs | 90 +++++++++++++++++-- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs index e1f1efa..27b6d07 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -1,7 +1,9 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,29 +14,107 @@ namespace JewelryStoreBusinessLogic.BusinessLogics { public class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic { + private readonly ILogger _logger; + private readonly IJewelStorage _jewelStorage; + + public JewelLogic(ILogger logger, IJewelStorage jewelStorage) + { + _logger = logger; + _jewelStorage= jewelStorage; + } + public bool Create(JewelBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_jewelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Delete(JewelBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_jewelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public JewelViewModel? ReadElement(JewelSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. JewelName:{JewelName}.Id:{ Id}", model.JewelName, model.Id); + var element = _jewelStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; } public List? ReadList(JewelSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. JewelName:{JeweltName}.Id:{ Id}", model?.JewelName, model?.Id); + var list = model == null ? _jewelStorage.GetFullList() : _jewelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } public bool Update(JewelBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_jewelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(JewelBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.JewelName)) + { + throw new ArgumentNullException("Нет названия драгоценности", + nameof(model.JewelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена драгоценности должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Jewel. JewelName:{JewelName}. Price:{ Price}. Id: { Id}", model.JewelName, model.Price, model.Id); + var element = _jewelStorage.GetElement(new JewelSearchModel + { + JewelName = model.JewelName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Драгоценность с таким названием уже есть"); + } } } } -- 2.25.1 From 3684e616dc99e9cdfe8c777c3e57f7b816803f77 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Feb 2023 15:42:50 +0400 Subject: [PATCH 18/21] orderLogic_1 --- JewelryStore/FormMain.Designer.cs | 28 ++--- JewelryStore/FormMain.resx | 65 +---------- .../BusinessLogics/OrderLogic.cs | 107 ++++++++++++++++-- 3 files changed, 114 insertions(+), 86 deletions(-) diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index 4729020..4988313 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.Windows.Forms.Button buttonReady; + this.buttonReady = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreate = new System.Windows.Forms.Button(); this.buttonToWork = new System.Windows.Forms.Button(); @@ -38,20 +38,19 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - buttonReady = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // buttonReady // - buttonReady.Location = new System.Drawing.Point(1273, 225); - buttonReady.Name = "buttonReady"; - buttonReady.Size = new System.Drawing.Size(215, 34); - buttonReady.TabIndex = 3; - buttonReady.Text = "Заказ готов"; - buttonReady.UseVisualStyleBackColor = true; - buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + this.buttonReady.Location = new System.Drawing.Point(1273, 225); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(215, 34); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ готов"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); // // dataGridView // @@ -126,14 +125,14 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // - this.изделияToolStripMenuItem.Name = "драгоценностиToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); this.изделияToolStripMenuItem.Text = "Драгоценности"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); // @@ -144,14 +143,14 @@ this.ClientSize = new System.Drawing.Size(1530, 450); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonPut); - this.Controls.Add(buttonReady); + this.Controls.Add(this.buttonReady); this.Controls.Add(this.buttonToWork); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); this.MainMenuStrip = this.menuStrip; this.Name = "FormMain"; - this.Text = "Сборка мебели"; + this.Text = "Изготовление Драгоценностей"; this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip.ResumeLayout(false); @@ -172,5 +171,6 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; + private Button buttonReady; } } \ No newline at end of file diff --git a/JewelryStore/FormMain.resx b/JewelryStore/FormMain.resx index 1af7de1..81a9e3d 100644 --- a/JewelryStore/FormMain.resx +++ b/JewelryStore/FormMain.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index f2c4576..6bcfa52 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,7 +1,10 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -11,35 +14,117 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic //TODO реализовать интерфейс - { -// Класс с логикой для заказов будет отвечать за получение списка заказов, -//создания заказа и смены его статусов.Следует учитывать, что у заказа можно -//менять статус на новый, если его текущий статус предшествует новому -//(например, в статус «Готов» можно переводить, если заказ находится в статусе -//«Выполняется»). + { + // Класс с логикой для заказов будет отвечать за получение списка заказов, + //создания заказа и смены его статусов.Следует учитывать, что у заказа можно + //менять статус на новый, если его текущий статус предшествует новому + //(например, в статус «Готов» можно переводить, если заказ находится в статусе + //«Выполняется»). + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public bool CreateOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool DeliveryOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Готов) return false; + + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } public bool FinishOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Выполняется) return false; + + model.Status = OrderStatus.Готов; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } public List? ReadList(OrderSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Принят) return false; + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.JewelId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество драгоценностей в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. JewelId: { JewelId}", model.Id, model.Sum, model.JewelId); + } + } } -- 2.25.1 From bed4ff1872d561b75c2fd064edc848c9b0be82ae Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Feb 2023 16:27:05 +0400 Subject: [PATCH 19/21] Order --- JewelryStoreDataModels/Models/IOrderModel.cs | 3 + .../Implements/OrderStorage.cs | 77 +++++++++++++++++-- JewelryStoreListImplement/Models/Order.cs | 62 +++++++++++++-- 3 files changed, 128 insertions(+), 14 deletions(-) diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs index b7b8c70..7de0c62 100644 --- a/JewelryStoreDataModels/Models/IOrderModel.cs +++ b/JewelryStoreDataModels/Models/IOrderModel.cs @@ -11,6 +11,9 @@ namespace JewelryStoreDataModels.Models public interface IOrderModel : IId { int JewelId { get; } + string JewelName { get; } + + int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs index ade07d9..ae9c7db 100644 --- a/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -12,34 +13,98 @@ namespace JewelryStoreListImplement.Implements { public class OrderStorage : IOrderStorage // TODO реализовать интерфейс { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } public OrderViewModel? Delete(OrderBindingModel model) { - throw new NotImplementedException(); + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; } public OrderViewModel? GetElement(OrderSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; } public List GetFilteredList(OrderSearchModel model) { - throw new NotImplementedException(); + var result = new List(); + if (model == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; } public List GetFullList() { - throw new NotImplementedException(); + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; } public OrderViewModel? Insert(OrderBindingModel model) { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; } } } diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs index dc1ef36..12349c8 100644 --- a/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStoreListImplement/Models/Order.cs @@ -1,4 +1,6 @@ -using JewelryStoreDataModels.Enums; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; using JewelryStoreDataModels.Models; using System; using System.Collections.Generic; @@ -10,18 +12,62 @@ namespace JewelryStoreListImplement.Models { public class Order : IOrderModel // TODO Класс для модели сущности «Заказ» разработать самостоятельно { - public int JewelId => throw new NotImplementedException(); + public int JewelId { get; private set; } + public string JewelName { get; private set; } - public int Count => throw new NotImplementedException(); + public int Count { get; private set; } - public double Sum => throw new NotImplementedException(); + public double Sum { get; private set; } - public OrderStatus Status => throw new NotImplementedException(); + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate => throw new NotImplementedException(); + public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement => throw new NotImplementedException(); + public DateTime? DateImplement { get; private set; } - public int Id => throw new NotImplementedException(); + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + JewelName = model.JewelName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + JewelId = model.JewelId; + JewelName = model.JewelName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + JewelName = JewelName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; } } -- 2.25.1 From db02f3c6d16e7889cfcf2e9f183e2575694c460b Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Feb 2023 16:31:17 +0400 Subject: [PATCH 20/21] Jewel Storage_1 --- .../Implements/JewelStorage.cs | 79 +++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs index 3d6c331..e09b4ab 100644 --- a/JewelryStoreListImplement/Implements/JewelStorage.cs +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -12,34 +13,100 @@ namespace JewelryStoreListImplement.Implements { public class JewelStorage : IJewelStorage // TODO реализовать интерфейс { + private readonly DataListSingleton _source; + public JewelStorage() + { + _source = DataListSingleton.GetInstance(); + } public JewelViewModel? Delete(JewelBindingModel model) { - throw new NotImplementedException(); + for (int i = 0; i < _source.Jewels.Count; ++i) + { + if (_source.Jewels[i].Id == model.Id) + { + var element = _source.Jewels[i]; + _source.Jewels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; } public JewelViewModel? GetElement(JewelSearchModel model) { - throw new NotImplementedException(); + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + foreach (var jewel in _source.Jewels) + { + if ((!string.IsNullOrEmpty(model.JewelName) && + jewel.JewelName == model.JewelName) || + (model.Id.HasValue && jewel.Id == model.Id)) + { + return jewel.GetViewModel; + } + } + return null; } public List GetFilteredList(JewelSearchModel model) { - throw new NotImplementedException(); + var result = new List(); + if (string.IsNullOrEmpty(model.JewelName)) + { + return result; + } + foreach (var jewel in _source.Jewels) + { + if (jewel.JewelName.Contains(model.JewelName)) + { + result.Add(jewel.GetViewModel); + } + } + return result; } public List GetFullList() { - throw new NotImplementedException(); + var result = new List(); + foreach (var jewel in _source.Jewels) + { + result.Add(jewel.GetViewModel); + } + return result; } public JewelViewModel? Insert(JewelBindingModel model) { - throw new NotImplementedException(); + model.Id = 1; + foreach (var jewel in _source.Jewels) + { + if (model.Id <= jewel.Id) + { + model.Id = jewel.Id + 1; + } + } + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + return newJewel.GetViewModel; } public JewelViewModel? Update(JewelBindingModel model) { - throw new NotImplementedException(); + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.Id) + { + jewel.Update(model); + return jewel.GetViewModel; + } + } + return null; } } } -- 2.25.1 From 9a7e0e839a38806971082f23a091aea81148fe4d Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Feb 2023 17:46:35 +0400 Subject: [PATCH 21/21] full --- JewelryStore/FormJewel.Designer.cs | 127 +++++++++++++++------------- JewelryStore/FormJewel.cs | 5 +- JewelryStore/FormJewel.resx | 65 +------------- JewelryStore/FormJewels.Designer.cs | 88 ++++++++++++++++++- JewelryStore/FormJewels.cs | 107 ++++++++++++++++++++++- JewelryStore/FormMain.cs | 4 +- 6 files changed, 266 insertions(+), 130 deletions(-) diff --git a/JewelryStore/FormJewel.Designer.cs b/JewelryStore/FormJewel.Designer.cs index ffaa849..3111cd6 100644 --- a/JewelryStore/FormJewel.Designer.cs +++ b/JewelryStore/FormJewel.Designer.cs @@ -33,15 +33,16 @@ this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxPrice = new System.Windows.Forms.TextBox(); this.groupBoxComponent = new System.Windows.Forms.GroupBox(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.buttonChange = new System.Windows.Forms.Button(); - this.buttonDelete = new System.Windows.Forms.Button(); - this.buttonUpdate = new System.Windows.Forms.Button(); this.groupBoxComponent.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -92,6 +93,60 @@ this.groupBoxComponent.TabStop = false; this.groupBoxComponent.Text = "Компоненты"; // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(604, 164); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(604, 124); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(602, 81); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(602, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(25, 30); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(554, 281); + this.dataGridView.TabIndex = 0; + // // buttonSave // this.buttonSave.Location = new System.Drawing.Point(431, 452); @@ -112,18 +167,13 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // - // dataGridView + // ID // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnComponent, - this.ColumnCount}); - this.dataGridView.Location = new System.Drawing.Point(25, 30); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.RowTemplate.Height = 33; - this.dataGridView.Size = new System.Drawing.Size(554, 281); - this.dataGridView.TabIndex = 0; + this.ID.HeaderText = "Column1"; + this.ID.MinimumWidth = 8; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 150; // // ColumnComponent // @@ -139,46 +189,6 @@ this.ColumnCount.Name = "ColumnCount"; this.ColumnCount.Width = 150; // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(602, 35); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(112, 34); - this.buttonAdd.TabIndex = 1; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); - // - // buttonChange - // - this.buttonChange.Location = new System.Drawing.Point(602, 81); - this.buttonChange.Name = "buttonChange"; - this.buttonChange.Size = new System.Drawing.Size(112, 34); - this.buttonChange.TabIndex = 2; - this.buttonChange.Text = "Изменить"; - this.buttonChange.UseVisualStyleBackColor = true; - this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); - // - // buttonDelete - // - this.buttonDelete.Location = new System.Drawing.Point(604, 124); - this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(112, 34); - this.buttonDelete.TabIndex = 3; - this.buttonDelete.Text = "Удалить"; - this.buttonDelete.UseVisualStyleBackColor = true; - this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); - // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(604, 164); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(112, 34); - this.buttonUpdate.TabIndex = 4; - this.buttonUpdate.Text = "Обновить"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); - // // FormJewel // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -213,9 +223,10 @@ private Button buttonChange; private Button buttonAdd; private DataGridView dataGridView; - private DataGridViewTextBoxColumn ColumnComponent; - private DataGridViewTextBoxColumn ColumnCount; private Button buttonSave; private Button buttonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/JewelryStore/FormJewel.cs b/JewelryStore/FormJewel.cs index c820b68..584076e 100644 --- a/JewelryStore/FormJewel.cs +++ b/JewelryStore/FormJewel.cs @@ -69,7 +69,7 @@ namespace JewelryStore dataGridView.Rows.Clear(); foreach (var pc in _JewelComponents) { - dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); + dataGridView.Rows.Add(new object[] { pc.Key,pc.Value.Item1.ComponentName, pc.Value.Item2 }); } textBoxPrice.Text = CalcPrice().ToString(); } @@ -115,8 +115,7 @@ namespace JewelryStore var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); if (service is FormJewelComponent form) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; form.Count = _JewelComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) diff --git a/JewelryStore/FormJewel.resx b/JewelryStore/FormJewel.resx index 1af7de1..bb23025 100644 --- a/JewelryStore/FormJewel.resx +++ b/JewelryStore/FormJewel.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + \ No newline at end of file diff --git a/JewelryStore/FormJewels.Designer.cs b/JewelryStore/FormJewels.Designer.cs index 1f178f8..54f228a 100644 --- a/JewelryStore/FormJewels.Designer.cs +++ b/JewelryStore/FormJewels.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(597, 547); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(615, 12); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(171, 39); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(615, 110); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(171, 39); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(615, 209); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(171, 39); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(615, 310); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(171, 39); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormJewels + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormJewels"; + this.ClientSize = new System.Drawing.Size(805, 563); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormJewels"; + this.Text = "Драгоценности"; + this.Load += new System.EventHandler(this.FormJewels_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; } } \ No newline at end of file diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index dc4f263..bea74a4 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,114 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; - +using JewelryStore; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; namespace JewelryStore { public partial class FormJewels : Form //TODO { - public FormJewels() + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + + public FormJewels(ILogger logger, IJewelLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка компонентов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + + if (service is FormJewel form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + + if (service is FormJewel form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 JewelBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + + private void FormJewels_Load(object sender, EventArgs e) + { + LoadData(); + } + } } diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 284076e..3baf773 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -64,9 +64,9 @@ namespace JewelryStore private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + var service = Program.ServiceProvider?.GetService(typeof(FormJewels)); - if (service is FormJewel form) + if (service is FormJewels form) { form.ShowDialog(); } -- 2.25.1