From 87d085de2f716eb73988d51428eea2e0d1598c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sun, 12 Feb 2023 12:21:10 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A1=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=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractAutoContracts.csproj | 13 ++++++++ .../BindingModels/ComponentBindingModel.cs | 16 ++++++++++ .../BindingModels/OrderBindingModel.cs | 21 +++++++++++++ .../BindingModels/ProductBindingModel.cs | 21 +++++++++++++ .../IComponentLogic.cs | 20 ++++++++++++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++++++++++++ .../BusinessLogicsContracts/IProductLogic.cs | 20 ++++++++++++ .../SearchModel/ComponentSearchModel.cs | 14 +++++++++ .../SearchModel/OrderSearchModel.cs | 14 +++++++++ .../SearchModel/ProductSearchModel.cs | 14 +++++++++ .../StoragesContracts/IComponentStorage.cs | 22 +++++++++++++ .../StoragesContracts/IOrderStorage.cs | 21 +++++++++++++ .../StoragesContracts/IProductStorage.cs | 22 +++++++++++++ .../ViewModel/ComponentViewModel.cs | 18 +++++++++++ .../ViewModel/OrderViewModel.cs | 31 +++++++++++++++++++ .../ViewModel/ProductViewModel.cs | 24 ++++++++++++++ .../AbstractAutoDataModels.csproj | 9 ++++++ .../Enums/OrderStatus.cs | 18 +++++++++++ AutomobilePlant/AbstractAutoDataModels/IId.cs | 13 ++++++++ .../Models/IComponentModel.cs | 14 +++++++++ .../Models/IOrderModel.cs | 19 ++++++++++++ .../Models/IProductModel.cs | 16 ++++++++++ AutomobilePlant/AutomobilePlant.sln | 12 +++++++ 23 files changed, 412 insertions(+) create mode 100644 AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj create mode 100644 AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs create mode 100644 AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj create mode 100644 AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs create mode 100644 AutomobilePlant/AbstractAutoDataModels/IId.cs create mode 100644 AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs create mode 100644 AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs create mode 100644 AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs diff --git a/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj b/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj new file mode 100644 index 0000000..81d9b57 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..6026680 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractAutoDataModels.Models; + +namespace AbstractAutoContracts.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/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..972ddc7 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractAutoDataModels.Enums; +using AbstractAutoDataModels.Models; + +namespace AbstractAutoContracts.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.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..b9b8775 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractAutoDataModels.Models; + +namespace AbstractAutoContracts.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(); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..7889ced --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..6d2e59d --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.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/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs new file mode 100644 index 0000000..d420044 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs @@ -0,0 +1,20 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.BusinessLogicsContracts +{ + public interface IProductLogic + { + List? ReadList(ProductSearchModel? model); + ProductViewModel? ReadElement(ProductSearchModel model); + bool Create(ProductBindingModel model); + bool Update(ProductBindingModel model); + bool Delete(ProductBindingModel model); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs new file mode 100644 index 0000000..9ffed3e --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.SearchModel +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs new file mode 100644 index 0000000..187982f --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.SearchModel +{ + public class OrderSearchModel + { + public int? Id { get; set; } + + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs new file mode 100644 index 0000000..7470ad4 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.SearchModel +{ + public class ProductSearchModel + { + public int? Id { get; set; } + public string? ProductName { get; set; } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..9cdbd2a --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..509c8a0 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.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/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs new file mode 100644 index 0000000..fc380f5 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs @@ -0,0 +1,22 @@ +using AbstractAutoContracts.BindingModels; +using AbstractAutoContracts.SearchModel; +using AbstractAutoContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoContracts.StoragesContracts +{ + public interface IProductStorage + { + List GetFullList(); + List GetFilteredList(ProductSearchModel model); + ProductViewModel? GetElement(ProductSearchModel model); + ProductViewModel? Insert(ProductBindingModel model); + ProductViewModel? Update(ProductBindingModel model); + ProductViewModel? Delete(ProductBindingModel model); + + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs new file mode 100644 index 0000000..2f1db18 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs @@ -0,0 +1,18 @@ +using AbstractAutoDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +namespace AbstractAutoContracts.ViewModel +{ + 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/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs new file mode 100644 index 0000000..8d8fdfb --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs @@ -0,0 +1,31 @@ +using AbstractAutoDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using AbstractAutoDataModels.Enums; + +namespace AbstractAutoContracts.ViewModel +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ProductId { get; set; } + [DisplayName("Изделие")] + public string ProductName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs new file mode 100644 index 0000000..74f846e --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs @@ -0,0 +1,24 @@ +using AbstractAutoDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +namespace AbstractAutoContracts.ViewModel +{ + public class ProductViewModel : IProductModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ProductName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ProductComponents + { + get; + set; + } = new(); + + } +} diff --git a/AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj b/AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..7a041e7 --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + + } +} diff --git a/AutomobilePlant/AbstractAutoDataModels/IId.cs b/AutomobilePlant/AbstractAutoDataModels/IId.cs new file mode 100644 index 0000000..d871603 --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..50c14e0 --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..8902035 --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using AbstractAutoDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoDataModels.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/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs new file mode 100644 index 0000000..2875b48 --- /dev/null +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractAutoDataModels.Models +{ + public interface IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + + } +} diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index 99fde6c..f7bdc84 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoDataModels", "AbstractAutoDataModels\AbstractAutoDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoContracts", "AbstractAutoContracts\AbstractAutoContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +19,14 @@ Global {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.Build.0 = Release|Any CPU + {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Release|Any CPU.Build.0 = Release|Any CPU + {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From d81b8cb9878d51838db7d7b158d2bddcdea2ab0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sun, 12 Feb 2023 16:08:29 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D0=B8=20=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlantBusinessLogic.csproj | 17 +++ .../BusinessLogics/ComponentLogic.cs | 114 +++++++++++++++ .../BusinessLogics/OrderLogic.cs | 132 ++++++++++++++++++ .../BusinessLogics/ProductLogic.cs | 113 +++++++++++++++ ...csproj => AutomobilePlantContracts.csproj} | 2 +- .../BindingModels/ComponentBindingModel.cs | 4 +- .../BindingModels/OrderBindingModel.cs | 7 +- .../BindingModels/ProductBindingModel.cs | 4 +- .../IComponentLogic.cs | 8 +- .../BusinessLogicsContracts/IOrderLogic.cs | 8 +- .../BusinessLogicsContracts/IProductLogic.cs | 8 +- .../SearchModel/ComponentSearchModel.cs | 2 +- .../SearchModel/OrderSearchModel.cs | 2 +- .../SearchModel/ProductSearchModel.cs | 2 +- .../StoragesContracts/IComponentStorage.cs | 8 +- .../StoragesContracts/IOrderStorage.cs | 8 +- .../StoragesContracts/IProductStorage.cs | 8 +- .../ViewModel/ComponentViewModel.cs | 4 +- .../ViewModel/OrderViewModel.cs | 6 +- .../ViewModel/ProductViewModel.cs | 4 +- ...sproj => AutomobilePlantDataModels.csproj} | 0 .../Enums/OrderStatus.cs | 2 +- AutomobilePlant/AbstractAutoDataModels/IId.cs | 2 +- .../Models/IComponentModel.cs | 2 +- .../Models/IOrderModel.cs | 5 +- .../Models/IProductModel.cs | 2 +- .../AutomobilePlantListImplement.csproj | 14 ++ .../DataListSingleton.cs | 31 ++++ .../Implements/ComponentStorage.cs | 108 ++++++++++++++ .../Implements/OrderStorage.cs | 124 ++++++++++++++++ .../Implements/ProductStorage.cs | 126 +++++++++++++++++ .../Models/Component.cs | 46 ++++++ .../AbstractAutoListImplement/Models/Order.cs | 70 ++++++++++ .../Models/Product.cs | 55 ++++++++ AutomobilePlant/AutomobilePlant.sln | 16 ++- 35 files changed, 1014 insertions(+), 50 deletions(-) create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs rename AutomobilePlant/AbstractAutoContracts/{AbstractAutoContracts.csproj => AutomobilePlantContracts.csproj} (71%) rename AutomobilePlant/AbstractAutoDataModels/{AbstractAutoDataModels.csproj => AutomobilePlantDataModels.csproj} (100%) create mode 100644 AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj create mode 100644 AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Models/Component.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Models/Order.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Models/Product.cs diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj new file mode 100644 index 0000000..37dc43e --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..134b061 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,114 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantBusinessLogic.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/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..e0d5a04 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,132 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.Id < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.Id)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.Id); + } + } +} diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs new file mode 100644 index 0000000..29fc773 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs @@ -0,0 +1,113 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ProductLogic : IProductLogic + { + private readonly ILogger _logger; + private readonly IProductStorage _productStorage; + public ProductLogic(ILogger logger, IProductStorage productStorage) + { + _logger = logger; + _productStorage = productStorage; + } + public List? ReadList(ProductSearchModel? model) + { + _logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id); + var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ProductViewModel? ReadElement(ProductSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProductName:{ProductName}. Id:{ Id}", model.ProductName, model.Id); + var element = _productStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProductBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_productStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProductBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProductName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.ProductName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Product. ProductName:{ProductName}.Cost:{ Cost}. Id: { Id}", model.ProductName, model.Price, model.Id); + var element = _productStorage.GetElement(new ProductSearchModel + { + ProductName = model.ProductName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj similarity index 71% rename from AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj rename to AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj index 81d9b57..940430a 100644 --- a/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj +++ b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj @@ -7,7 +7,7 @@ - + diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs index 6026680..3c76c66 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class ComponentBindingModel : IComponentModel { diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs index 972ddc7..1b7d314 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs @@ -3,15 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Enums; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class OrderBindingModel : IOrderModel { public int Id { get; set; } public int ProductId { get; set; } + public string ProductName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs index b9b8775..b0d0949 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class ProductBindingModel : IProductModel { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs index 7889ced..887da15 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IComponentLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs index 6d2e59d..60238ac 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IOrderLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs index d420044..8e3cfd8 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IProductLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs index 9ffed3e..203914a 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class ComponentSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs index 187982f..de416ba 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class OrderSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs index 7470ad4..5ca3dbe 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class ProductSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs index 9cdbd2a..24f1fec 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IComponentStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs index 509c8a0..344332f 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IOrderStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs index fc380f5..08c58e0 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IProductStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs index 2f1db18..efaeb1b 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs @@ -1,11 +1,11 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class ComponentViewModel : IComponentModel { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs index 8d8fdfb..98cd8cc 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs @@ -1,13 +1,13 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -using AbstractAutoDataModels.Enums; +using AutomobilePlantDataModels.Enums; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class OrderViewModel : IOrderModel { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs index 74f846e..642b457 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs @@ -1,11 +1,11 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class ProductViewModel : IProductModel { diff --git a/AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj b/AutomobilePlant/AbstractAutoDataModels/AutomobilePlantDataModels.csproj similarity index 100% rename from AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj rename to AutomobilePlant/AbstractAutoDataModels/AutomobilePlantDataModels.csproj diff --git a/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs index 7a041e7..f560e42 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Enums +namespace AutomobilePlantDataModels.Enums { public enum OrderStatus { diff --git a/AutomobilePlant/AbstractAutoDataModels/IId.cs b/AutomobilePlant/AbstractAutoDataModels/IId.cs index d871603..1dd266c 100644 --- a/AutomobilePlant/AbstractAutoDataModels/IId.cs +++ b/AutomobilePlant/AbstractAutoDataModels/IId.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels +namespace AutomobilePlantDataModels { public interface IId { diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs index 50c14e0..65039ce 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IComponentModel : IId { diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs index 8902035..b60da02 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs @@ -1,15 +1,16 @@ -using AbstractAutoDataModels.Enums; +using AutomobilePlantDataModels.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IOrderModel : IId { int ProductId { get; } + string ProductName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs index 2875b48..a061105 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IProductModel : IId { diff --git a/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj new file mode 100644 index 0000000..43870e5 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b50c69 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e895b67 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.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/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d285c75 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs @@ -0,0 +1,124 @@ +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.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.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && 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; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..b748f67 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs @@ -0,0 +1,126 @@ +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class ProductStorage : IProductStorage + { + private readonly DataListSingleton _source; + + public ProductStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var product in _source.Products) + { + result.Add(product.GetViewModel); + } + + return result; + } + + public List GetFilteredList(ProductSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ProductName)) + { + return result; + } + + foreach (var product in _source.Products) + { + if (product.ProductName.Contains(model.ProductName)) + { + result.Add(product.GetViewModel); + } + } + + return result; + } + + public ProductViewModel? GetElement(ProductSearchModel model) + { + if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) + { + return null; + } + + foreach (var product in _source.Products) + { + if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) + { + return product.GetViewModel; + } + } + + return null; + } + + public ProductViewModel? Insert(ProductBindingModel model) + { + model.Id = 1; + + foreach (var product in _source.Products) + { + if (model.Id <= product.Id) + { + model.Id = product.Id + 1; + } + } + + var newProduct = Product.Create(model); + + if (newProduct == null) + { + return null; + } + + _source.Products.Add(newProduct); + + return newProduct.GetViewModel; + } + + public ProductViewModel? Update(ProductBindingModel model) + { + foreach (var product in _source.Products) + { + if (product.Id == model.Id) + { + product.Update(model); + return product.GetViewModel; + } + } + + return null; + } + + public ProductViewModel? Delete(ProductBindingModel model) + { + for (int i = 0; i < _source.Products.Count; ++i) + { + if (_source.Products[i].Id == model.Id) + { + var element = _source.Products[i]; + _source.Products.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs new file mode 100644 index 0000000..c194758 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.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/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs new file mode 100644 index 0000000..d4649ed --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ProductId { get; private set; } + public string ProductName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ProductId = model.ProductId, + ProductName = model.ProductName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + ProductId = model.ProductId; + ProductName = model.ProductName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + ProductId = ProductId, + ProductName = ProductName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs new file mode 100644 index 0000000..06c9cde --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs @@ -0,0 +1,55 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Product : IProductModel + { + public int Id { get; private set; } + public string ProductName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ProductComponents + { + get; + private set; + } = new Dictionary(); + public static Product? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Product() + { + Id = model.Id, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + + } +} diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index f7bdc84..1642a09 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -5,9 +5,13 @@ VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoDataModels", "AbstractAutoDataModels\AbstractAutoDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AbstractAutoDataModels\AutomobilePlantDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoContracts", "AbstractAutoContracts\AbstractAutoContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +31,14 @@ Global {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.Build.0 = Release|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.25.1 From f27ce6cc8e925cb32ed27c4cdd57e35766b282c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Wed, 19 Apr 2023 15:41:28 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlantBusinessLogic.csproj | 3 +- .../{ProductLogic.cs => CarLogic.cs} | 44 +-- .../BusinessLogics/OrderLogic.cs | 4 +- ...ductBindingModel.cs => CarBindingModel.cs} | 6 +- .../BindingModels/OrderBindingModel.cs | 4 +- .../{IProductLogic.cs => ICarLogic.cs} | 12 +- ...roductSearchModel.cs => CarSearchModel.cs} | 4 +- .../StoragesContracts/ICarStorage.cs | 22 ++ .../StoragesContracts/IProductStorage.cs | 22 -- .../{ProductViewModel.cs => CarViewModel.cs} | 6 +- .../ViewModel/OrderViewModel.cs | 4 +- .../Models/{IProductModel.cs => ICarModel.cs} | 6 +- .../Models/IOrderModel.cs | 4 +- .../DataListSingleton.cs | 4 +- .../Implements/CarStorage.cs | 126 +++++++++ .../Implements/ProductStorage.cs | 126 --------- .../Models/{Product.cs => Car.cs} | 26 +- .../AbstractAutoListImplement/Models/Order.cs | 17 +- AutomobilePlant/AutomobilePlant.sln | 12 +- AutomobilePlant/AutomobilePlant/App.config | 6 - .../AutomobilePlant/AutomobilePlant.csproj | 88 ++---- .../AutomobilePlant/Form1.Designer.cs | 40 --- AutomobilePlant/AutomobilePlant/Form1.cs | 20 -- .../AutomobilePlant/FormCar.Designer.cs | 252 ++++++++++++++++++ AutomobilePlant/AutomobilePlant/FormCar.cs | 223 ++++++++++++++++ .../Resources.resx => FormCar.resx} | 13 +- .../FormCarComponent.Designer.cs | 124 +++++++++ .../AutomobilePlant/FormCarComponent.cs | 91 +++++++ .../AutomobilePlant/FormCarComponent.resx | 120 +++++++++ .../AutomobilePlant/FormCars.Designer.cs | 121 +++++++++ AutomobilePlant/AutomobilePlant/FormCars.cs | 120 +++++++++ AutomobilePlant/AutomobilePlant/FormCars.resx | 60 +++++ .../AutomobilePlant/FormComponent.Designer.cs | 123 +++++++++ .../AutomobilePlant/FormComponent.cs | 92 +++++++ .../AutomobilePlant/FormComponent.resx | 120 +++++++++ .../FormComponents.Designer.cs | 121 +++++++++ .../AutomobilePlant/FormComponents.cs | 117 ++++++++ .../AutomobilePlant/FormComponents.resx | 60 +++++ .../FormCreateOrder.Designer.cs | 149 +++++++++++ .../AutomobilePlant/FormCreateOrder.cs | 143 ++++++++++ .../AutomobilePlant/FormCreateOrder.resx | 120 +++++++++ .../AutomobilePlant/FormMain.Designer.cs | 184 +++++++++++++ AutomobilePlant/AutomobilePlant/FormMain.cs | 200 ++++++++++++++ AutomobilePlant/AutomobilePlant/FormMain.resx | 63 +++++ AutomobilePlant/AutomobilePlant/Program.cs | 51 +++- .../Properties/AssemblyInfo.cs | 36 --- .../Properties/Resources.Designer.cs | 71 ----- .../Properties/Settings.Designer.cs | 30 --- .../Properties/Settings.settings | 7 - AutomobilePlant/AutomobilePlant/nlog.config | 15 ++ 50 files changed, 2909 insertions(+), 523 deletions(-) rename AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/{ProductLogic.cs => CarLogic.cs} (62%) rename AutomobilePlant/AbstractAutoContracts/BindingModels/{ProductBindingModel.cs => CarBindingModel.cs} (65%) rename AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/{IProductLogic.cs => ICarLogic.cs} (51%) rename AutomobilePlant/AbstractAutoContracts/SearchModel/{ProductSearchModel.cs => CarSearchModel.cs} (72%) create mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarStorage.cs delete mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs rename AutomobilePlant/AbstractAutoContracts/ViewModel/{ProductViewModel.cs => CarViewModel.cs} (72%) rename AutomobilePlant/AbstractAutoDataModels/Models/{IProductModel.cs => ICarModel.cs} (58%) create mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/CarStorage.cs delete mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs rename AutomobilePlant/AbstractAutoListImplement/Models/{Product.cs => Car.cs} (57%) delete mode 100644 AutomobilePlant/AutomobilePlant/App.config delete mode 100644 AutomobilePlant/AutomobilePlant/Form1.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Form1.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCar.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCar.cs rename AutomobilePlant/AutomobilePlant/{Properties/Resources.resx => FormCar.resx} (90%) create mode 100644 AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCarComponent.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCarComponent.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormCars.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCars.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCars.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponent.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponents.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormComponents.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCreateOrder.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormCreateOrder.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormMain.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormMain.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormMain.resx delete mode 100644 AutomobilePlant/AutomobilePlant/Properties/AssemblyInfo.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Properties/Resources.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Properties/Settings.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlant/Properties/Settings.settings create mode 100644 AutomobilePlant/AutomobilePlant/nlog.config diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj index 37dc43e..8bad4dd 100644 --- a/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj +++ b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj @@ -5,8 +5,7 @@ enable enable - - + diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/CarLogic.cs similarity index 62% rename from AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs rename to AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/CarLogic.cs index 29fc773..24cf454 100644 --- a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/CarLogic.cs @@ -12,19 +12,19 @@ using System.Threading.Tasks; namespace AutomobilePlantBusinessLogic.BusinessLogics { - public class ProductLogic : IProductLogic + public class CarLogic : ICarLogic { private readonly ILogger _logger; - private readonly IProductStorage _productStorage; - public ProductLogic(ILogger logger, IProductStorage productStorage) + private readonly ICarStorage _carStorage; + public CarLogic(ILogger logger, ICarStorage carStorage) { _logger = logger; - _productStorage = productStorage; + _carStorage = carStorage; } - public List? ReadList(ProductSearchModel? model) + public List? ReadList(CarSearchModel? model) { - _logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id); - var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + _logger.LogInformation("ReadList. CarName:{CarName}.Id:{ Id}", model?.CarName, model?.Id); + var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -33,14 +33,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public ProductViewModel? ReadElement(ProductSearchModel model) + public CarViewModel? ReadElement(CarSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ProductName:{ProductName}. Id:{ Id}", model.ProductName, model.Id); - var element = _productStorage.GetElement(model); + _logger.LogInformation("ReadElement. CarName:{CarName}. Id:{ Id}", model.CarName, model.Id); + var element = _carStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -49,38 +49,38 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - public bool Create(ProductBindingModel model) + public bool Create(CarBindingModel model) { CheckModel(model); - if (_productStorage.Insert(model) == null) + if (_carStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } return true; } - public bool Update(ProductBindingModel model) + public bool Update(CarBindingModel model) { CheckModel(model); - if (_productStorage.Update(model) == null) + if (_carStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; } return true; } - public bool Delete(ProductBindingModel model) + public bool Delete(CarBindingModel model) { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_productStorage.Delete(model) == null) + if (_carStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; } return true; } - private void CheckModel(ProductBindingModel model, bool withParams = + private void CheckModel(CarBindingModel model, bool withParams = true) { if (model == null) @@ -91,18 +91,18 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics { return; } - if (string.IsNullOrEmpty(model.ProductName)) + if (string.IsNullOrEmpty(model.CarName)) { - throw new ArgumentNullException("Нет названия изделия", nameof(model.ProductName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.CarName)); } if (model.Price <= 0) { throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Product. ProductName:{ProductName}.Cost:{ Cost}. Id: { Id}", model.ProductName, model.Price, model.Id); - var element = _productStorage.GetElement(new ProductSearchModel + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.CarName, model.Price, model.Id); + var element = _carStorage.GetElement(new CarSearchModel { - ProductName = model.ProductName + CarName = model.CarName }); if (element != null && element.Id != model.Id) { diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs index e0d5a04..5a5ac5c 100644 --- a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs @@ -72,12 +72,12 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - return StatusUpdate(model, OrderStatus.Готов); + return StatusUpdate(model, OrderStatus.Выдан); } public bool FinishOrder(OrderBindingModel model) { - return StatusUpdate(model, OrderStatus.Выдан); + return StatusUpdate(model, OrderStatus.Готов); } public bool TakeOrderInWork(OrderBindingModel model) diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/CarBindingModel.cs similarity index 65% rename from AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs rename to AutomobilePlant/AbstractAutoContracts/BindingModels/CarBindingModel.cs index b0d0949..3216c44 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/CarBindingModel.cs @@ -7,12 +7,12 @@ using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.BindingModels { - public class ProductBindingModel : IProductModel + public class CarBindingModel : ICarModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string CarName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary CarComponents { get; set; diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs index 1b7d314..00bad8b 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs @@ -11,8 +11,8 @@ namespace AutomobilePlantContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } - public string ProductName { get; set; } = string.Empty; + public int CarId { get; set; } + public string CarName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/ICarLogic.cs similarity index 51% rename from AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs rename to AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/ICarLogic.cs index 8e3cfd8..2a636cb 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/ICarLogic.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; namespace AutomobilePlantContracts.BusinessLogicsContracts { - public interface IProductLogic + public interface ICarLogic { - List? ReadList(ProductSearchModel? model); - ProductViewModel? ReadElement(ProductSearchModel model); - bool Create(ProductBindingModel model); - bool Update(ProductBindingModel model); - bool Delete(ProductBindingModel model); + List? ReadList(CarSearchModel? model); + CarViewModel? ReadElement(CarSearchModel model); + bool Create(CarBindingModel model); + bool Update(CarBindingModel model); + bool Delete(CarBindingModel model); } } diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/CarSearchModel.cs similarity index 72% rename from AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs rename to AutomobilePlant/AbstractAutoContracts/SearchModel/CarSearchModel.cs index 5ca3dbe..e5f22c8 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/CarSearchModel.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace AutomobilePlantContracts.SearchModel { - public class ProductSearchModel + public class CarSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? CarName { get; set; } } } diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarStorage.cs new file mode 100644 index 0000000..013f2c2 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarStorage.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface ICarStorage + { + List GetFullList(); + List GetFilteredList(CarSearchModel model); + CarViewModel? GetElement(CarSearchModel model); + CarViewModel? Insert(CarBindingModel model); + CarViewModel? Update(CarBindingModel model); + CarViewModel? Delete(CarBindingModel model); + + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs deleted file mode 100644 index 08c58e0..0000000 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AutomobilePlantContracts.BindingModels; -using AutomobilePlantContracts.SearchModel; -using AutomobilePlantContracts.ViewModel; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AutomobilePlantContracts.StoragesContracts -{ - public interface IProductStorage - { - List GetFullList(); - List GetFilteredList(ProductSearchModel model); - ProductViewModel? GetElement(ProductSearchModel model); - ProductViewModel? Insert(ProductBindingModel model); - ProductViewModel? Update(ProductBindingModel model); - ProductViewModel? Delete(ProductBindingModel model); - - } -} diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs similarity index 72% rename from AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs rename to AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs index 642b457..dfd9bb0 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs @@ -7,14 +7,14 @@ using System.Threading.Tasks; using System.ComponentModel; namespace AutomobilePlantContracts.ViewModel { - public class ProductViewModel : IProductModel + public class CarViewModel : ICarModel { public int Id { get; set; } [DisplayName("Название изделия")] - public string ProductName { get; set; } = string.Empty; + public string CarName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary CarComponents { get; set; diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs index 98cd8cc..70368cc 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs @@ -13,9 +13,9 @@ namespace AutomobilePlantContracts.ViewModel { [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int CarId { get; set; } [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public string CarName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/ICarModel.cs similarity index 58% rename from AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs rename to AutomobilePlant/AbstractAutoDataModels/Models/ICarModel.cs index a061105..f74680a 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/ICarModel.cs @@ -6,11 +6,11 @@ using System.Threading.Tasks; namespace AutomobilePlantDataModels.Models { - public interface IProductModel : IId + public interface ICarModel : IId { - string ProductName { get; } + string CarName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary CarComponents { get; } } } diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs index b60da02..851b552 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs @@ -9,8 +9,8 @@ namespace AutomobilePlantDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } - string ProductName { get; } + int CarId { get; } + string CarName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs index 1b50c69..0d84092 100644 --- a/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs +++ b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs @@ -12,12 +12,12 @@ namespace AutomobilePlantListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Cars { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Cars = new List(); } public static DataListSingleton GetInstance() { diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/CarStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/CarStorage.cs new file mode 100644 index 0000000..0689ae1 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/CarStorage.cs @@ -0,0 +1,126 @@ +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class CarStorage : ICarStorage + { + private readonly DataListSingleton _source; + + public CarStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var car in _source.Cars) + { + result.Add(car.GetViewModel); + } + + return result; + } + + public List GetFilteredList(CarSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.CarName)) + { + return result; + } + + foreach (var car in _source.Cars) + { + if (car.CarName.Contains(model.CarName)) + { + result.Add(car.GetViewModel); + } + } + + return result; + } + + public CarViewModel? GetElement(CarSearchModel model) + { + if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue) + { + return null; + } + + foreach (var car in _source.Cars) + { + if ((!string.IsNullOrEmpty(model.CarName) && car.CarName == model.CarName) || (model.Id.HasValue && car.Id == model.Id)) + { + return car.GetViewModel; + } + } + + return null; + } + + public CarViewModel? Insert(CarBindingModel model) + { + model.Id = 1; + + foreach (var car in _source.Cars) + { + if (model.Id <= car.Id) + { + model.Id = car.Id + 1; + } + } + + var newCar = Car.Create(model); + + if (newCar == null) + { + return null; + } + + _source.Cars.Add(newCar); + + return newCar.GetViewModel; + } + + public CarViewModel? Update(CarBindingModel model) + { + foreach (var car in _source.Cars) + { + if (car.Id == model.Id) + { + car.Update(model); + return car.GetViewModel; + } + } + + return null; + } + + public CarViewModel? Delete(CarBindingModel model) + { + for (int i = 0; i < _source.Cars.Count; ++i) + { + if (_source.Cars[i].Id == model.Id) + { + var element = _source.Cars[i]; + _source.Cars.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs deleted file mode 100644 index b748f67..0000000 --- a/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs +++ /dev/null @@ -1,126 +0,0 @@ -using AutomobilePlantContracts.StoragesContracts; -using AutomobilePlantContracts.ViewModel; -using AutomobilePlantContracts.BindingModels; -using AutomobilePlantContracts.SearchModel; -using AutomobilePlantListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AutomobilePlantListImplement.Implements -{ - public class ProductStorage : IProductStorage - { - private readonly DataListSingleton _source; - - public ProductStorage() - { - _source = DataListSingleton.GetInstance(); - } - - public List GetFullList() - { - var result = new List(); - - foreach (var product in _source.Products) - { - result.Add(product.GetViewModel); - } - - return result; - } - - public List GetFilteredList(ProductSearchModel model) - { - var result = new List(); - - if (string.IsNullOrEmpty(model.ProductName)) - { - return result; - } - - foreach (var product in _source.Products) - { - if (product.ProductName.Contains(model.ProductName)) - { - result.Add(product.GetViewModel); - } - } - - return result; - } - - public ProductViewModel? GetElement(ProductSearchModel model) - { - if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) - { - return null; - } - - foreach (var product in _source.Products) - { - if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) - { - return product.GetViewModel; - } - } - - return null; - } - - public ProductViewModel? Insert(ProductBindingModel model) - { - model.Id = 1; - - foreach (var product in _source.Products) - { - if (model.Id <= product.Id) - { - model.Id = product.Id + 1; - } - } - - var newProduct = Product.Create(model); - - if (newProduct == null) - { - return null; - } - - _source.Products.Add(newProduct); - - return newProduct.GetViewModel; - } - - public ProductViewModel? Update(ProductBindingModel model) - { - foreach (var product in _source.Products) - { - if (product.Id == model.Id) - { - product.Update(model); - return product.GetViewModel; - } - } - - return null; - } - - public ProductViewModel? Delete(ProductBindingModel model) - { - for (int i = 0; i < _source.Products.Count; ++i) - { - if (_source.Products[i].Id == model.Id) - { - var element = _source.Products[i]; - _source.Products.RemoveAt(i); - return element.GetViewModel; - } - } - - return null; - } - } -} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Car.cs similarity index 57% rename from AutomobilePlant/AbstractAutoListImplement/Models/Product.cs rename to AutomobilePlant/AbstractAutoListImplement/Models/Car.cs index 06c9cde..4c312f6 100644 --- a/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Car.cs @@ -9,46 +9,46 @@ using System.Threading.Tasks; namespace AutomobilePlantListImplement.Models { - public class Product : IProductModel + public class Car : ICarModel { public int Id { get; private set; } - public string ProductName { get; private set; } = string.Empty; + public string CarName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary ProductComponents + public Dictionary CarComponents { get; private set; } = new Dictionary(); - public static Product? Create(ProductBindingModel? model) + public static Car? Create(CarBindingModel? model) { if (model == null) { return null; } - return new Product() + return new Car() { Id = model.Id, - ProductName = model.ProductName, + CarName = model.CarName, Price = model.Price, - ProductComponents = model.ProductComponents + CarComponents = model.CarComponents }; } - public void Update(ProductBindingModel? model) + public void Update(CarBindingModel? model) { if (model == null) { return; } - ProductName = model.ProductName; + CarName = model.CarName; Price = model.Price; - ProductComponents = model.ProductComponents; + CarComponents = model.CarComponents; } - public ProductViewModel GetViewModel => new() + public CarViewModel GetViewModel => new() { Id = Id, - ProductName = ProductName, + CarName = CarName, Price = Price, - ProductComponents = ProductComponents + CarComponents = CarComponents }; } diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs index d4649ed..5c17d17 100644 --- a/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs @@ -13,8 +13,8 @@ namespace AutomobilePlantListImplement.Models public class Order : IOrderModel { public int Id { get; private set; } - public int ProductId { get; private set; } - public string ProductName { get; private set; } + public int CarId { get; private set; } + public string CarName { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -30,8 +30,8 @@ namespace AutomobilePlantListImplement.Models return new Order() { Id = model.Id, - ProductId = model.ProductId, - ProductName = model.ProductName, + CarId = model.CarId, + CarName = model.CarName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -46,20 +46,15 @@ namespace AutomobilePlantListImplement.Models { return; } - ProductId = model.ProductId; - ProductName = model.ProductName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, - ProductId = ProductId, - ProductName = ProductName, + CarId = CarId, + CarName = CarName, Count = Count, Sum = Sum, Status = Status, diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index 1642a09..e1f3e29 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -3,8 +3,6 @@ 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}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AbstractAutoDataModels\AutomobilePlantDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" @@ -13,16 +11,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2A499DE6-B7DE-4A28-9906-12FC100451F0}.Release|Any CPU.Build.0 = Release|Any CPU {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD7B0E1A-2EE9-441A-87C3-03AC0421746E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -39,6 +35,10 @@ Global {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.Build.0 = Release|Any CPU + {8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DB13E4F-D083-40DD-B1C2-F3CF74B762C2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AutomobilePlant/AutomobilePlant/App.config b/AutomobilePlant/AutomobilePlant/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/AutomobilePlant/AutomobilePlant/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj index 90cafcf..b9586a3 100644 --- a/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj +++ b/AutomobilePlant/AutomobilePlant/AutomobilePlant.csproj @@ -1,80 +1,30 @@ - - - + + - Debug - AnyCPU - {2A499DE6-B7DE-4A28-9906-12FC100451F0} WinExe - AutomobilePlant - AutomobilePlant - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + net6.0-windows + enable + true + enable + - - - - - - - - - - - + + - - Form - - - Form1.cs - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer + + Always - - True - Resources.resx - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - + - + - + + + + + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/Form1.Designer.cs b/AutomobilePlant/AutomobilePlant/Form1.Designer.cs deleted file mode 100644 index 599ef6f..0000000 --- a/AutomobilePlant/AutomobilePlant/Form1.Designer.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace AutomobilePlant -{ - partial class Form1 - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором форм Windows - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - 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 - } -} - diff --git a/AutomobilePlant/AutomobilePlant/Form1.cs b/AutomobilePlant/AutomobilePlant/Form1.cs deleted file mode 100644 index 8e7dda6..0000000 --- a/AutomobilePlant/AutomobilePlant/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace AutomobilePlant -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs b/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs new file mode 100644 index 0000000..712b213 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs @@ -0,0 +1,252 @@ +namespace AutomobilePlant +{ + partial class FormCar + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + this.CarNameLabel = new System.Windows.Forms.Label(); + this.PriceLabel = new System.Windows.Forms.Label(); + this.CarNameTextBox = new System.Windows.Forms.TextBox(); + this.PriceTextBox = new System.Windows.Forms.TextBox(); + this.ComponentsGroupBox = new System.Windows.Forms.GroupBox(); + this.UpdateButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.AddButton = new System.Windows.Forms.Button(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ComponentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // CarNameLabel + // + this.CarNameLabel.AutoSize = true; + this.CarNameLabel.Location = new System.Drawing.Point(12, 9); + this.CarNameLabel.Name = "PackageNameLabel"; + this.CarNameLabel.Size = new System.Drawing.Size(65, 15); + this.CarNameLabel.TabIndex = 0; + this.CarNameLabel.Text = "Название: "; + // + // PriceLabel + // + this.PriceLabel.AutoSize = true; + this.PriceLabel.Location = new System.Drawing.Point(12, 43); + this.PriceLabel.Name = "PriceLabel"; + this.PriceLabel.Size = new System.Drawing.Size(73, 15); + this.PriceLabel.TabIndex = 1; + this.PriceLabel.Text = "Стоимость: "; + // + // CarNameTextBox + // + this.CarNameTextBox.Location = new System.Drawing.Point(83, 6); + this.CarNameTextBox.Name = "PackageNameTextBox"; + this.CarNameTextBox.Size = new System.Drawing.Size(283, 23); + this.CarNameTextBox.TabIndex = 2; + // + // PriceTextBox + // + this.PriceTextBox.Location = new System.Drawing.Point(83, 40); + this.PriceTextBox.Name = "PriceTextBox"; + this.PriceTextBox.Size = new System.Drawing.Size(283, 23); + this.PriceTextBox.TabIndex = 3; + // + // ComponentsGroupBox + // + this.ComponentsGroupBox.Controls.Add(this.UpdateButton); + this.ComponentsGroupBox.Controls.Add(this.DeleteButton); + this.ComponentsGroupBox.Controls.Add(this.ChangeButton); + this.ComponentsGroupBox.Controls.Add(this.AddButton); + this.ComponentsGroupBox.Controls.Add(this.DataGridView); + this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 80); + this.ComponentsGroupBox.Name = "ComponentsGroupBox"; + this.ComponentsGroupBox.Size = new System.Drawing.Size(722, 350); + this.ComponentsGroupBox.TabIndex = 5; + this.ComponentsGroupBox.TabStop = false; + this.ComponentsGroupBox.Text = "Компоненты"; + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(590, 203); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(110, 38); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(590, 143); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(110, 38); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(590, 82); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(110, 38); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(590, 22); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(110, 38); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // DataGridView + // + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ComponentNameField, + this.CountField}); + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2; + this.DataGridView.Location = new System.Drawing.Point(6, 22); + this.DataGridView.Name = "DataGridView"; + dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(561, 322); + this.DataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // ComponentNameField + // + this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComponentNameField.HeaderText = "Компонент"; + this.ComponentNameField.Name = "ComponentNameField"; + // + // CountField + // + this.CountField.HeaderText = "Количество"; + this.CountField.Name = "CountField"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(602, 446); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(110, 34); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(486, 446); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(110, 34); + this.SaveButton.TabIndex = 8; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // FormCar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(746, 498); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ComponentsGroupBox); + this.Controls.Add(this.PriceTextBox); + this.Controls.Add(this.CarNameTextBox); + this.Controls.Add(this.PriceLabel); + this.Controls.Add(this.CarNameLabel); + this.Name = "FormCar"; + this.Text = "Изделие"; + this.ComponentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label CarNameLabel; + private Label PriceLabel; + private TextBox CarNameTextBox; + private TextBox PriceTextBox; + private GroupBox ComponentsGroupBox; + private Button UpdateButton; + private Button DeleteButton; + private Button ChangeButton; + private Button AddButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentNameField; + private DataGridViewTextBoxColumn CountField; + private Button ButtonCancel; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormCar.cs b/AutomobilePlant/AutomobilePlant/FormCar.cs new file mode 100644 index 0000000..a6ffb47 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCar.cs @@ -0,0 +1,223 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormCar : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + private int? _id; + private Dictionary _carComponents; + public int Id { set { _id = value; } } + public FormCar(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _carComponents = new Dictionary(); + } + private void FormCar_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new CarSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + CarNameTextBox.Text = view.CarName; + PriceTextBox.Text = view.Price.ToString(); + _carComponents = view.CarComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_carComponents != null) + { + DataGridView.Rows.Clear(); + foreach (var pc in _carComponents) + { + DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + PriceTextBox.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + if (service is FormCarComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count); + if (_carComponents.ContainsKey(form.Id)) + { + _carComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _carComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + if (service is FormCarComponent form) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _carComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _carComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void DeleteButton_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, DataGridView.SelectedRows[0].Cells[2].Value); + _carComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CarNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PriceTextBox.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_carComponents == null || _carComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new CarBindingModel + { + Id = _id ?? 0, + CarName = CarNameTextBox.Text, + Price = Convert.ToDouble(PriceTextBox.Text), + CarComponents = _carComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, +MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _carComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/Properties/Resources.resx b/AutomobilePlant/AutomobilePlant/FormCar.resx similarity index 90% rename from AutomobilePlant/AutomobilePlant/Properties/Resources.resx rename to AutomobilePlant/AutomobilePlant/FormCar.resx index af7dbeb..1af7de1 100644 --- a/AutomobilePlant/AutomobilePlant/Properties/Resources.resx +++ b/AutomobilePlant/AutomobilePlant/FormCar.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.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/AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs b/AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs new file mode 100644 index 0000000..2143b68 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCarComponent.Designer.cs @@ -0,0 +1,124 @@ +namespace AutomobilePlant +{ + partial class FormCarComponent + { + /// + /// 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.ComponentSelectLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.ComponentComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentSelectLabel + // + this.ComponentSelectLabel.AutoSize = true; + this.ComponentSelectLabel.Location = new System.Drawing.Point(30, 27); + this.ComponentSelectLabel.Name = "ComponentSelectLabel"; + this.ComponentSelectLabel.Size = new System.Drawing.Size(95, 20); + this.ComponentSelectLabel.TabIndex = 0; + this.ComponentSelectLabel.Text = "Компонент: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(30, 75); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(97, 20); + this.CountLabel.TabIndex = 1; + this.CountLabel.Text = "Количество: "; + // + // ComponentComboBox + // + this.ComponentComboBox.FormattingEnabled = true; + this.ComponentComboBox.Location = new System.Drawing.Point(122, 23); + this.ComponentComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ComponentComboBox.Name = "ComponentComboBox"; + this.ComponentComboBox.Size = new System.Drawing.Size(217, 28); + this.ComponentComboBox.TabIndex = 2; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(122, 71); + this.CountTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(217, 27); + this.CountTextBox.TabIndex = 3; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(152, 131); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(254, 131); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCarComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(385, 188); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.ComponentComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.ComponentSelectLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCarComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentSelectLabel; + private Label CountLabel; + private ComboBox ComponentComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormCarComponent.cs b/AutomobilePlant/AutomobilePlant/FormCarComponent.cs new file mode 100644 index 0000000..d33c335 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCarComponent.cs @@ -0,0 +1,91 @@ +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormCarComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return + Convert.ToInt32(ComponentComboBox.SelectedValue); + } + set + { + ComponentComboBox.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(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + public FormCarComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + ComponentComboBox.DisplayMember = "ComponentName"; + ComponentComboBox.ValueMember = "Id"; + ComponentComboBox.DataSource = _list; + ComponentComboBox.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ComponentComboBox.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/AutomobilePlant/AutomobilePlant/FormCarComponent.resx b/AutomobilePlant/AutomobilePlant/FormCarComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCarComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormCars.Designer.cs b/AutomobilePlant/AutomobilePlant/FormCars.Designer.cs new file mode 100644 index 0000000..0614d53 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCars.Designer.cs @@ -0,0 +1,121 @@ +namespace AutomobilePlant +{ + partial class FormCars + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(642, 660); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(669, 16); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(137, 55); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(669, 95); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(137, 55); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(669, 173); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(137, 55); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(669, 255); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(137, 55); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(819, 669); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCars"; + this.Text = "Машины"; + this.Load += new System.EventHandler(this.FormCars_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormCars.cs b/AutomobilePlant/AutomobilePlant/FormCars.cs new file mode 100644 index 0000000..3748c60 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCars.cs @@ -0,0 +1,120 @@ +using Microsoft.Extensions.Logging; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormCars : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + + public FormCars(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCars_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["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["CarComponents"].Visible = false; + } + + _logger.LogInformation("Загрузка изделий"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + + if (service is FormCar 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(FormCar)); + + if (service is FormCar form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + + try + { + if (!_logic.Delete(new CarBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormCars.resx b/AutomobilePlant/AutomobilePlant/FormCars.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCars.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/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs b/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs new file mode 100644 index 0000000..cd009e8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponent.Designer.cs @@ -0,0 +1,123 @@ +namespace AutomobilePlant +{ + 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.ComponentNameLabel = new System.Windows.Forms.Label(); + this.ComponentNameTextBox = new System.Windows.Forms.TextBox(); + this.CostLabel = new System.Windows.Forms.Label(); + this.CostTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Название: "; + // + // ComponentNameTextBox + // + this.ComponentNameTextBox.Location = new System.Drawing.Point(103, 16); + this.ComponentNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ComponentNameTextBox.Name = "ComponentNameTextBox"; + this.ComponentNameTextBox.Size = new System.Drawing.Size(238, 27); + this.ComponentNameTextBox.TabIndex = 2; + // + // CostLabel + // + this.CostLabel.AutoSize = true; + this.CostLabel.Location = new System.Drawing.Point(46, 72); + this.CostLabel.Name = "CostLabel"; + this.CostLabel.Size = new System.Drawing.Size(56, 20); + this.CostLabel.TabIndex = 3; + this.CostLabel.Text = "Цена: "; + // + // CostTextBox + // + this.CostTextBox.Location = new System.Drawing.Point(103, 68); + this.CostTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CostTextBox.Name = "CostTextBox"; + this.CostTextBox.Size = new System.Drawing.Size(238, 27); + this.CostTextBox.TabIndex = 4; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(154, 120); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(256, 120); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 167); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CostTextBox); + this.Controls.Add(this.CostLabel); + this.Controls.Add(this.ComponentNameTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox ComponentNameTextBox; + private Label CostLabel; + private TextBox CostTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormComponent.cs b/AutomobilePlant/AutomobilePlant/FormComponent.cs new file mode 100644 index 0000000..84819cd --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponent.cs @@ -0,0 +1,92 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using Microsoft.Extensions.Logging; +namespace AutomobilePlant +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + ComponentNameTextBox.Text = view.ComponentName; + CostTextBox.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(ComponentNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = ComponentNameTextBox.Text, + Cost = Convert.ToDouble(CostTextBox.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormComponent.resx b/AutomobilePlant/AutomobilePlant/FormComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs b/AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs new file mode 100644 index 0000000..e3b48d9 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponents.Designer.cs @@ -0,0 +1,121 @@ +namespace AutomobilePlant +{ + 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(2, 0); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(630, 735); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(653, 35); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(162, 60); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(653, 124); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(162, 60); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(653, 216); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(162, 60); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(653, 307); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(162, 60); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(829, 736); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + 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 AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormComponents.cs b/AutomobilePlant/AutomobilePlant/FormComponents.cs new file mode 100644 index 0000000..e9b6f67 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormComponents.cs @@ -0,0 +1,117 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void AddButton_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 ChangeButton_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 DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении.Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormComponents.resx b/AutomobilePlant/AutomobilePlant/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs b/AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..5bd9626 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCreateOrder.Designer.cs @@ -0,0 +1,149 @@ +namespace AutomobilePlant +{ + 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.CarNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.SumLabel = new System.Windows.Forms.Label(); + this.CarComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SumTextBox = new System.Windows.Forms.TextBox(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SaveButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // CarNameLabel + // + this.CarNameLabel.AutoSize = true; + this.CarNameLabel.Location = new System.Drawing.Point(14, 12); + this.CarNameLabel.Name = "CarNameLabel"; + this.CarNameLabel.Size = new System.Drawing.Size(75, 20); + this.CarNameLabel.TabIndex = 0; + this.CarNameLabel.Text = "Изделие: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(14, 53); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(97, 20); + this.CountLabel.TabIndex = 1; + this.CountLabel.Text = "Количество: "; + // + // SumLabel + // + this.SumLabel.AutoSize = true; + this.SumLabel.Location = new System.Drawing.Point(14, 96); + this.SumLabel.Name = "SumLabel"; + this.SumLabel.Size = new System.Drawing.Size(62, 20); + this.SumLabel.TabIndex = 2; + this.SumLabel.Text = "Сумма: "; + // + // CarComboBox + // + this.CarComboBox.FormattingEnabled = true; + this.CarComboBox.Location = new System.Drawing.Point(106, 8); + this.CarComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CarComboBox.Name = "CarComboBox"; + this.CarComboBox.Size = new System.Drawing.Size(229, 28); + this.CarComboBox.TabIndex = 3; + this.CarComboBox.SelectedIndexChanged += new System.EventHandler(this.CarComboBox_SelectedIndexChanged); + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(106, 49); + this.CountTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(229, 27); + this.CountTextBox.TabIndex = 4; + this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged); + // + // SumTextBox + // + this.SumTextBox.Location = new System.Drawing.Point(106, 92); + this.SumTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SumTextBox.Name = "SumTextBox"; + this.SumTextBox.Size = new System.Drawing.Size(229, 27); + this.SumTextBox.TabIndex = 5; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(250, 151); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(147, 151); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(97, 31); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(353, 204); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SumTextBox); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.CarComboBox); + this.Controls.Add(this.SumLabel); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.CarNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label CarNameLabel; + private Label CountLabel; + private Label SumLabel; + private ComboBox CarComboBox; + private TextBox CountTextBox; + private TextBox SumTextBox; + private Button ButtonCancel; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs b/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs new file mode 100644 index 0000000..0084982 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs @@ -0,0 +1,143 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicW; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, ICarLogic logicW, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicW; + _logicO = logicO; + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий для заказа"); + + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + CarComboBox.DisplayMember = "CarName"; + CarComboBox.ValueMember = "Id"; + CarComboBox.DataSource = list; + CarComboBox.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CalcSum() + { + if (CarComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) + { + try + { + int id = Convert.ToInt32(CarComboBox.SelectedValue); + + var car = _logicW.ReadElement(new CarSearchModel + { + Id = id + }); + + int count = Convert.ToInt32(CountTextBox.Text); + SumTextBox.Text = Math.Round(count * (car?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void CountTextBox_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void CarComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (CarComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CarId = Convert.ToInt32(CarComboBox.SelectedValue), + CarName = CarComboBox.Text, + Count = Convert.ToInt32(CountTextBox.Text), + Sum = Convert.ToDouble(SumTextBox.Text) + }); + + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormCreateOrder.resx b/AutomobilePlant/AutomobilePlant/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs new file mode 100644 index 0000000..1a73596 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs @@ -0,0 +1,184 @@ +namespace AutomobilePlant +{ + 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.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.DataGridView = new System.Windows.Forms.DataGridView(); + this.CreateOrderButton = new System.Windows.Forms.Button(); + this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); + this.OrderReadyButton = new System.Windows.Forms.Button(); + this.IssuedOrderButton = new System.Windows.Forms.Button(); + this.UpdateListButton = new System.Windows.Forms.Button(); + this.MenuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // MenuStrip + // + this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + 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(7, 3, 0, 3); + this.MenuStrip.Size = new System.Drawing.Size(989, 30); + this.MenuStrip.TabIndex = 0; + 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(117, 24); + this.СправочникиToolStripMenuItem.Text = "Cправочники"; + // + // ИзделияToolStripMenuItem + // + this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.ИзделияToolStripMenuItem.Text = "Изделия"; + this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // КомпонентыToolStripMenuItem + // + this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.КомпонентыToolStripMenuItem.Text = "Компоненты"; + this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(0, 36); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(825, 561); + this.DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + this.CreateOrderButton.Location = new System.Drawing.Point(832, 37); + this.CreateOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CreateOrderButton.Name = "CreateOrderButton"; + this.CreateOrderButton.Size = new System.Drawing.Size(143, 44); + this.CreateOrderButton.TabIndex = 2; + this.CreateOrderButton.Text = "Создать заказ"; + this.CreateOrderButton.UseVisualStyleBackColor = true; + this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); + // + // TakeOrderInWorkButton + // + this.TakeOrderInWorkButton.Location = new System.Drawing.Point(832, 111); + this.TakeOrderInWorkButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; + this.TakeOrderInWorkButton.Size = new System.Drawing.Size(143, 52); + this.TakeOrderInWorkButton.TabIndex = 3; + this.TakeOrderInWorkButton.Text = "Отдать на выполнение"; + this.TakeOrderInWorkButton.UseVisualStyleBackColor = true; + this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click); + // + // OrderReadyButton + // + this.OrderReadyButton.Location = new System.Drawing.Point(832, 195); + this.OrderReadyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.OrderReadyButton.Name = "OrderReadyButton"; + this.OrderReadyButton.Size = new System.Drawing.Size(143, 44); + this.OrderReadyButton.TabIndex = 4; + this.OrderReadyButton.Text = "Заказ готов"; + this.OrderReadyButton.UseVisualStyleBackColor = true; + this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click); + // + // IssuedOrderButton + // + this.IssuedOrderButton.Location = new System.Drawing.Point(832, 272); + this.IssuedOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.IssuedOrderButton.Name = "IssuedOrderButton"; + this.IssuedOrderButton.Size = new System.Drawing.Size(143, 44); + this.IssuedOrderButton.TabIndex = 5; + this.IssuedOrderButton.Text = "Заказ выдан"; + this.IssuedOrderButton.UseVisualStyleBackColor = true; + this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click); + // + // UpdateListButton + // + this.UpdateListButton.Location = new System.Drawing.Point(832, 349); + this.UpdateListButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateListButton.Name = "UpdateListButton"; + this.UpdateListButton.Size = new System.Drawing.Size(143, 44); + this.UpdateListButton.TabIndex = 6; + this.UpdateListButton.Text = "Обновить список"; + this.UpdateListButton.UseVisualStyleBackColor = true; + this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(989, 600); + this.Controls.Add(this.UpdateListButton); + this.Controls.Add(this.IssuedOrderButton); + this.Controls.Add(this.OrderReadyButton); + this.Controls.Add(this.TakeOrderInWorkButton); + this.Controls.Add(this.CreateOrderButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.MenuStrip); + this.MainMenuStrip = this.MenuStrip; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormMain"; + this.Text = "Автозавод"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.MenuStrip.ResumeLayout(false); + this.MenuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip MenuStrip; + private ToolStripMenuItem СправочникиToolStripMenuItem; + private ToolStripMenuItem ИзделияToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button TakeOrderInWorkButton; + private Button OrderReadyButton; + private Button IssuedOrderButton; + private Button UpdateListButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.cs b/AutomobilePlant/AutomobilePlant/FormMain.cs new file mode 100644 index 0000000..241de04 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormMain.cs @@ -0,0 +1,200 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["CarId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + + if (service is FormCars form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void TakeOrderInWorkButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value), + CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void OrderReadyButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value), + CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void IssuedOrderButton_Click (object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["CarId"].Value), + CarName = DataGridView.SelectedRows[0].Cells["CarName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + + }); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void UpdateListButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormMain.resx b/AutomobilePlant/AutomobilePlant/FormMain.resx new file mode 100644 index 0000000..a694815 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index 08596b9..f8f9e03 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -1,22 +1,53 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; +using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; namespace AutomobilePlant { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// Главная точка входа для приложения. + /// The main entry point for the application. /// [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } -} +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/Properties/AssemblyInfo.cs b/AutomobilePlant/AutomobilePlant/Properties/AssemblyInfo.cs deleted file mode 100644 index 3e42964..0000000 --- a/AutomobilePlant/AutomobilePlant/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Общие сведения об этой сборке предоставляются следующим набором -// набора атрибутов. Измените значения этих атрибутов для изменения сведений, -// связанных со сборкой. -[assembly: AssemblyTitle("AutomobilePlant")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("AutomobilePlant")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми -// для компонентов COM. Если необходимо обратиться к типу в этой сборке через -// COM, следует установить атрибут ComVisible в TRUE для этого типа. -[assembly: ComVisible(false)] - -// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM -[assembly: Guid("2a499de6-b7de-4a28-9906-12fc100451f0")] - -// Сведения о версии сборки состоят из указанных ниже четырех значений: -// -// Основной номер версии -// Дополнительный номер версии -// Номер сборки -// Редакция -// -// Можно задать все значения или принять номера сборки и редакции по умолчанию -// используя "*", как показано ниже: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AutomobilePlant/AutomobilePlant/Properties/Resources.Designer.cs b/AutomobilePlant/AutomobilePlant/Properties/Resources.Designer.cs deleted file mode 100644 index d0d9279..0000000 --- a/AutomobilePlant/AutomobilePlant/Properties/Resources.Designer.cs +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Этот код создан программным средством. -// Версия среды выполнения: 4.0.30319.42000 -// -// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если -// код создан повторно. -// -//------------------------------------------------------------------------------ - -namespace AutomobilePlant.Properties -{ - - - /// - /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. - /// - // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder - // класс с помощью таких средств, как ResGen или Visual Studio. - // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen - // с параметром /str или заново постройте свой VS-проект. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutomobilePlant.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Переопределяет свойство CurrentUICulture текущего потока для всех - /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/AutomobilePlant/AutomobilePlant/Properties/Settings.Designer.cs b/AutomobilePlant/AutomobilePlant/Properties/Settings.Designer.cs deleted file mode 100644 index db6fc4e..0000000 --- a/AutomobilePlant/AutomobilePlant/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace AutomobilePlant.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/AutomobilePlant/AutomobilePlant/Properties/Settings.settings b/AutomobilePlant/AutomobilePlant/Properties/Settings.settings deleted file mode 100644 index 3964565..0000000 --- a/AutomobilePlant/AutomobilePlant/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/AutomobilePlant/AutomobilePlant/nlog.config b/AutomobilePlant/AutomobilePlant/nlog.config new file mode 100644 index 0000000..dcd37c8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1