From 5bf198916eb1133d4ec84ed002c9fd663703db3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 18:03:54 +0400 Subject: [PATCH 01/14] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop.sln | 6 ++++++ .../FlowerShopDataModels.csproj | 9 +++++++++ FlowerShop/FlowerShopDataModels/IComponentModel.cs | 8 ++++++++ FlowerShop/FlowerShopDataModels/IId.cs | 7 +++++++ FlowerShop/FlowerShopDataModels/IOrderModel.cs | 14 ++++++++++++++ FlowerShop/FlowerShopDataModels/IProductModel.cs | 9 +++++++++ FlowerShop/FlowerShopDataModels/OrderStatus.cs | 11 +++++++++++ 7 files changed, 64 insertions(+) create mode 100644 FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj create mode 100644 FlowerShop/FlowerShopDataModels/IComponentModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/IId.cs create mode 100644 FlowerShop/FlowerShopDataModels/IOrderModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/IProductModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/OrderStatus.cs diff --git a/FlowerShop/FlowerShop.sln b/FlowerShop/FlowerShop.sln index 1fb10d9..1885fb7 100644 --- a/FlowerShop/FlowerShop.sln +++ b/FlowerShop/FlowerShop.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{086CB019-AA3B-425A-87B0-26662D1F201F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {086CB019-AA3B-425A-87B0-26662D1F201F}.Debug|Any CPU.Build.0 = Debug|Any CPU {086CB019-AA3B-425A-87B0-26662D1F201F}.Release|Any CPU.ActiveCfg = Release|Any CPU {086CB019-AA3B-425A-87B0-26662D1F201F}.Release|Any CPU.Build.0 = Release|Any CPU + {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj b/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/FlowerShop/FlowerShopDataModels/IComponentModel.cs b/FlowerShop/FlowerShopDataModels/IComponentModel.cs new file mode 100644 index 0000000..05b4348 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/IId.cs b/FlowerShop/FlowerShopDataModels/IId.cs new file mode 100644 index 0000000..dfec951 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace FlowerShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/IOrderModel.cs new file mode 100644 index 0000000..70be197 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IOrderModel.cs @@ -0,0 +1,14 @@ +using FlowerShopDataModels.Enums; + +namespace FlowerShopDataModels.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/FlowerShop/FlowerShopDataModels/IProductModel.cs b/FlowerShop/FlowerShopDataModels/IProductModel.cs new file mode 100644 index 0000000..73210af --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IProductModel.cs @@ -0,0 +1,9 @@ +namespace FlowerShopDataModels.Models +{ + public interface IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/OrderStatus.cs new file mode 100644 index 0000000..583cc02 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace FlowerShopDataModels.Enums +{ + public enum OrderStatus + { + Unknown = -1, + Accepted = 0, + Processing = 1, + Ready = 2, + Issued = 3 + } +} -- 2.25.1 From f5db27a124c41e0a311f14d226c8dbd382ed5b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 18:15:14 +0400 Subject: [PATCH 02/14] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20Binding=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop.sln | 6 ++++++ .../BindingModels/ComponentBindingModel.cs | 11 ++++++++++ .../BindingModels/OrderBindingModel.cs | 16 +++++++++++++++ .../BindingModels/ProductBindingModel.cs | 12 +++++++++++ .../FlowerShopContracts.csproj | 20 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj diff --git a/FlowerShop/FlowerShop.sln b/FlowerShop/FlowerShop.sln index 1885fb7..4c8577a 100644 --- a/FlowerShop/FlowerShop.sln +++ b/FlowerShop/FlowerShop.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\Fl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.Build.0 = Release|Any CPU + {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..917c68f --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..7f94bb7 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ProductId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Unknown; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..28300bf --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs @@ -0,0 +1,12 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class ProductBindingModel : IProductModel + { + public int Id { get; set; } + public string ProductName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ProductComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj new file mode 100644 index 0000000..66e8e8a --- /dev/null +++ b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + -- 2.25.1 From dea2ccc826eb5156eddc370a901f34cfb47054ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 18:17:58 +0400 Subject: [PATCH 03/14] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20View=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj | 1 - .../SearchModels/ComponentSearchModel.cs | 8 ++++++++ .../FlowerShopContracts/SearchModels/OrderSearchModel.cs | 7 +++++++ .../SearchModels/ProductSearchModel.cs | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs diff --git a/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj index 66e8e8a..5c02fdf 100644 --- a/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj +++ b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj @@ -12,7 +12,6 @@ - diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..37afe02 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..288271c --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace FlowerShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs new file mode 100644 index 0000000..383ac75 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopContracts.SearchModels +{ + public class ProductSearchModel + { + public int? Id { get; set; } + public string? ProductName { get; set; } + } +} -- 2.25.1 From 80eb3374b1b40d97b7135ee106820efa9ea20bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 18:59:33 +0400 Subject: [PATCH 04/14] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ProductBindingModel.cs => BouquetBindingModel.cs} | 6 +++--- .../BindingModels/OrderBindingModel.cs | 2 +- .../SearchModels/ProductSearchModel.cs | 4 ++-- FlowerShop/FlowerShopDataModels/IBouquetModel.cs | 9 +++++++++ FlowerShop/FlowerShopDataModels/IOrderModel.cs | 2 +- FlowerShop/FlowerShopDataModels/IProductModel.cs | 9 --------- 6 files changed, 16 insertions(+), 16 deletions(-) rename FlowerShop/FlowerShopContracts/BindingModels/{ProductBindingModel.cs => BouquetBindingModel.cs} (53%) create mode 100644 FlowerShop/FlowerShopDataModels/IBouquetModel.cs delete mode 100644 FlowerShop/FlowerShopDataModels/IProductModel.cs diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs similarity index 53% rename from FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs rename to FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs index 28300bf..6db7a88 100644 --- a/FlowerShop/FlowerShopContracts/BindingModels/ProductBindingModel.cs +++ b/FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs @@ -2,11 +2,11 @@ namespace FlowerShopContracts.BindingModels { - public class ProductBindingModel : IProductModel + public class BouquetBindingModel : IBouquetModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string BouquetName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents { get; set; } = new(); + public Dictionary BouquetComponents { get; set; } = new(); } } \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs index 7f94bb7..76cfd77 100644 --- a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -6,7 +6,7 @@ namespace FlowerShopContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } + public int BouquetId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Unknown; diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs index 383ac75..75debc3 100644 --- a/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs +++ b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs @@ -1,8 +1,8 @@ namespace FlowerShopContracts.SearchModels { - public class ProductSearchModel + public class BouquetSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? BouquetName { get; set; } } } diff --git a/FlowerShop/FlowerShopDataModels/IBouquetModel.cs b/FlowerShop/FlowerShopDataModels/IBouquetModel.cs new file mode 100644 index 0000000..29b973d --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IBouquetModel.cs @@ -0,0 +1,9 @@ +namespace FlowerShopDataModels.Models +{ + public interface IBouquetModel : IId + { + string BouquetName { get; } + double Price { get; } + Dictionary BouquetComponents { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/IOrderModel.cs index 70be197..416bc78 100644 --- a/FlowerShop/FlowerShopDataModels/IOrderModel.cs +++ b/FlowerShop/FlowerShopDataModels/IOrderModel.cs @@ -4,7 +4,7 @@ namespace FlowerShopDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } + int BouquetId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FlowerShop/FlowerShopDataModels/IProductModel.cs b/FlowerShop/FlowerShopDataModels/IProductModel.cs deleted file mode 100644 index 73210af..0000000 --- a/FlowerShop/FlowerShopDataModels/IProductModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace FlowerShopDataModels.Models -{ - public interface IProductModel : IId - { - string ProductName { get; } - double Price { get; } - Dictionary ProductComponents { get; } - } -} -- 2.25.1 From 52ba95b50e1b4ce489cebaf6f2b80c1970887ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 19:21:11 +0400 Subject: [PATCH 05/14] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts/IBouquetLogic.cs | 15 +++++++++++ .../IComponentLogic.cs | 15 +++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 +++++++++++ .../FlowerShopContracts.csproj | 6 ----- .../StoragesContracts/IBouquetStorage.cs | 16 ++++++++++++ .../StoragesContracts/IComponentStorage.cs | 16 ++++++++++++ .../StoragesContracts/IOrderStorage.cs | 16 ++++++++++++ .../ViewModels/BouquetViewModel.cs | 15 +++++++++++ .../ViewModels/ComponentViewModel.cs | 14 +++++++++++ .../ViewModels/OrderViewModel.cs | 25 +++++++++++++++++++ .../FlowerShopDataModels/OrderStatus.cs | 2 +- 11 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs new file mode 100644 index 0000000..ce69ce4 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IBouquetLogic + { + List? ReadList(BouquetSearchModel? model); + BouquetViewModel? ReadElement(BouquetSearchModel model); + bool Create(BouquetBindingModel model); + bool Update(BouquetBindingModel model); + bool Delete(BouquetBindingModel model); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..5913315 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.ViewModels; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..0449bf8 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj index 5c02fdf..5192185 100644 --- a/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj +++ b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj @@ -10,10 +10,4 @@ - - - - - - diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs new file mode 100644 index 0000000..3243a87 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IBouquetStorage + { + List GetFullList(); + List GetFilteredList(BouquetSearchModel model); + BouquetViewModel? GetElement(BouquetSearchModel model); + BouquetViewModel? Insert(BouquetBindingModel model); + BouquetViewModel? Update(BouquetBindingModel model); + BouquetViewModel? Delete(BouquetBindingModel model); + } +} diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..355796c --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..c0f34d9 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs new file mode 100644 index 0000000..2a7d6ed --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs @@ -0,0 +1,15 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class BouquetViewModel : IBouquetModel + { + public int Id { get; set; } + [DisplayName("Название букета")] + public string BouquetName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary BouquetComponents { get; set; } = new(); + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..3a06a8f --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..397a029 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int BouquetId { get; set; } + [DisplayName("Букет")] + public string BouquetName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Unknown; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/OrderStatus.cs index 583cc02..a93420b 100644 --- a/FlowerShop/FlowerShopDataModels/OrderStatus.cs +++ b/FlowerShop/FlowerShopDataModels/OrderStatus.cs @@ -6,6 +6,6 @@ Accepted = 0, Processing = 1, Ready = 2, - Issued = 3 + Delivered = 3 } } -- 2.25.1 From fa639ce8b4fac826685f1a755744460e7065881c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 29 Jan 2023 22:10:01 +0400 Subject: [PATCH 06/14] =?UTF-8?q?=D0=A0=D0=B5=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D1=83=D0=BA=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=B2.=20=D0=9E=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop.sln | 6 + .../FlowerShopBusinessLogic/BouquetLogic.cs | 127 ++++++++++++++++++ .../FlowerShopBusinessLogic/ComponentLogic.cs | 127 ++++++++++++++++++ .../FlowerShopBusinessLogic.csproj | 18 +++ .../FlowerShopBusinessLogic/OrderLogic.cs | 98 ++++++++++++++ 5 files changed, 376 insertions(+) create mode 100644 FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj create mode 100644 FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs diff --git a/FlowerShop/FlowerShop.sln b/FlowerShop/FlowerShop.sln index 4c8577a..5af9705 100644 --- a/FlowerShop/FlowerShop.sln +++ b/FlowerShop/FlowerShop.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "Flo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.Build.0 = Debug|Any CPU {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.ActiveCfg = Release|Any CPU {404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.Build.0 = Release|Any CPU + {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs new file mode 100644 index 0000000..0f4c3fb --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs @@ -0,0 +1,127 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class BouquetLogic : IBouquetLogic + { + private readonly ILogger _logger; + private readonly IBouquetStorage _bouquetStorage; + + public BouquetLogic(ILogger logger, IBouquetStorage bouquetStorage) + { + _logger = logger; + _bouquetStorage = bouquetStorage; + } + + public List? ReadList(BouquetSearchModel? model) + { + _logger.LogInformation("ReadList. BouquetName: {BouquetName}. Id: {Id}", model?.BouquetName, model?.Id); + + var list = model == null ? _bouquetStorage.GetFullList() : _bouquetStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public BouquetViewModel? ReadElement(BouquetSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. BouquetName: {BouquetName}. Id: {Id}", model.BouquetName, model.Id); + + var element = _bouquetStorage.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(BouquetBindingModel model) + { + CheckModel(model); + + if (_bouquetStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(BouquetBindingModel model) + { + CheckModel(model); + + if (_bouquetStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(BouquetBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_bouquetStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(BouquetBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.BouquetName)) + { + throw new ArgumentNullException("Нет названия букета", nameof(model.BouquetName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена букета должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Bouquet. BouquetName: {BouquetName}. Price: {Price}. Id: {Id}", model.BouquetName, model.Price, model.Id); + + var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs b/FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..6874aae --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs @@ -0,0 +1,127 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.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/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj new file mode 100644 index 0000000..a2ee322 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..7e603f3 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs @@ -0,0 +1,98 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id: {Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Unknown) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Accepted; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + throw new NotImplementedException(); + } + public bool FinishOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId); + + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким идентификатором уже есть"); + } + } + } +} -- 2.25.1 From 2093186453cc531445a2c83c52a9913a5a872b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 18:21:48 +0400 Subject: [PATCH 07/14] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowerShopBusinessLogic/OrderLogic.cs | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs index 7e603f3..d21bffe 100644 --- a/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs @@ -57,16 +57,61 @@ namespace FlowerShopBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + if (model.Status != OrderStatus.Accepted) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Processing; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + } + + return true; } public bool FinishOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + if (model.Status != OrderStatus.Processing) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Ready; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + } + + return true; } public bool DeliveryOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + if (model.Status != OrderStatus.Ready) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Delivered; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + } + + return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) -- 2.25.1 From cdf691d0787b55e6f361397d6f1fa340b0545f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 19:26:20 +0400 Subject: [PATCH 08/14] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B-?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D1=81=D1=83=D1=89=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D0=B2=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop.sln | 14 ++-- .../FlowerShopListImplement.csproj | 14 ++++ .../FlowerShopListImplement/Models/Bouquet.cs | 50 +++++++++++++++ .../Models/Component.cs | 47 ++++++++++++++ .../FlowerShopListImplement/Models/Order.cs | 64 +++++++++++++++++++ 5 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj create mode 100644 FlowerShop/FlowerShopListImplement/Models/Bouquet.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Component.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Order.cs diff --git a/FlowerShop/FlowerShop.sln b/FlowerShop/FlowerShop.sln index 5af9705..db9a6f6 100644 --- a/FlowerShop/FlowerShop.sln +++ b/FlowerShop/FlowerShop.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{086CB019-AA3B-425A-87B0-26662D1F201F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{086CB019-AA3B-425A-87B0-26662D1F201F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{C58840E6-D68D-476E-AB3A-EB13F1740FC8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.Build.0 = Debug|Any CPU {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.ActiveCfg = Release|Any CPU {D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.Build.0 = Release|Any CPU + {C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj b/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj new file mode 100644 index 0000000..ca6fa62 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs b/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs new file mode 100644 index 0000000..c4fbad1 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs @@ -0,0 +1,50 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Bouquet : IBouquetModel + { + public int Id { get; private set; } + public string BouquetName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary BouquetComponents { get; private set; } = new Dictionary(); + + public static Bouquet? Create(BouquetBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Bouquet() + { + Id = model.Id, + BouquetName = model.BouquetName, + Price = model.Price, + BouquetComponents = model.BouquetComponents + }; + } + + public void Update(BouquetBindingModel? model) + { + if (model == null) + { + return; + } + + BouquetName = model.BouquetName; + Price = model.Price; + BouquetComponents = model.BouquetComponents; + } + + public BouquetViewModel GetViewModel => new() + { + Id = Id, + BouquetName = BouquetName, + Price = Price, + BouquetComponents = BouquetComponents + }; + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Component.cs b/FlowerShop/FlowerShopListImplement/Models/Component.cs new file mode 100644 index 0000000..e49ccfa --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + + +namespace FlowerShopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs new file mode 100644 index 0000000..55daa06 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Order.cs @@ -0,0 +1,64 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int BouquetId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Order() + { + Id = model.Id, + BouquetId = model.BouquetId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Id = model.Id; + BouquetId = model.BouquetId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + BouquetId = BouquetId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file -- 2.25.1 From 538b903af492a7aa8ae02e6a18f7b2ed293618bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 19:28:42 +0400 Subject: [PATCH 09/14] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlowerShopBusinessLogic/{ => BusinessLogics}/BouquetLogic.cs | 0 .../{ => BusinessLogics}/ComponentLogic.cs | 0 .../FlowerShopBusinessLogic/{ => BusinessLogics}/OrderLogic.cs | 0 FlowerShop/FlowerShopDataModels/{ => Enums}/OrderStatus.cs | 0 FlowerShop/FlowerShopDataModels/{ => Models}/IBouquetModel.cs | 0 FlowerShop/FlowerShopDataModels/{ => Models}/IComponentModel.cs | 0 FlowerShop/FlowerShopDataModels/{ => Models}/IOrderModel.cs | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename FlowerShop/FlowerShopBusinessLogic/{ => BusinessLogics}/BouquetLogic.cs (100%) rename FlowerShop/FlowerShopBusinessLogic/{ => BusinessLogics}/ComponentLogic.cs (100%) rename FlowerShop/FlowerShopBusinessLogic/{ => BusinessLogics}/OrderLogic.cs (100%) rename FlowerShop/FlowerShopDataModels/{ => Enums}/OrderStatus.cs (100%) rename FlowerShop/FlowerShopDataModels/{ => Models}/IBouquetModel.cs (100%) rename FlowerShop/FlowerShopDataModels/{ => Models}/IComponentModel.cs (100%) rename FlowerShop/FlowerShopDataModels/{ => Models}/IOrderModel.cs (100%) diff --git a/FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs similarity index 100% rename from FlowerShop/FlowerShopBusinessLogic/BouquetLogic.cs rename to FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs diff --git a/FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs similarity index 100% rename from FlowerShop/FlowerShopBusinessLogic/ComponentLogic.cs rename to FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs diff --git a/FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs similarity index 100% rename from FlowerShop/FlowerShopBusinessLogic/OrderLogic.cs rename to FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs diff --git a/FlowerShop/FlowerShopDataModels/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs similarity index 100% rename from FlowerShop/FlowerShopDataModels/OrderStatus.cs rename to FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs diff --git a/FlowerShop/FlowerShopDataModels/IBouquetModel.cs b/FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs similarity index 100% rename from FlowerShop/FlowerShopDataModels/IBouquetModel.cs rename to FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs diff --git a/FlowerShop/FlowerShopDataModels/IComponentModel.cs b/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs similarity index 100% rename from FlowerShop/FlowerShopDataModels/IComponentModel.cs rename to FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs diff --git a/FlowerShop/FlowerShopDataModels/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs similarity index 100% rename from FlowerShop/FlowerShopDataModels/IOrderModel.cs rename to FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs -- 2.25.1 From e692d5d442c535f3efe97eff887c550a009efcfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 20:03:38 +0400 Subject: [PATCH 10/14] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataListSingleton.cs | 29 +++++ .../Implements/BouquetStorage.cs | 119 ++++++++++++++++++ .../Implements/ComponentStorage.cs | 119 ++++++++++++++++++ .../Implements/OrderStorage.cs | 119 ++++++++++++++++++ 4 files changed, 386 insertions(+) create mode 100644 FlowerShop/FlowerShopListImplement/DataListSingleton.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs diff --git a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..59460c6 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs @@ -0,0 +1,29 @@ +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Bouquets { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Bouquets = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs new file mode 100644 index 0000000..37f43f2 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs @@ -0,0 +1,119 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + public class BouquetStorage : IBouquetStorage + { + private readonly DataListSingleton _source; + + public BouquetStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var bouquet in _source.Bouquets) + { + result.Add(bouquet.GetViewModel); + } + + return result; + } + + public List GetFilteredList(BouquetSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.BouquetName)) + { + return result; + } + + foreach (var bouquet in _source.Bouquets) + { + if (bouquet.BouquetName.Contains(model.BouquetName)) + { + result.Add(bouquet.GetViewModel); + } + } + + return result; + } + + public BouquetViewModel? GetElement(BouquetSearchModel model) + { + if (string.IsNullOrEmpty(model.BouquetName) && !model.Id.HasValue) + { + return null; + } + + foreach (var bouquet in _source.Bouquets) + { + if ((!string.IsNullOrEmpty(model.BouquetName) && bouquet.BouquetName == model.BouquetName) || (model.Id.HasValue && bouquet.Id == model.Id)) + { + return bouquet.GetViewModel; + } + } + + return null; + } + + public BouquetViewModel? Insert(BouquetBindingModel model) + { + model.Id = 1; + foreach (var bouquet in _source.Bouquets) + { + if (model.Id <= bouquet.Id) + { + model.Id = bouquet.Id + 1; + } + } + + var newBouquet = Bouquet.Create(model); + if (newBouquet == null) + { + return null; + } + + _source.Bouquets.Add(newBouquet); + + return newBouquet.GetViewModel; + } + + public BouquetViewModel? Update(BouquetBindingModel model) + { + foreach (var bouquet in _source.Bouquets) + { + if (bouquet.Id == model.Id) + { + bouquet.Update(model); + return bouquet.GetViewModel; + } + } + + return null; + } + + public BouquetViewModel? Delete(BouquetBindingModel model) + { + for (int i = 0; i < _source.Bouquets.Count; ++i) + { + if (_source.Bouquets[i].Id == model.Id) + { + var element = _source.Bouquets[i]; + _source.Bouquets.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..0006a6c --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,119 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + 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/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..90302d3 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,119 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + 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 OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if ((model.Id.HasValue && order.Id == model.Id)) + { + return order.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} -- 2.25.1 From d627ca6623c742129224b095823e9f5086eeefc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 23:20:34 +0400 Subject: [PATCH 11/14] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=E2=84=961=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FlowerShop.csproj | 12 + FlowerShop/FlowerShop/Form1.Designer.cs | 39 --- FlowerShop/FlowerShop/Form1.cs | 10 - FlowerShop/FlowerShop/Form1.resx | 120 --------- FlowerShop/FlowerShop/FormBouquet.Designer.cs | 235 ++++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.cs | 222 +++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.resx | 60 +++++ .../FormBouquetComponent.Designer.cs | 126 ++++++++++ FlowerShop/FlowerShop/FormBouquetComponent.cs | 82 ++++++ .../FlowerShop/FormBouquetComponent.resx | 60 +++++ .../FlowerShop/FormBouquets.Designer.cs | 122 +++++++++ FlowerShop/FlowerShop/FormBouquets.cs | 111 +++++++++ FlowerShop/FlowerShop/FormBouquets.resx | 60 +++++ .../FlowerShop/FormComponent.Designer.cs | 126 ++++++++++ FlowerShop/FlowerShop/FormComponent.cs | 86 +++++++ FlowerShop/FlowerShop/FormComponent.resx | 60 +++++ .../FlowerShop/FormComponents.Designer.cs | 122 +++++++++ FlowerShop/FlowerShop/FormComponents.cs | 102 ++++++++ FlowerShop/FlowerShop/FormComponents.resx | 60 +++++ .../FlowerShop/FormCreateOrder.Designer.cs | 153 ++++++++++++ FlowerShop/FlowerShop/FormCreateOrder.cs | 126 ++++++++++ FlowerShop/FlowerShop/FormCreateOrder.resx | 60 +++++ FlowerShop/FlowerShop/FormMain.Designer.cs | 184 ++++++++++++++ FlowerShop/FlowerShop/FormMain.cs | 184 ++++++++++++++ FlowerShop/FlowerShop/FormMain.resx | 63 +++++ FlowerShop/FlowerShop/Program.cs | 39 ++- .../BusinessLogics/BouquetLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 29 +-- .../BindingModels/OrderBindingModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../FlowerShopDataModels/Enums/OrderStatus.cs | 10 +- .../Implements/OrderStorage.cs | 22 +- .../FlowerShopListImplement/Models/Order.cs | 5 - 33 files changed, 2490 insertions(+), 206 deletions(-) delete mode 100644 FlowerShop/FlowerShop/Form1.Designer.cs delete mode 100644 FlowerShop/FlowerShop/Form1.cs delete mode 100644 FlowerShop/FlowerShop/Form1.resx create mode 100644 FlowerShop/FlowerShop/FormBouquet.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormBouquet.cs create mode 100644 FlowerShop/FlowerShop/FormBouquet.resx create mode 100644 FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormBouquetComponent.cs create mode 100644 FlowerShop/FlowerShop/FormBouquetComponent.resx create mode 100644 FlowerShop/FlowerShop/FormBouquets.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormBouquets.cs create mode 100644 FlowerShop/FlowerShop/FormBouquets.resx create mode 100644 FlowerShop/FlowerShop/FormComponent.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.resx create mode 100644 FlowerShop/FlowerShop/FormComponents.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.resx create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.resx create mode 100644 FlowerShop/FlowerShop/FormMain.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormMain.cs create mode 100644 FlowerShop/FlowerShop/FormMain.resx diff --git a/FlowerShop/FlowerShop/FlowerShop.csproj b/FlowerShop/FlowerShop/FlowerShop.csproj index b57c89e..ef0424f 100644 --- a/FlowerShop/FlowerShop/FlowerShop.csproj +++ b/FlowerShop/FlowerShop/FlowerShop.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Form1.Designer.cs b/FlowerShop/FlowerShop/Form1.Designer.cs deleted file mode 100644 index 1b52567..0000000 --- a/FlowerShop/FlowerShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FlowerShop -{ - 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/FlowerShop/FlowerShop/Form1.cs b/FlowerShop/FlowerShop/Form1.cs deleted file mode 100644 index d0bd2d4..0000000 --- a/FlowerShop/FlowerShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FlowerShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Form1.resx b/FlowerShop/FlowerShop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormBouquet.Designer.cs b/FlowerShop/FlowerShop/FormBouquet.Designer.cs new file mode 100644 index 0000000..a36ea10 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.Designer.cs @@ -0,0 +1,235 @@ +namespace FlowerShop +{ + partial class FormBouquet + { + /// + /// 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.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.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxComponent.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(13, 11); + this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(13, 40); + this.labelPrice.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(73, 15); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(83, 10); + this.textBoxName.Margin = new System.Windows.Forms.Padding(2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(83, 37); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(106, 23); + 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(10, 65); + this.groupBoxComponent.Margin = new System.Windows.Forms.Padding(2); + this.groupBoxComponent.Name = "groupBoxComponent"; + this.groupBoxComponent.Padding = new System.Windows.Forms.Padding(2); + this.groupBoxComponent.Size = new System.Drawing.Size(534, 198); + this.groupBoxComponent.TabIndex = 4; + this.groupBoxComponent.TabStop = false; + this.groupBoxComponent.Text = "Компоненты"; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(433, 122); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 30); + 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(433, 88); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 30); + 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(433, 54); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 30); + 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(433, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 30); + 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.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(18, 18); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(388, 169); + 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; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(329, 267); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 25); + 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(420, 267); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 25); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormBouquet + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(560, 297); + 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.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquet"; + this.Text = "Букет"; + this.Load += new System.EventHandler(this.BouquetForm_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/FlowerShop/FlowerShop/FormBouquet.cs b/FlowerShop/FlowerShop/FormBouquet.cs new file mode 100644 index 0000000..199e887 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.cs @@ -0,0 +1,222 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormBouquet : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logic; + private int? _id; + private Dictionary _bouquetComponents; + public int Id { set { _id = value; } } + + public FormBouquet(ILogger logger, IBouquetLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _bouquetComponents = new Dictionary(); + } + + private void BouquetForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Receving bouquet"); + try + { + var view = _logic.ReadElement(new BouquetSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.BouquetName; + textBoxPrice.Text = view.Price.ToString(); + _bouquetComponents = view.BouquetComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquet"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_bouquetComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _bouquetComponents) + { + 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(FormBouquetComponent)); + if (service is FormBouquetComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_bouquetComponents.ContainsKey(form.Id)) + { + _bouquetComponents[form.Id] = (form.ComponentModel, form.Count); + } + + else + { + _bouquetComponents.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(FormBouquetComponent)); + if (service is FormBouquetComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _bouquetComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _bouquetComponents[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); + _bouquetComponents?.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 (_bouquetComponents == null || _bouquetComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Saving bouquet"); + try + { + var model = new BouquetBindingModel + { + Id = _id ?? 0, + BouquetName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + BouquetComponents = _bouquetComponents + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Error during saving"); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during saving bouquet"); + 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 _bouquetComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FlowerShop/FlowerShop/FormBouquet.resx b/FlowerShop/FlowerShop/FormBouquet.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.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/FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs b/FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs new file mode 100644 index 0000000..7ef6205 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace FlowerShop +{ + partial class FormBouquetComponent + { + /// + /// 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(104, 6); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(2); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(129, 23); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(104, 32); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(129, 23); + this.textBoxCount.TabIndex = 1; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(11, 11); + this.labelComponent.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(69, 15); + this.labelComponent.TabIndex = 2; + this.labelComponent.Text = "Компонент"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 34); + this.labelCount.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество "; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(102, 61); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 25); + 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(184, 61); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 25); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormBouquetComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(273, 97); + 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.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquetComponent"; + 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/FlowerShop/FlowerShop/FormBouquetComponent.cs b/FlowerShop/FlowerShop/FormBouquetComponent.cs new file mode 100644 index 0000000..07dbc61 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.cs @@ -0,0 +1,82 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShop +{ + public partial class FormBouquetComponent : 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 FormBouquetComponent(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/FlowerShop/FlowerShop/FormBouquetComponent.resx b/FlowerShop/FlowerShop/FormBouquetComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.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/FlowerShop/FlowerShop/FormBouquets.Designer.cs b/FlowerShop/FlowerShop/FormBouquets.Designer.cs new file mode 100644 index 0000000..eb7fb08 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.Designer.cs @@ -0,0 +1,122 @@ +namespace FlowerShop +{ + partial class FormBouquets + { + /// + /// 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.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(321, 293); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(336, 15); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 25); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(336, 44); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 25); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.ChangeButton_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(336, 73); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 25); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.DeleteButton_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(336, 102); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 25); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormBouquets + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 293); + 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.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquets"; + this.Text = "Букеты"; + this.Load += new System.EventHandler(this.BouquetsForm_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/FlowerShop/FlowerShop/FormBouquets.cs b/FlowerShop/FlowerShop/FormBouquets.cs new file mode 100644 index 0000000..2dca392 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.cs @@ -0,0 +1,111 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormBouquets : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logic; + + public FormBouquets(ILogger logger, IBouquetLogic 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["BouquetName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["BouquetComponents"].Visible = false; + } + + _logger.LogInformation("Receiving bouquets"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquets"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquet)); + + if (service is FormBouquet 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(FormBouquet)); + + if (service is FormBouquet 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("Deleting bouquet"); + + try + { + if (!_logic.Delete(new BouquetBindingModel { Id = id })) + { + throw new Exception("Error during deleting bouquet"); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error deleting bouquet"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void BouquetsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormBouquets.resx b/FlowerShop/FlowerShop/FormBouquets.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.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/FlowerShop/FlowerShop/FormComponent.Designer.cs b/FlowerShop/FlowerShop/FormComponent.Designer.cs new file mode 100644 index 0000000..b37a218 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace FlowerShop +{ + 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(135, 73); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 26); + 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(227, 73); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 26); + 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(17, 8); + this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(17, 38); + this.labelCost.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(76, 6); + this.textBoxName.Margin = new System.Windows.Forms.Padding(2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(208, 23); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(76, 35); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(208, 23); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(316, 110); + 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.Margin = new System.Windows.Forms.Padding(2); + 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/FlowerShop/FlowerShop/FormComponent.cs b/FlowerShop/FlowerShop/FormComponent.cs new file mode 100644 index 0000000..1f4fea1 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.cs @@ -0,0 +1,86 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + 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("Receiving component"); + + 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, "Error during receiving component"); + 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("Saving component"); + 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("Error during saving"); + } + + 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/FlowerShop/FlowerShop/FormComponent.resx b/FlowerShop/FlowerShop/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormComponents.Designer.cs b/FlowerShop/FlowerShop/FormComponents.Designer.cs new file mode 100644 index 0000000..9dfb315 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.Designer.cs @@ -0,0 +1,122 @@ +namespace FlowerShop +{ + 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.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(321, 293); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(336, 15); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 25); + 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(337, 44); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 25); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(336, 73); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 25); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(336, 102); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 25); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 293); + 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.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + 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/FlowerShop/FlowerShop/FormComponents.cs b/FlowerShop/FlowerShop/FormComponents.cs new file mode 100644 index 0000000..1bfbe37 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.cs @@ -0,0 +1,102 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + 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("Receiving components"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving components"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormComponents.resx b/FlowerShop/FlowerShop/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..b7086bf --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs @@ -0,0 +1,153 @@ +namespace FlowerShop +{ + 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.comboBoxBouquet = new System.Windows.Forms.ComboBox(); + this.labelBouquet = 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(); + // + // comboBoxBouquet + // + this.comboBoxBouquet.FormattingEnabled = true; + this.comboBoxBouquet.Location = new System.Drawing.Point(80, 8); + this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(2); + this.comboBoxBouquet.Name = "comboBoxBouquet"; + this.comboBoxBouquet.Size = new System.Drawing.Size(176, 23); + this.comboBoxBouquet.TabIndex = 0; + // + // labelBouquet + // + this.labelBouquet.AutoSize = true; + this.labelBouquet.Location = new System.Drawing.Point(8, 13); + this.labelBouquet.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelBouquet.Name = "labelBouquet"; + this.labelBouquet.Size = new System.Drawing.Size(56, 15); + this.labelBouquet.TabIndex = 1; + this.labelBouquet.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(8, 40); + this.labelCount.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(8, 72); + this.labelSum.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 3; + this.labelSum.Text = "Сумма:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(80, 38); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(176, 23); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(80, 69); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(176, 23); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(96, 97); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 25); + 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(178, 97); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 25); + 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(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(281, 124); + 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.labelBouquet); + this.Controls.Add(this.comboBoxBouquet); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.OrderForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxBouquet; + private Label labelBouquet; + 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/FlowerShop/FlowerShop/FormCreateOrder.cs b/FlowerShop/FlowerShop/FormCreateOrder.cs new file mode 100644 index 0000000..3b2e1fd --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.cs @@ -0,0 +1,126 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Diagnostics; + +namespace FlowerShop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logicBouquet; + private readonly IOrderLogic _logicOrder; + + public FormCreateOrder(ILogger logger, IBouquetLogic logicBouquet, IOrderLogic logicOrder) + { + InitializeComponent(); + _logger = logger; + _logicBouquet = logicBouquet; + _logicOrder = logicOrder; + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Receiving bouquets for order"); + + try + { + var list = _logicBouquet.ReadList(null); + if (list != null) + { + comboBoxBouquet.DisplayMember = "BouquetName"; + comboBoxBouquet.ValueMember = "Id"; + comboBoxBouquet.DataSource = list; + comboBoxBouquet.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquets for order"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void OrderForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CalculateSum() + { + if (comboBoxBouquet.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxBouquet.SelectedValue); + var furniture = _logicBouquet.ReadElement(new BouquetSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + + textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString(); + + _logger.LogInformation("Calculating order's sum"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during calculating order's sum"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalculateSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxBouquet.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicOrder.CreateOrder(new OrderBindingModel + { + BouquetId = Convert.ToInt32(comboBoxBouquet.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + + if (!operationResult) + { + throw new Exception("Error during order creation"); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during order creation"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormCreateOrder.resx b/FlowerShop/FlowerShop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs new file mode 100644 index 0000000..f962aca --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -0,0 +1,184 @@ +namespace FlowerShop +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.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(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(891, 99); + this.buttonReady.Margin = new System.Windows.Forms.Padding(2); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(150, 30); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ готов"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(6, 31); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(859, 359); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(891, 31); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(2); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(150, 30); + 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(891, 65); + this.buttonToWork.Margin = new System.Windows.Forms.Padding(2); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(150, 30); + 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(891, 133); + this.buttonPut.Margin = new System.Windows.Forms.Padding(2); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(150, 30); + 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(891, 167); + this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(150, 30); + 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.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); + this.menuStrip.Size = new System.Drawing.Size(1071, 24); + 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(94, 22); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изделияToolStripMenuItem.Text = "Букеты"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1071, 401); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + 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.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormMain"; + this.Text = "Цветочный магазин"; + this.Load += new System.EventHandler(this.MainForm_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; + private Button buttonReady; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs new file mode 100644 index 0000000..b175c4a --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -0,0 +1,184 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + 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 MainForm_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["BouquetId"].Visible = false; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving orders"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void bouquetsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquets)); + + if (service is FormBouquets 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("Order №{id}. Changing status to 'Processing'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Processing'"); + MessageBox.Show("Заказ должен быть в состоянии 'Принят'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Processing'"); + 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("Order №{id}. Changing status to 'Ready'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Ready'"); + MessageBox.Show("Заказ должен быть в состоянии 'В работе'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Ready'"); + 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("Order №{id}. Changing status to 'Delivered'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { + Id = id, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Delivered'"); + MessageBox.Show("Заказ должен быть в состоянии 'Готов'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Delivered'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormMain.resx b/FlowerShop/FlowerShop/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Program.cs b/FlowerShop/FlowerShop/Program.cs index 4757509..d80bfe5 100644 --- a/FlowerShop/FlowerShop/Program.cs +++ b/FlowerShop/FlowerShop/Program.cs @@ -1,17 +1,50 @@ +using FlowerShopContracts.StoragesContracts; +using Microsoft.Extensions.DependencyInjection; +using FlowerShopListImplement.Implements; +using FlowerShopBusinessLogic.BusinessLogics; +using FlowerShopContracts.BusinessLogicsContracts; +using NLog.Extensions.Logging; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + namespace FlowerShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// 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(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs index 0f4c3fb..ada5b16 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs @@ -120,7 +120,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Букет с таким названием уже есть"); } } } diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs index d21bffe..4a72073 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -38,13 +38,13 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model); - if (model.Status != OrderStatus.Unknown) + if (model.Status != OrderStatus.Неизвестен) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Accepted; + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { @@ -59,17 +59,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Accepted) + if (model.Status != OrderStatus.Принят) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Processing; + model.Status = OrderStatus.Выполняется; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; @@ -78,17 +78,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Processing) + if (model.Status != OrderStatus.Выполняется) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Ready; + model.Status = OrderStatus.Готов; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; @@ -98,17 +98,18 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Ready) + if (model.Status != OrderStatus.Готов) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Delivered; + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; diff --git a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs index 76cfd77..025d6ca 100644 --- a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -9,7 +9,7 @@ namespace FlowerShopContracts.BindingModels public int BouquetId { get; set; } public int Count { get; set; } public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Unknown; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } } diff --git a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs index 397a029..5feb9e8 100644 --- a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs +++ b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -16,7 +16,7 @@ namespace FlowerShopContracts.ViewModels [DisplayName("Сумма")] public double Sum { get; set; } [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Unknown; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] diff --git a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs index a93420b..df31dea 100644 --- a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs +++ b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs @@ -2,10 +2,10 @@ { public enum OrderStatus { - Unknown = -1, - Accepted = 0, - Processing = 1, - Ready = 2, - Delivered = 3 + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 } } diff --git a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs index 90302d3..6c470bb 100644 --- a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -21,7 +21,7 @@ namespace FlowerShopListImplement.Implements foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(AttachBouquetName(order.GetViewModel)); } return result; @@ -40,7 +40,7 @@ namespace FlowerShopListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(AttachBouquetName(order.GetViewModel)); } } @@ -56,9 +56,9 @@ namespace FlowerShopListImplement.Implements foreach (var order in _source.Orders) { - if ((model.Id.HasValue && order.Id == model.Id)) + if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return AttachBouquetName(order.GetViewModel); } } @@ -84,7 +84,7 @@ namespace FlowerShopListImplement.Implements _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return AttachBouquetName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -94,7 +94,7 @@ namespace FlowerShopListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return AttachBouquetName(order.GetViewModel); } } @@ -109,11 +109,19 @@ namespace FlowerShopListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return AttachBouquetName(element.GetViewModel); } } return null; } + + private OrderViewModel AttachBouquetName(OrderViewModel model) + { + var bouquet = _source.Bouquets.Find(b => b.Id == model.BouquetId); + model.BouquetName = bouquet is null ? String.Empty : bouquet.BouquetName; + + return model; + } } } diff --git a/FlowerShop/FlowerShopListImplement/Models/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs index 55daa06..9bd45ed 100644 --- a/FlowerShop/FlowerShopListImplement/Models/Order.cs +++ b/FlowerShop/FlowerShopListImplement/Models/Order.cs @@ -41,12 +41,7 @@ namespace FlowerShopListImplement.Models return; } - Id = model.Id; - BouquetId = model.BouquetId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } -- 2.25.1 From 3155cd0b0d824b30116857f851cb6f010d0ff27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 27 Feb 2023 03:19:29 +0400 Subject: [PATCH 12/14] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=201.=20=D0=98=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FormMain.cs | 36 +++---------------- .../BusinessLogics/OrderLogic.cs | 11 +++--- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs index b175c4a..63f690d 100644 --- a/FlowerShop/FlowerShop/FormMain.cs +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -79,15 +79,7 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Processing'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { @@ -114,19 +106,11 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Ready'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { _logger.LogError("Error during changing order's status to 'Ready'"); - MessageBox.Show("Заказ должен быть в состоянии 'В работе'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заказ должен быть в состоянии 'Выполняется'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } @@ -147,16 +131,7 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Delivered'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new - OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { @@ -169,8 +144,7 @@ namespace FlowerShop catch (Exception ex) { _logger.LogError(ex, "Error during changing order's status to 'Delivered'"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs index 4a72073..9ef4477 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -59,7 +59,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Принят) + if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят) { _logger.LogWarning("Invalid order status"); return false; @@ -78,13 +78,14 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Выполняется) + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) { _logger.LogWarning("Invalid order status"); return false; } model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) { @@ -98,14 +99,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Готов) + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (order?.Status != OrderStatus.Готов) { _logger.LogWarning("Invalid order status"); return false; } model.Status = OrderStatus.Выдан; - model.DateImplement = DateTime.Now; + model.DateImplement = order.DateImplement; if (_orderStorage.Update(model) == null) { -- 2.25.1 From a023b4f508a7e1d5368b561c39f3d671c505d840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Mar 2023 17:44:08 +0400 Subject: [PATCH 13/14] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=E2=84=961:=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FormMain.Designer.cs | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs index f962aca..2af388e 100644 --- a/FlowerShop/FlowerShop/FormMain.Designer.cs +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -35,9 +35,9 @@ 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(); + this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); @@ -112,7 +112,7 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.guidesToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); @@ -122,26 +122,26 @@ // // справочники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(94, 22); - this.справочникиToolStripMenuItem.Text = "Справочники"; + this.guidesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.bouquetsToolStripMenuItem}); + this.guidesToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.guidesToolStripMenuItem.Size = new System.Drawing.Size(94, 22); + this.guidesToolStripMenuItem.Text = "Справочники"; // // компонентыToolStripMenuItem // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + this.componentsToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.componentsToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); // // изделияToolStripMenuItem // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.изделияToolStripMenuItem.Text = "Букеты"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); + this.bouquetsToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.bouquetsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.bouquetsToolStripMenuItem.Text = "Букеты"; + this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); // // FormMain // @@ -176,9 +176,9 @@ private Button buttonPut; private Button buttonRefresh; private MenuStrip menuStrip; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem guidesToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem bouquetsToolStripMenuItem; private Button buttonReady; } } \ No newline at end of file -- 2.25.1 From b64d65bb181a7636ba56ccf76d1983de05f24936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Mar 2023 18:01:13 +0400 Subject: [PATCH 14/14] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=E2=84=961:=20=D0=95=D1=89=D1=91=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FormMain.Designer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs index 2af388e..6a02953 100644 --- a/FlowerShop/FlowerShop/FormMain.Designer.cs +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -120,25 +120,25 @@ this.menuStrip.TabIndex = 6; this.menuStrip.Text = "menuStrip1"; // - // справочникиToolStripMenuItem + // guidesToolStripMenuItem // this.guidesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItem, this.bouquetsToolStripMenuItem}); - this.guidesToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.guidesToolStripMenuItem.Name = "guidesToolStripMenuItem"; this.guidesToolStripMenuItem.Size = new System.Drawing.Size(94, 22); this.guidesToolStripMenuItem.Text = "Справочники"; // - // компонентыToolStripMenuItem + // componentsToolStripMenuItem // - this.componentsToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentsToolStripMenuItem.Text = "Компоненты"; this.componentsToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); // - // изделияToolStripMenuItem + // bouquetsToolStripMenuItem // - this.bouquetsToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.bouquetsToolStripMenuItem.Name = "bouquetsToolStripMenuItem"; this.bouquetsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.bouquetsToolStripMenuItem.Text = "Букеты"; this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); -- 2.25.1