From 055177276843780c5ebb3a2eaea6dd30d9cf21bb Mon Sep 17 00:00:00 2001 From: Sasylika4598 Date: Sat, 11 May 2024 11:52:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=201?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SecuritySystem/SecuritySystem.sln | 49 ++++ .../BusinessLogics/ComponentLogic.cs | 109 +++++++++ .../BusinessLogics/OrderLogic.cs | 119 +++++++++ .../BusinessLogics/SecureLogic.cs | 107 ++++++++ .../SecuritySystemBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 11 + .../BindingModels/OrderBindingModel.cs | 16 ++ .../BindingModels/SecureBindingModel.cs | 12 + .../IComponentLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../BusinessLogicsContracts/ISecureLogic.cs | 15 ++ .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/SecureSearchModel.cs | 8 + .../SecuritySystemContracts.csproj | 13 + .../StoragesContracts/IComponentStorage.cs | 17 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../StoragesContracts/ISecureStorage.cs | 16 ++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../ViewModels/SecureViewModel.cs | 15 ++ .../Enums/OrderStatus.cs | 11 + .../SecuritySystemDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 8 + .../Models/IOrderModel.cs | 14 ++ .../Models/ISecureModel.cs | 9 + .../SecuritySystemDataModels.csproj | 9 + .../DataListSingleton.cs | 26 ++ .../Implements/ComponentStorage.cs | 104 ++++++++ .../Implements/OrderStorage.cs | 115 +++++++++ .../Implements/SecureStorage.cs | 109 +++++++++ .../Models/Component.cs | 41 ++++ .../Models/Order.cs | 62 +++++ .../Models/Secure.cs | 50 ++++ .../SecuritySystemListImplement.csproj | 14 ++ .../FormComponent.Designer.cs | 118 +++++++++ .../SecuritySystemView/FormComponent.cs | 85 +++++++ .../SecuritySystemView/FormComponent.resx | 120 +++++++++ .../FormComponents.Designer.cs | 124 ++++++++++ .../SecuritySystemView/FormComponents.cs | 98 ++++++++ .../SecuritySystemView/FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 145 +++++++++++ .../SecuritySystemView/FormCreateOrder.cs | 117 +++++++++ .../SecuritySystemView/FormCreateOrder.resx | 120 +++++++++ .../SecuritySystemView/FormMain.Designer.cs | 181 ++++++++++++++ SecuritySystem/SecuritySystemView/FormMain.cs | 140 +++++++++++ .../SecuritySystemView/FormMain.resx | 123 ++++++++++ .../SecuritySystemView/FormSecure.Designer.cs | 230 ++++++++++++++++++ .../SecuritySystemView/FormSecure.cs | 207 ++++++++++++++++ .../SecuritySystemView/FormSecure.resx | 129 ++++++++++ .../FormSecureComponent.Designer.cs | 119 +++++++++ .../SecuritySystemView/FormSecureComponent.cs | 85 +++++++ .../FormSecureComponent.resx | 120 +++++++++ .../FormSecures.Designer.cs | 122 ++++++++++ .../SecuritySystemView/FormSecures.cs | 98 ++++++++ .../SecuritySystemView/FormSecures.resx | 120 +++++++++ SecuritySystem/SecuritySystemView/Program.cs | 51 ++++ .../SecuritySystemView.csproj | 35 +++ SecuritySystem/SecuritySystemView/nlog.config | 16 ++ 59 files changed, 4026 insertions(+) create mode 100644 SecuritySystem/SecuritySystem.sln create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/OrderBindingModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/SecureBindingModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs create mode 100644 SecuritySystem/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/SearchModels/OrderSearchModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/SearchModels/SecureSearchModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/SecuritySystemContracts.csproj create mode 100644 SecuritySystem/SecuritySystemContracts/StoragesContracts/IComponentStorage.cs create mode 100644 SecuritySystem/SecuritySystemContracts/StoragesContracts/IOrderStorage.cs create mode 100644 SecuritySystem/SecuritySystemContracts/StoragesContracts/ISecureStorage.cs create mode 100644 SecuritySystem/SecuritySystemContracts/ViewModels/ComponentViewModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/ViewModels/OrderViewModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/ViewModels/SecureViewModel.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/Enums/OrderStatus.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/IId.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/Models/IComponentModel.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/Models/IOrderModel.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/Models/ISecureModel.cs create mode 100644 SecuritySystem/SecuritySystemDataModels/SecuritySystemDataModels.csproj create mode 100644 SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Component.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Order.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Secure.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj create mode 100644 SecuritySystem/SecuritySystemView/FormComponent.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponent.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponent.resx create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.resx create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.cs create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.resx create mode 100644 SecuritySystem/SecuritySystemView/FormMain.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormMain.cs create mode 100644 SecuritySystem/SecuritySystemView/FormMain.resx create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.resx create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.resx create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecures.resx create mode 100644 SecuritySystem/SecuritySystemView/Program.cs create mode 100644 SecuritySystem/SecuritySystemView/SecuritySystemView.csproj create mode 100644 SecuritySystem/SecuritySystemView/nlog.config diff --git a/SecuritySystem/SecuritySystem.sln b/SecuritySystem/SecuritySystem.sln new file mode 100644 index 0000000..02b0a54 --- /dev/null +++ b/SecuritySystem/SecuritySystem.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemView", "SecuritySystemView\SecuritySystemView.csproj", "{B4D0310E-1162-4BCF-A7E0-2AC41959C963}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDataModels", "SecuritySystemDataModels\SecuritySystemDataModels.csproj", "{37DD658F-D5C0-4C97-A83D-A21EE0076C55}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemContracts", "SecuritySystemContracts\SecuritySystemContracts.csproj", "{0737BCB2-EEDB-44A4-8BD2-5B5EA689A7FF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogic", "SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{38C8A0AB-9363-4914-B967-02586827588D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{6A104362-3398-4D4E-A3D0-2F4B32858569}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B4D0310E-1162-4BCF-A7E0-2AC41959C963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4D0310E-1162-4BCF-A7E0-2AC41959C963}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4D0310E-1162-4BCF-A7E0-2AC41959C963}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4D0310E-1162-4BCF-A7E0-2AC41959C963}.Release|Any CPU.Build.0 = Release|Any CPU + {37DD658F-D5C0-4C97-A83D-A21EE0076C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37DD658F-D5C0-4C97-A83D-A21EE0076C55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37DD658F-D5C0-4C97-A83D-A21EE0076C55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37DD658F-D5C0-4C97-A83D-A21EE0076C55}.Release|Any CPU.Build.0 = Release|Any CPU + {0737BCB2-EEDB-44A4-8BD2-5B5EA689A7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0737BCB2-EEDB-44A4-8BD2-5B5EA689A7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0737BCB2-EEDB-44A4-8BD2-5B5EA689A7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0737BCB2-EEDB-44A4-8BD2-5B5EA689A7FF}.Release|Any CPU.Build.0 = Release|Any CPU + {38C8A0AB-9363-4914-B967-02586827588D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38C8A0AB-9363-4914-B967-02586827588D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.Build.0 = Release|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {09EF3C7E-54D5-4BC3-BF2D-8E42771DED19} + EndGlobalSection +EndGlobal diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ComponentLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..83354d5 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,109 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemBusinessLogic.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/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..44b56f0 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Enums; + +namespace SecuritySystemBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + OrderStatus oldStatus = model.Status; + model.Status = status; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status = oldStatus; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SecureId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор secure", nameof(model.SecureId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество secure в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{Cost}. Id: {Id}", model.Sum, model.Id); + } + } +} diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs new file mode 100644 index 0000000..3cc8f0a --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs @@ -0,0 +1,107 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemBusinessLogic.BusinessLogics +{ + public class SecureLogic : ISecureLogic + { + private readonly ILogger _logger; + private readonly ISecureStorage _secureStorage; + public SecureLogic(ILogger logger, ISecureStorage secureStorage) + { + _logger = logger; + _secureStorage = secureStorage; + } + public bool Create(SecureBindingModel model) + { + CheckModel(model); + if (_secureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Delete(SecureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_secureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public SecureViewModel? ReadElement(SecureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SecureName:{SecureName}. Id:{Id}", model.SecureName, model.Id); + var element = _secureStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public List? ReadList(SecureSearchModel? model) + { + _logger.LogInformation("ReadList. SecureName:{SecureName}. Id:{Id}", model?.SecureName, model?.Id); + var list = model == null ? _secureStorage.GetFullList() : _secureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool Update(SecureBindingModel model) + { + CheckModel(model); + if (_secureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(SecureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SecureName)) + { + throw new ArgumentNullException("Нет названия secure", nameof(model.SecureName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена secure должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Secure. SecureName:{SecureName}. Price:{Price}. Id:{Id}", model.SecureName, model.Price, model.Id); + var element = _secureStorage.GetElement(new SecureSearchModel + { + SecureName = model.SecureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Secure с таким названием уже есть"); + } + } + } +} diff --git a/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj b/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj new file mode 100644 index 0000000..d936e08 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..3f01435 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.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/SecuritySystem/SecuritySystemContracts/BindingModels/OrderBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..3ff6f27 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using SecuritySystemDataModels.Enums; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int SecureId { 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/SecuritySystem/SecuritySystemContracts/BindingModels/SecureBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/SecureBindingModel.cs new file mode 100644 index 0000000..b6e3cb8 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/SecureBindingModel.cs @@ -0,0 +1,12 @@ +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BindingModels +{ + public class SecureBindingModel : ISecureModel + { + public int Id { get; set; } + public string SecureName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary SecureComponents { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..48c12b3 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.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/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..5017a75 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.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/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs new file mode 100644 index 0000000..4162113 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs @@ -0,0 +1,15 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.BusinessLogicsContracts +{ + public interface ISecureLogic + { + List? ReadList(SecureSearchModel? model); + SecureViewModel? ReadElement(SecureSearchModel model); + bool Create(SecureBindingModel model); + bool Update(SecureBindingModel model); + bool Delete(SecureBindingModel model); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..71b6fb5 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/OrderSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..500fb59 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/SecureSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/SecureSearchModel.cs new file mode 100644 index 0000000..596ead5 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/SecureSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class SecureSearchModel + { + public int? Id { get; set; } + public string? SecureName { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SecuritySystemContracts.csproj b/SecuritySystem/SecuritySystemContracts/SecuritySystemContracts.csproj new file mode 100644 index 0000000..755c027 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SecuritySystemContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/SecuritySystem/SecuritySystemContracts/StoragesContracts/IComponentStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..67b3928 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.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/SecuritySystem/SecuritySystemContracts/StoragesContracts/IOrderStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..3d3941a --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.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/SecuritySystem/SecuritySystemContracts/StoragesContracts/ISecureStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/ISecureStorage.cs new file mode 100644 index 0000000..21770d5 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/ISecureStorage.cs @@ -0,0 +1,16 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.StoragesContracts +{ + public interface ISecureStorage + { + List GetFullList(); + List GetFilteredList(SecureSearchModel model); + SecureViewModel? GetElement(SecureSearchModel model); + SecureViewModel? Insert(SecureBindingModel model); + SecureViewModel? Update(SecureBindingModel model); + SecureViewModel? Delete(SecureBindingModel model); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/ComponentViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..852c89c --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/OrderViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..1a300c0 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using SecuritySystemDataModels.Enums; +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int SecureId { get; set; } + [DisplayName("Изделие")] + public string SecureName { 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/SecuritySystem/SecuritySystemContracts/ViewModels/SecureViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/SecureViewModel.cs new file mode 100644 index 0000000..3da5222 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/SecureViewModel.cs @@ -0,0 +1,15 @@ +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.ViewModels +{ + public class SecureViewModel : ISecureModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string SecureName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary SecureComponents { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Enums/OrderStatus.cs b/SecuritySystem/SecuritySystemDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..c423671 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace SecuritySystemDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/IId.cs b/SecuritySystem/SecuritySystemDataModels/IId.cs new file mode 100644 index 0000000..aa1a466 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace SecuritySystemDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IComponentModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..56c0829 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IOrderModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..c6fd126 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using SecuritySystemDataModels.Enums; + +namespace SecuritySystemDataModels.Models +{ + public interface IOrderModel : IId + { + int SecureId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Models/ISecureModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/ISecureModel.cs new file mode 100644 index 0000000..50588c7 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/ISecureModel.cs @@ -0,0 +1,9 @@ +namespace SecuritySystemDataModels.Models +{ + public interface ISecureModel : IId + { + string SecureName { get; } + double Price { get; } + Dictionary SecureComponents { get; } + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/SecuritySystemDataModels.csproj b/SecuritySystem/SecuritySystemDataModels/SecuritySystemDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/SecuritySystemDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs new file mode 100644 index 0000000..e173975 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Secures { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Secures = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..11a7c78 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,104 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.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/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..3bc00f8 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs @@ -0,0 +1,115 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.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(GetViewModel(order)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ( + (model.Id.HasValue && order.Id == model.Id) + ) + { + return order.GetViewModel; + } + } + return null; + } + 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; + } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var secure in _source.Secures) + { + if (secure.Id == order.SecureId) + { + viewModel.SecureName = secure.SecureName; + break; + } + } + return viewModel; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs new file mode 100644 index 0000000..fadad29 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs @@ -0,0 +1,109 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.Implements +{ + public class SecureStorage : ISecureStorage + { + private readonly DataListSingleton _source; + + public SecureStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var secure in _source.Secures) + { + result.Add(secure.GetViewModel); + } + return result; + } + + public List GetFilteredList(SecureSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SecureName)) + { + return result; + } + foreach (var secure in _source.Secures) + { + if (secure.SecureName.Contains(model.SecureName)) + { + result.Add(secure.GetViewModel); + } + } + return result; + } + public SecureViewModel? GetElement(SecureSearchModel model) + { + if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue) + { + return null; + } + foreach (var secure in _source.Secures) + { + if ( + (!string.IsNullOrEmpty(model.SecureName) && + secure.SecureName == model.SecureName) || + (model.Id.HasValue && secure.Id == model.Id) + ) + { + return secure.GetViewModel; + } + } + return null; + } + + public SecureViewModel? Insert(SecureBindingModel model) + { + model.Id = 1; + foreach (var secure in _source.Secures) + { + if (model.Id <= secure.Id) + { + model.Id = secure.Id + 1; + } + } + var newSecure = Secure.Create(model); + if (newSecure == null) + { + return null; + } + _source.Secures.Add(newSecure); + return newSecure.GetViewModel; + } + + public SecureViewModel? Update(SecureBindingModel model) + { + foreach (var secure in _source.Secures) + { + if (secure.Id == model.Id) + { + secure.Update(model); + return secure.GetViewModel; + } + } + return null; + } + public SecureViewModel? Delete(SecureBindingModel model) + { + for (int i = 0; i < _source.Secures.Count; ++i) + { + if (_source.Secures[i].Id == model.Id) + { + var element = _source.Secures[i]; + _source.Secures.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Component.cs b/SecuritySystem/SecuritySystemListImplement/Models/Component.cs new file mode 100644 index 0000000..804f338 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.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/SecuritySystem/SecuritySystemListImplement/Models/Order.cs b/SecuritySystem/SecuritySystemListImplement/Models/Order.cs new file mode 100644 index 0000000..47bc31d --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Enums; + +namespace SecuritySystemListImplement.Models +{ + public class Order + { + public int SecureId { 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 int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + Id = model.Id, + SecureId = model.SecureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + SecureId = SecureId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs b/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs new file mode 100644 index 0000000..9b5698a --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs @@ -0,0 +1,50 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.Models +{ + public class Secure : ISecureModel + { + public int Id { get; private set; } + public string SecureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary SecureComponents + { + get; + private set; + } = new Dictionary(); + public static Secure? Create(SecureBindingModel? model) + { + if (model == null) + { + return null; + } + return new Secure() + { + Id = model.Id, + SecureName = model.SecureName, + Price = model.Price, + SecureComponents = model.SecureComponents + }; + } + public void Update(SecureBindingModel? model) + { + if (model == null) + { + return; + } + SecureName = model.SecureName; + Price = model.Price; + SecureComponents = model.SecureComponents; + } + public SecureViewModel GetViewModel => new() + { + Id = Id, + SecureName = SecureName, + Price = Price, + SecureComponents = SecureComponents + }; + + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj new file mode 100644 index 0000000..7d1c090 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs b/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs new file mode 100644 index 0000000..ffb456e --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace SecuritySystemView +{ + 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() + { + textBoxComponentName = new TextBox(); + textBoxComponentCost = new TextBox(); + labelComponentName = new Label(); + labelComponentCost = new Label(); + buttonSaveComponent = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxComponentName + // + textBoxComponentName.Location = new Point(98, 6); + textBoxComponentName.Name = "textBoxComponentName"; + textBoxComponentName.Size = new Size(372, 27); + textBoxComponentName.TabIndex = 0; + // + // textBoxComponentCost + // + textBoxComponentCost.Location = new Point(98, 41); + textBoxComponentCost.Name = "textBoxComponentCost"; + textBoxComponentCost.Size = new Size(125, 27); + textBoxComponentCost.TabIndex = 1; + // + // labelComponentName + // + labelComponentName.AutoSize = true; + labelComponentName.Location = new Point(12, 9); + labelComponentName.Name = "labelComponentName"; + labelComponentName.Size = new Size(80, 20); + labelComponentName.TabIndex = 2; + labelComponentName.Text = "Название:"; + // + // labelComponentCost + // + labelComponentCost.AutoSize = true; + labelComponentCost.Location = new Point(12, 41); + labelComponentCost.Name = "labelComponentCost"; + labelComponentCost.Size = new Size(48, 20); + labelComponentCost.TabIndex = 3; + labelComponentCost.Text = "Цена:"; + // + // buttonSaveComponent + // + buttonSaveComponent.Location = new Point(211, 80); + buttonSaveComponent.Name = "buttonSaveComponent"; + buttonSaveComponent.Size = new Size(115, 29); + buttonSaveComponent.TabIndex = 1; + buttonSaveComponent.Text = "Сохранить"; + buttonSaveComponent.UseVisualStyleBackColor = true; + buttonSaveComponent.Click += ButtonSaveComponent_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(348, 80); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(122, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(482, 119); + Controls.Add(buttonCancel); + Controls.Add(buttonSaveComponent); + Controls.Add(labelComponentCost); + Controls.Add(labelComponentName); + Controls.Add(textBoxComponentCost); + Controls.Add(textBoxComponentName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxComponentName; + private TextBox textBoxComponentCost; + private Label labelComponentName; + private Label labelComponentCost; + private Button buttonSaveComponent; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormComponent.cs b/SecuritySystem/SecuritySystemView/FormComponent.cs new file mode 100644 index 0000000..470d226 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponent.cs @@ -0,0 +1,85 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using System.Windows.Forms; + +namespace SecuritySystemView +{ + 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) + { + textBoxComponentName.Text = view.ComponentName; + textBoxComponentCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSaveComponent_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxComponentName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxComponentName.Text, + Cost = Convert.ToDouble(textBoxComponentCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/SecuritySystem/SecuritySystemView/FormComponent.resx b/SecuritySystem/SecuritySystemView/FormComponent.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/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/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs new file mode 100644 index 0000000..47a72ff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs @@ -0,0 +1,124 @@ +namespace SecuritySystemView +{ + 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() + { + dataGridViewComponents = new DataGridView(); + buttonAddComponent = new Button(); + buttonEditComponent = new Button(); + buttonDeleteComponent = new Button(); + buttonRefreshComponents = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); + SuspendLayout(); + // + // dataGridViewComponents + // + dataGridViewComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridViewComponents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewComponents.Location = new Point(0, 0); + dataGridViewComponents.MultiSelect = false; + dataGridViewComponents.Name = "dataGridViewComponents"; + dataGridViewComponents.ReadOnly = true; + dataGridViewComponents.RowHeadersVisible = false; + dataGridViewComponents.RowHeadersWidth = 51; + dataGridViewComponents.RowTemplate.Height = 29; + dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewComponents.Size = new Size(637, 450); + dataGridViewComponents.TabIndex = 0; + // + // buttonAddComponent + // + buttonAddComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAddComponent.Location = new Point(660, 23); + buttonAddComponent.Name = "buttonAddComponent"; + buttonAddComponent.Size = new Size(94, 29); + buttonAddComponent.TabIndex = 1; + buttonAddComponent.Text = "Добавить"; + buttonAddComponent.UseVisualStyleBackColor = true; + buttonAddComponent.Click += ButtonAddComponent_Click; + // + // buttonEditComponent + // + buttonEditComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEditComponent.Location = new Point(660, 75); + buttonEditComponent.Name = "buttonEditComponent"; + buttonEditComponent.Size = new Size(94, 29); + buttonEditComponent.TabIndex = 2; + buttonEditComponent.Text = "Изменить"; + buttonEditComponent.UseVisualStyleBackColor = true; + buttonEditComponent.Click += ButtonEditComponent_Click; + // + // buttonDeleteComponent + // + buttonDeleteComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDeleteComponent.Location = new Point(660, 125); + buttonDeleteComponent.Name = "buttonDeleteComponent"; + buttonDeleteComponent.Size = new Size(94, 29); + buttonDeleteComponent.TabIndex = 3; + buttonDeleteComponent.Text = "Удалить"; + buttonDeleteComponent.UseVisualStyleBackColor = true; + buttonDeleteComponent.Click += ButtonDeleteComponent_Click; + // + // buttonRefreshComponents + // + buttonRefreshComponents.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefreshComponents.Location = new Point(660, 173); + buttonRefreshComponents.Name = "buttonRefreshComponents"; + buttonRefreshComponents.Size = new Size(94, 29); + buttonRefreshComponents.TabIndex = 4; + buttonRefreshComponents.Text = "Обновить"; + buttonRefreshComponents.UseVisualStyleBackColor = true; + buttonRefreshComponents.Click += ButtonRefreshComponents_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(775, 450); + Controls.Add(buttonRefreshComponents); + Controls.Add(buttonDeleteComponent); + Controls.Add(buttonEditComponent); + Controls.Add(buttonAddComponent); + Controls.Add(dataGridViewComponents); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewComponents; + private Button buttonAddComponent; + private Button buttonEditComponent; + private Button buttonDeleteComponent; + private Button buttonRefreshComponents; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormComponents.cs b/SecuritySystem/SecuritySystemView/FormComponents.cs new file mode 100644 index 0000000..182e508 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponents.cs @@ -0,0 +1,98 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + 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) + { + dataGridViewComponents.DataSource = list; + dataGridViewComponents.Columns["Id"].Visible = false; + dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAddComponent_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 ButtonEditComponent_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDeleteComponent_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewComponents.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 ButtonRefreshComponents_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/SecuritySystem/SecuritySystemView/FormComponents.resx b/SecuritySystem/SecuritySystemView/FormComponents.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs b/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..d99f108 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace SecuritySystemView +{ + 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() + { + labelSecureName = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxSecure = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelSecureName + // + labelSecureName.AutoSize = true; + labelSecureName.Location = new Point(11, 12); + labelSecureName.Name = "labelSecureName"; + labelSecureName.Size = new Size(71, 20); + labelSecureName.TabIndex = 0; + labelSecureName.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(11, 46); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 78); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(58, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // comboBoxSecure + // + comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(110, 9); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(462, 28); + comboBoxSecure.TabIndex = 3; + comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(110, 43); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(462, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(110, 75); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(462, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(370, 118); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(478, 118); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(586, 160); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxSecure); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelSecureName); + Name = "FormCreateOrder"; + Text = "Создание заказа"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelSecureName; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxSecure; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.cs b/SecuritySystem/SecuritySystemView/FormCreateOrder.cs new file mode 100644 index 0000000..d075ddf --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormCreateOrder.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; + +namespace SecuritySystemView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logicSecure; + private readonly IOrderLogic _logicOrder; + public FormCreateOrder(ILogger logger, ISecureLogic logicSecure, IOrderLogic logicOrder) + { + InitializeComponent(); + _logger = logger; + _logicSecure = logicSecure; + _logicOrder = logicOrder; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicSecure.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxSecure.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSecure.SelectedValue); + var secure = _logicSecure.ReadElement(new SecureSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (secure?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxSecure_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicOrder.CreateOrder(new OrderBindingModel + { + SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.resx b/SecuritySystem/SecuritySystemView/FormCreateOrder.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/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/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs new file mode 100644 index 0000000..5ff6f2b --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -0,0 +1,181 @@ +namespace SecuritySystemView +{ + 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() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + ComponentsToolStripMenuItem = new ToolStripMenuItem(); + SecuresToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + button4 = new Button(); + buttonRefresh = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1043, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // ComponentsToolStripMenuItem + // + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(182, 26); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // SecuresToolStripMenuItem + // + SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; + SecuresToolStripMenuItem.Size = new Size(182, 26); + SecuresToolStripMenuItem.Text = "Изделия"; + SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(775, 296); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(816, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(216, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(816, 110); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(216, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(816, 167); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(216, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // button4 + // + button4.Anchor = AnchorStyles.Top | AnchorStyles.Right; + button4.Location = new Point(816, 230); + button4.Name = "button4"; + button4.Size = new Size(216, 29); + button4.TabIndex = 5; + button4.Text = "Заказ выдан"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(816, 290); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(216, 29); + buttonRefresh.TabIndex = 1; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1043, 339); + Controls.Add(buttonRefresh); + Controls.Add(button4); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Системы безопасности"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem SecuresToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button button4; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs new file mode 100644 index 0000000..2fed95c --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -0,0 +1,140 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + 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["SecureId"].Visible = false; + + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void SecuresToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecures)); + if (service is FormSecures form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormMain.resx b/SecuritySystem/SecuritySystemView/FormMain.resx new file mode 100644 index 0000000..c17a880 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs new file mode 100644 index 0000000..d64046a --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs @@ -0,0 +1,230 @@ +namespace SecuritySystemView +{ + partial class FormSecure + { + /// + /// 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() + { + labelSecureName = new Label(); + labelSecurePrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponentsControl = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponentsControl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelSecureName + // + labelSecureName.AutoSize = true; + labelSecureName.Location = new Point(12, 9); + labelSecureName.Name = "labelSecureName"; + labelSecureName.Size = new Size(80, 20); + labelSecureName.TabIndex = 0; + labelSecureName.Text = "Название:"; + // + // labelSecurePrice + // + labelSecurePrice.AutoSize = true; + labelSecurePrice.Location = new Point(12, 46); + labelSecurePrice.Name = "labelSecurePrice"; + labelSecurePrice.Size = new Size(86, 20); + labelSecurePrice.TabIndex = 1; + labelSecurePrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(108, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(368, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(108, 43); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(143, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponentsControl + // + groupBoxComponentsControl.Controls.Add(buttonRefresh); + groupBoxComponentsControl.Controls.Add(buttonDelete); + groupBoxComponentsControl.Controls.Add(buttonEdit); + groupBoxComponentsControl.Controls.Add(buttonAdd); + groupBoxComponentsControl.Controls.Add(dataGridView); + groupBoxComponentsControl.Location = new Point(12, 76); + groupBoxComponentsControl.Name = "groupBoxComponentsControl"; + groupBoxComponentsControl.Size = new Size(776, 317); + groupBoxComponentsControl.TabIndex = 5; + groupBoxComponentsControl.TabStop = false; + groupBoxComponentsControl.Text = "Компоненты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(668, 197); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(668, 147); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(668, 99); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(668, 48); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(627, 285); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Location = new Point(537, 409); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(108, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(665, 409); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(109, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSecure + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponentsControl); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelSecurePrice); + Controls.Add(labelSecureName); + Name = "FormSecure"; + Text = "Изделие"; + Load += FormSecure_Load; + groupBoxComponentsControl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelSecureName; + private Label labelSecurePrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponentsControl; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecure.cs b/SecuritySystem/SecuritySystemView/FormSecure.cs new file mode 100644 index 0000000..7083b18 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.cs @@ -0,0 +1,207 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemDataModels.Models; +using System.Windows.Forms; + +namespace SecuritySystemView +{ + public partial class FormSecure : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + private int? _id; + private Dictionary _secureComponents; + public int Id { set { _id = value; } } + public FormSecure(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _secureComponents = new Dictionary(); + } + private void FormSecure_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new SecureSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SecureName; + textBoxPrice.Text = view.Price.ToString(); + _secureComponents = view.SecureComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_secureComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _secureComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); + if (service is FormSecureComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_secureComponents.ContainsKey(form.Id)) + { + _secureComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _secureComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); + if (service is FormSecureComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _secureComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); _secureComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); + _secureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_secureComponents == null || _secureComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new SecureBindingModel + { + Id = _id ?? 0, + SecureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SecureComponents = _secureComponents + }; + 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 _secureComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormSecure.resx b/SecuritySystem/SecuritySystemView/FormSecure.resx new file mode 100644 index 0000000..e524ea4 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs new file mode 100644 index 0000000..f49c86c --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace SecuritySystemView +{ + partial class FormSecureComponent + { + /// + /// 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() + { + labelComponentSelect = new Label(); + labelComponentsCount = new Label(); + comboBoxComponents = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponentSelect + // + labelComponentSelect.AutoSize = true; + labelComponentSelect.Location = new Point(10, 9); + labelComponentSelect.Name = "labelComponentSelect"; + labelComponentSelect.Size = new Size(91, 20); + labelComponentSelect.TabIndex = 0; + labelComponentSelect.Text = "Компонент:"; + // + // labelComponentsCount + // + labelComponentsCount.AutoSize = true; + labelComponentsCount.Location = new Point(10, 44); + labelComponentsCount.Name = "labelComponentsCount"; + labelComponentsCount.Size = new Size(93, 20); + labelComponentsCount.TabIndex = 1; + labelComponentsCount.Text = "Количество:"; + // + // comboBoxComponents + // + comboBoxComponents.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponents.FormattingEnabled = true; + comboBoxComponents.Location = new Point(109, 6); + comboBoxComponents.Name = "comboBoxComponents"; + comboBoxComponents.Size = new Size(315, 28); + comboBoxComponents.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(109, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(315, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(230, 84); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(330, 84); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSecureComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(432, 121); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponents); + Controls.Add(labelComponentsCount); + Controls.Add(labelComponentSelect); + Name = "FormSecureComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponentSelect; + private Label labelComponentsCount; + private ComboBox comboBoxComponents; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.cs b/SecuritySystem/SecuritySystemView/FormSecureComponent.cs new file mode 100644 index 0000000..c71e459 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.cs @@ -0,0 +1,85 @@ +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemView +{ + public partial class FormSecureComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponents.SelectedValue); + } + set + { + comboBoxComponents.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormSecureComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponents.DisplayMember = "ComponentName"; + comboBoxComponents.ValueMember = "Id"; + comboBoxComponents.DataSource = _list; + comboBoxComponents.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (Count <= 0) + { + MessageBox.Show("Количество должно быть больше 0", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponents.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/SecuritySystem/SecuritySystemView/FormSecureComponent.resx b/SecuritySystem/SecuritySystemView/FormSecureComponent.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.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/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs new file mode 100644 index 0000000..b3ac3b4 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs @@ -0,0 +1,122 @@ +namespace SecuritySystemView +{ + partial class FormSecures + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(3, 3); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(705, 296); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(739, 162); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 8; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefreshSecures_Click; + // + // buttonDelete + // + buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDelete.Location = new Point(739, 114); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 7; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDeleteSecure_Click; + // + // buttonEdit + // + buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEdit.Location = new Point(739, 64); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 6; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEditSecure_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(739, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAddSecure_Click; + // + // FormSecures + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(853, 311); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormSecures"; + Text = "Изделия"; + Load += FormSecures_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecures.cs b/SecuritySystem/SecuritySystemView/FormSecures.cs new file mode 100644 index 0000000..36b76ba --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.cs @@ -0,0 +1,98 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + public partial class FormSecures : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + public FormSecures(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormSecures_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["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["SecureComponents"].Visible = false; + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAddSecure_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + if (service is FormSecure form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonEditSecure_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + if (service is FormSecure form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDeleteSecure_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 SecureBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRefreshSecures_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormSecures.resx b/SecuritySystem/SecuritySystemView/FormSecures.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecures.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/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs new file mode 100644 index 0000000..e5fad2f --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -0,0 +1,51 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SecuritySystemBusinessLogic.BusinessLogics; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemListImplement.Implements; + +namespace SecuritySystemView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj b/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj new file mode 100644 index 0000000..726d3b3 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj @@ -0,0 +1,35 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/nlog.config b/SecuritySystem/SecuritySystemView/nlog.config new file mode 100644 index 0000000..036b2f8 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/nlog.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file