From 9644cb22bb754b80773283d59e7d8f10f95efc0d Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Tue, 27 Feb 2024 23:44:38 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SoftwareInstallation/SoftwareInstallation.sln | 24 ++ .../ComponentLogic.cs | 119 +++++++++ .../OrderLogic.cs | 148 +++++++++++ .../PackageLogic.cs | 143 +++++++++++ .../SoftwareInstallationBusinessLogic.csproj | 18 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../BindingModels/PackageBindingModel.cs | 21 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/IPackageLogic.cs | 20 ++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/PackageSearchModel.cs | 14 ++ .../SoftwareInstallationContracts.csproj | 18 ++ .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IPackageStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 20 ++ .../ViewModels/OrderViewModel.cs | 30 +++ .../ViewModels/PackageViewModel.cs | 24 ++ .../IComponentModel.cs | 14 ++ .../SoftwareInstallationDataModels/IId.cs | 13 + .../IOrderModel.cs | 19 ++ .../IPackageModel.cs | 15 ++ .../OrderStatus.cs | 11 + .../SoftwareInstallationDataModels.csproj | 14 ++ .../Component.cs | 41 ++++ .../ComponentStorage.cs | 108 ++++++++ .../DataListSingleton.cs | 31 +++ .../Order.cs | 56 +++++ .../OrderStorage.cs | 136 +++++++++++ .../Package.cs | 55 +++++ .../PackageStorage.cs | 123 ++++++++++ .../SoftwareInstallationListImplement.csproj | 19 ++ .../Form1.Designer.cs | 39 --- .../SoftwareInstallationView/Form1.cs | 10 - .../FormComponent.Designer.cs | 120 +++++++++ .../SoftwareInstallationView/FormComponent.cs | 95 ++++++++ .../{Form1.resx => FormComponent.resx} | 50 ++-- .../FormComponents.Designer.cs | 111 +++++++++ .../FormComponents.cs | 114 +++++++++ .../FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 146 +++++++++++ .../FormCreateOrder.cs | 132 ++++++++++ .../FormCreateOrder.resx | 120 +++++++++ .../FormMain.Designer.cs | 169 +++++++++++++ .../SoftwareInstallationView/FormMain.cs | 164 +++++++++++++ .../SoftwareInstallationView/FormMain.resx | 123 ++++++++++ .../FormPackage.Designer.cs | 222 +++++++++++++++++ .../SoftwareInstallationView/FormPackage.cs | 230 ++++++++++++++++++ .../SoftwareInstallationView/FormPackage.resx | 129 ++++++++++ .../FormPackageComponent.Designer.cs | 118 +++++++++ .../FormPackageComponent.cs | 89 +++++++ .../FormPackageComponent.resx | 120 +++++++++ .../FormPackages.Designer.cs | 112 +++++++++ .../SoftwareInstallationView/FormPackages.cs | 122 ++++++++++ .../FormPackages.resx | 120 +++++++++ .../SoftwareInstallationView/Program.cs | 43 +++- .../SoftwareInstallationView.csproj | 11 + 60 files changed, 4174 insertions(+), 76 deletions(-) create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IComponentModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IId.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/IPackageModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/OrderStatus.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDataModels/SoftwareInstallationDataModels.csproj create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Component.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/ComponentStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Order.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Package.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj delete mode 100644 SoftwareInstallation/SoftwareInstallationView/Form1.Designer.cs delete mode 100644 SoftwareInstallation/SoftwareInstallationView/Form1.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormComponent.cs rename SoftwareInstallation/SoftwareInstallationView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormComponents.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormComponents.resx create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.resx create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormMain.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormMain.resx create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackage.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackage.resx create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.resx create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackages.cs create mode 100644 SoftwareInstallation/SoftwareInstallationView/FormPackages.resx diff --git a/SoftwareInstallation/SoftwareInstallation.sln b/SoftwareInstallation/SoftwareInstallation.sln index 9941865..4cf044a 100644 --- a/SoftwareInstallation/SoftwareInstallation.sln +++ b/SoftwareInstallation/SoftwareInstallation.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.8.34525.116 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationView", "SoftwareInstallationView\SoftwareInstallationView.csproj", "{D86A164A-35C2-464D-B992-BFCE38FB2896}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationDataModels", "SoftwareInstallationDataModels\SoftwareInstallationDataModels.csproj", "{6CAFB9E0-A05C-4EE4-8035-B20EC40F97A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationContracts", "SoftwareInstallationContracts\SoftwareInstallationContracts.csproj", "{14EB070B-255F-4627-8CB9-4A24B9D3F140}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationBusinessLogic", "SoftwareInstallationBusinessLogic\SoftwareInstallationBusinessLogic.csproj", "{0AAEC0FD-D4CC-4877-AA6A-6D6C8D08A12A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationListImplement", "SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj", "{A49F0730-79D5-41CC-8A5C-CCAE4CD75DCF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {D86A164A-35C2-464D-B992-BFCE38FB2896}.Debug|Any CPU.Build.0 = Debug|Any CPU {D86A164A-35C2-464D-B992-BFCE38FB2896}.Release|Any CPU.ActiveCfg = Release|Any CPU {D86A164A-35C2-464D-B992-BFCE38FB2896}.Release|Any CPU.Build.0 = Release|Any CPU + {6CAFB9E0-A05C-4EE4-8035-B20EC40F97A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CAFB9E0-A05C-4EE4-8035-B20EC40F97A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CAFB9E0-A05C-4EE4-8035-B20EC40F97A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CAFB9E0-A05C-4EE4-8035-B20EC40F97A0}.Release|Any CPU.Build.0 = Release|Any CPU + {14EB070B-255F-4627-8CB9-4A24B9D3F140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14EB070B-255F-4627-8CB9-4A24B9D3F140}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14EB070B-255F-4627-8CB9-4A24B9D3F140}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14EB070B-255F-4627-8CB9-4A24B9D3F140}.Release|Any CPU.Build.0 = Release|Any CPU + {0AAEC0FD-D4CC-4877-AA6A-6D6C8D08A12A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0AAEC0FD-D4CC-4877-AA6A-6D6C8D08A12A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0AAEC0FD-D4CC-4877-AA6A-6D6C8D08A12A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0AAEC0FD-D4CC-4877-AA6A-6D6C8D08A12A}.Release|Any CPU.Build.0 = Release|Any CPU + {A49F0730-79D5-41CC-8A5C-CCAE4CD75DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A49F0730-79D5-41CC-8A5C-CCAE4CD75DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A49F0730-79D5-41CC-8A5C-CCAE4CD75DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A49F0730-79D5-41CC-8A5C-CCAE4CD75DCF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..872185c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs @@ -0,0 +1,119 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.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/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..0f93b79 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs @@ -0,0 +1,148 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new() { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Обновление статуса на " + newStatus.ToString() + " вызвало ошибку. Статус заказа некорректен."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + model.Sum = viewModel.Sum; + model.Count = viewModel.Count; + model.PackageId = viewModel.PackageId; + + CheckModel(model, false); + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Неудачная операция обновления статуса"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.PackageId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.PackageId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{Sum}. PackageId: {PackageId}", model.Id, model.Sum, model.PackageId); + } + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs new file mode 100644 index 0000000..009f2ea --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs @@ -0,0 +1,143 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics +{ + public class PackageLogic : IPackageLogic + { + private readonly ILogger _logger; + + private readonly IPackageStorage _packageStorage; + + public PackageLogic(ILogger logger, IPackageStorage packageStorage) + { + _logger = logger; + _packageStorage = packageStorage; + } + + public bool Create(PackageBindingModel model) + { + CheckModel(model); + + if (_packageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(PackageBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_packageStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public PackageViewModel? ReadElement(PackageSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. PackageName:{PackageName}.Id:{Id}", model.PackageName, model.Id); + + var element = _packageStorage.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(PackageSearchModel? model) + { + _logger.LogInformation("ReadList. PackageName:{PackageName}.Id:{ Id}", model?.PackageName, model?.Id); + + var list = model == null ? _packageStorage.GetFullList() : _packageStorage.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(PackageBindingModel model) + { + CheckModel(model); + + if (_packageStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(PackageBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.PackageName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.PackageName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Package. PackageName:{PackageName}.Price:{ Cost}. Id: { Id}", model.PackageName, model.Price, model.Id); + + var element = _packageStorage.GetElement(new PackageSearchModel + { + PackageName = model.PackageName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj new file mode 100644 index 0000000..1a4adac --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..42c4e7d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..5a329f7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PackageId { 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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs new file mode 100644 index 0000000..16bc0c8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class PackageBindingModel : IPackageModel + { + public int Id { get; set; } + public string PackageName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PackageComponents + { + get; + set; + } = new(); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..cb73ad1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ViewModels.ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..41bc7f7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs new file mode 100644 index 0000000..49b9995 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IPackageLogic + { + List? ReadList(PackageSearchModel? model); + PackageViewModel? ReadElement(PackageSearchModel model); + bool Create(PackageBindingModel model); + bool Update(PackageBindingModel model); + bool Delete(PackageBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..c15aff8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..b2831f6 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs new file mode 100644 index 0000000..43c90d4 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class PackageSearchModel + { + public int? Id { get; set; } + public string? PackageName { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj b/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj new file mode 100644 index 0000000..00a4658 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..14e31cc --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ViewModels.ComponentViewModel? GetElement(ComponentSearchModel model); + ViewModels.ComponentViewModel? Insert(ComponentBindingModel model); + ViewModels.ComponentViewModel? Update(ComponentBindingModel model); + ViewModels.ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..79db704 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs new file mode 100644 index 0000000..3148b30 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs @@ -0,0 +1,21 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IPackageStorage + { + List GetFullList(); + List GetFilteredList(PackageSearchModel model); + PackageViewModel? GetElement(PackageSearchModel model); + PackageViewModel? Insert(PackageBindingModel model); + PackageViewModel? Update(PackageBindingModel model); + PackageViewModel? Delete(PackageBindingModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..ce038ee --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..a328954 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int PackageId { get; set; } + [DisplayName("Изделие")] + public string PackageName { 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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs new file mode 100644 index 0000000..c2b7fd0 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.ViewModels +{ + public class PackageViewModel : IPackageModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string PackageName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary PackageComponents + { + get; + set; + } = new(); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IComponentModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IComponentModel.cs new file mode 100644 index 0000000..b8078b1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IId.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IId.cs new file mode 100644 index 0000000..4c444f5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs new file mode 100644 index 0000000..a02d9a6 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SoftwareInstallationDataModels.Enums; + +namespace SoftwareInstallationDataModels.Models +{ + public interface IOrderModel : IId + { + int PackageId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IPackageModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IPackageModel.cs new file mode 100644 index 0000000..cba5df1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IPackageModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels.Models +{ + public interface IPackageModel : IId + { + string PackageName { get; } + double Price { get; } + Dictionary PackageComponents { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/OrderStatus.cs b/SoftwareInstallation/SoftwareInstallationDataModels/OrderStatus.cs new file mode 100644 index 0000000..7cf4108 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace SoftwareInstallationDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/SoftwareInstallationDataModels.csproj b/SoftwareInstallation/SoftwareInstallationDataModels/SoftwareInstallationDataModels.csproj new file mode 100644 index 0000000..490296d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/SoftwareInstallationDataModels.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Component.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Component.cs new file mode 100644 index 0000000..e3b94c6 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Component.cs @@ -0,0 +1,41 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationListImplement.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/SoftwareInstallation/SoftwareInstallationListImplement/ComponentStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ComponentStorage.cs new file mode 100644 index 0000000..57da53e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ComponentStorage.cs @@ -0,0 +1,108 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement.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; + } + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs new file mode 100644 index 0000000..00565cd --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using SoftwareInstallationListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Packages { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Packages = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs new file mode 100644 index 0000000..562b303 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs @@ -0,0 +1,56 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class Order : IOrderModel + { + public int PackageId { 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 + { + PackageId = model.PackageId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + PackageId = PackageId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs new file mode 100644 index 0000000..c6ab2fa --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs @@ -0,0 +1,136 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + 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; + } + + 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 List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(GetViewModelName(order)); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(GetViewModelName(order)); + } + + return result; + } + + 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; + } + private OrderViewModel GetViewModelName(Order model) + { + var res = model.GetViewModel; + foreach (var package in _source.Packages) + { + if (package.Id == model.PackageId) + { + res.PackageName = package.PackageName; + break; + } + } + return res; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Package.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Package.cs new file mode 100644 index 0000000..1f55bcc --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Package.cs @@ -0,0 +1,55 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement.Models +{ + public class Package : IPackageModel + { + public int Id { get; private set; } + public string PackageName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PackageComponents + { + get; + private set; + } = new Dictionary(); + public static Package? Create(PackageBindingModel? model) + { + if (model == null) + { + return null; + } + return new Package() + { + + Id = model.Id, + PackageName = model.PackageName, + Price = model.Price, + PackageComponents = model.PackageComponents + }; + } + public void Update(PackageBindingModel? model) + { + if (model == null) + { + return; + } + PackageName = model.PackageName; + Price = model.Price; + PackageComponents = model.PackageComponents; + } + public PackageViewModel GetViewModel => new() + { + Id = Id, + PackageName = PackageName, + Price = Price, + PackageComponents = PackageComponents + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs new file mode 100644 index 0000000..927b21c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs @@ -0,0 +1,123 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class PackageStorage : IPackageStorage + { + private readonly DataListSingleton _source; + public PackageStorage() + { + _source = DataListSingleton.GetInstance(); + } + public PackageViewModel? Delete(PackageBindingModel model) + { + for (int i = 0; i < _source.Packages.Count; ++i) + { + if (_source.Packages[i].Id == model.Id) + { + var element = _source.Packages[i]; + _source.Packages.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) + { + return null; + } + + foreach (var package in _source.Packages) + { + if ((!string.IsNullOrEmpty(model.PackageName) && package.PackageName == model.PackageName) || (model.Id.HasValue && package.Id == model.Id)) + { + return package.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(PackageSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.PackageName)) + { + return result; + } + + foreach (var package in _source.Packages) + { + if (package.PackageName.Contains(model.PackageName)) + { + result.Add(package.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var package in _source.Packages) + { + result.Add(package.GetViewModel); + } + + return result; + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + model.Id = 1; + + foreach (var package in _source.Packages) + { + if (model.Id <= package.Id) + { + model.Id = package.Id + 1; + } + } + + var newPackage = Package.Create(model); + + if (newPackage == null) + { + return null; + } + + _source.Packages.Add(newPackage); + + return newPackage.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + foreach (var package in _source.Packages) + { + if (package.Id == model.Id) + { + package.Update(model); + return package.GetViewModel; + } + } + + return null; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj new file mode 100644 index 0000000..1b6acc3 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallationView/Form1.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/Form1.Designer.cs deleted file mode 100644 index ffed987..0000000 --- a/SoftwareInstallation/SoftwareInstallationView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SoftwareInstallationView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/SoftwareInstallation/SoftwareInstallationView/Form1.cs b/SoftwareInstallation/SoftwareInstallationView/Form1.cs deleted file mode 100644 index 402fe6c..0000000 --- a/SoftwareInstallation/SoftwareInstallationView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SoftwareInstallationView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs new file mode 100644 index 0000000..4990ddf --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace SoftwareInstallationView +{ + 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() + { + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Font = new Font("Segoe UI", 12F); + labelName.Location = new Point(12, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(81, 21); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Font = new Font("Segoe UI", 12F); + labelCost.Location = new Point(12, 74); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(50, 21); + labelCost.TabIndex = 1; + labelCost.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(113, 23); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(230, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(113, 76); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(156, 23); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(239, 129); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(320, 129); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(407, 164); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponent.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponent.cs new file mode 100644 index 0000000..e770518 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponent.cs @@ -0,0 +1,95 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; + + +namespace SoftwareInstallationView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation(" "); + + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception(" . ."); + } + + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/Form1.resx b/SoftwareInstallation/SoftwareInstallationView/FormComponent.resx similarity index 93% rename from SoftwareInstallation/SoftwareInstallationView/Form1.resx rename to SoftwareInstallation/SoftwareInstallationView/FormComponent.resx index 1af7de1..af32865 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Form1.resx +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs new file mode 100644 index 0000000..a622dd7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs @@ -0,0 +1,111 @@ +namespace SoftwareInstallationView +{ + 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 1); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(611, 451); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(659, 58); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(105, 42); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(659, 141); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(105, 42); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(659, 227); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(105, 42); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(659, 312); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(105, 42); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs new file mode 100644 index 0000000..60e55c7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.resx b/SoftwareInstallation/SoftwareInstallationView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/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/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..e3f35f5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace SoftwareInstallationView +{ + 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() + { + labelPackage = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxPackage = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelPackage + // + labelPackage.AutoSize = true; + labelPackage.Font = new Font("Segoe UI", 10F); + labelPackage.Location = new Point(12, 13); + labelPackage.Name = "labelPackage"; + labelPackage.Size = new Size(66, 19); + labelPackage.TabIndex = 0; + labelPackage.Text = "Изделие "; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Font = new Font("Segoe UI", 10F); + labelCount.Location = new Point(12, 47); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(82, 19); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Font = new Font("Segoe UI", 10F); + labelSum.Location = new Point(12, 83); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(52, 19); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма"; + // + // comboBoxPackage + // + comboBoxPackage.FormattingEnabled = true; + comboBoxPackage.Location = new Point(122, 9); + comboBoxPackage.Name = "comboBoxPackage"; + comboBoxPackage.Size = new Size(287, 23); + comboBoxPackage.TabIndex = 3; + comboBoxPackage.SelectedIndexChanged += comboBoxPackage_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(122, 43); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(287, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(122, 79); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(287, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(229, 114); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(96, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(331, 114); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(96, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(439, 149); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPackage); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelPackage); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelPackage; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPackage; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs new file mode 100644 index 0000000..e0c84e8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs @@ -0,0 +1,132 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPackageLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPackageLogic + logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = list; + comboBoxPackage.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void CalcSum() + { + if (comboBoxPackage.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPackage.SelectedValue); + var Package = _logicP.ReadElement(new PackageSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Package?.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 comboBoxPackage_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 (comboBoxPackage.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PackageId = Convert.ToInt32(comboBoxPackage.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/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.resx b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/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/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs new file mode 100644 index 0000000..d04428c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -0,0 +1,169 @@ +namespace SoftwareInstallationView +{ + 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(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonIssuedOrder = new Button(); + buttonOrderReady = new Button(); + buttonRefresh = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(958, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(145, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(145, 22); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(751, 395); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(785, 110); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(144, 39); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(785, 155); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(144, 39); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(785, 245); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(144, 39); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(785, 200); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(144, 39); + buttonOrderReady.TabIndex = 5; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(785, 290); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(144, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(958, 439); + Controls.Add(buttonRefresh); + Controls.Add(buttonOrderReady); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "FormMain"; + 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 компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonIssuedOrder; + private Button buttonOrderReady; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs new file mode 100644 index 0000000..c0d136d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -0,0 +1,164 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + 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["PackageId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void изделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPackages)); + + if (service is FormPackages 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/SoftwareInstallation/SoftwareInstallationView/FormMain.resx b/SoftwareInstallation/SoftwareInstallationView/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/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/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs new file mode 100644 index 0000000..e05be79 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs @@ -0,0 +1,222 @@ +namespace SoftwareInstallationView +{ + partial class FormPackage + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + componentsGroupBox = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + componentsDataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + componentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)componentsDataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 57); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(67, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость"; + // + // textBoxName + // + textBoxName.Location = new Point(85, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(326, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(85, 54); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(186, 23); + textBoxPrice.TabIndex = 3; + // + // componentsGroupBox + // + componentsGroupBox.Controls.Add(buttonRefresh); + componentsGroupBox.Controls.Add(buttonDelete); + componentsGroupBox.Controls.Add(buttonUpdate); + componentsGroupBox.Controls.Add(buttonAdd); + componentsGroupBox.Controls.Add(componentsDataGridView); + componentsGroupBox.Location = new Point(12, 98); + componentsGroupBox.Name = "componentsGroupBox"; + componentsGroupBox.Size = new Size(672, 340); + componentsGroupBox.TabIndex = 4; + componentsGroupBox.TabStop = false; + componentsGroupBox.Text = "Компоненты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(541, 241); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(113, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(541, 193); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(113, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(541, 140); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(113, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(541, 90); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // componentsDataGridView + // + componentsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + componentsDataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount }); + componentsDataGridView.Location = new Point(0, 19); + componentsDataGridView.Name = "componentsDataGridView"; + componentsDataGridView.Size = new Size(521, 321); + componentsDataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnComponent + // + ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Location = new Point(465, 457); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(100, 25); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(584, 457); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(100, 25); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormPackage + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(705, 494); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(componentsGroupBox); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormPackage"; + Text = "FormPackage"; + Load += FormPackage_Load; + componentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)componentsDataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox componentsGroupBox; + private DataGridView componentsDataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs new file mode 100644 index 0000000..660f561 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs @@ -0,0 +1,230 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormPackage : Form + { + private readonly ILogger _logger; + private readonly IPackageLogic _logic; + private int? _id; + private Dictionary _PackageComponents; + public int Id { set { _id = value; } } + public FormPackage(ILogger logger, IPackageLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _PackageComponents = new Dictionary(); + } + private void FormPackage_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PackageSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PackageName; + textBoxPrice.Text = view.Price.ToString(); + _PackageComponents = view.PackageComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_PackageComponents != null) + { + componentsDataGridView.Rows.Clear(); + foreach (var pc in _PackageComponents) + { + componentsDataGridView.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(FormPackageComponent)); + if (service is FormPackageComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_PackageComponents.ContainsKey(form.Id)) + { + _PackageComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _PackageComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (componentsDataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); + if (service is FormPackageComponent form) + { + int id = + Convert.ToInt32(componentsDataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _PackageComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _PackageComponents[form.Id] = (form.ComponentModel, + form.Count); + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (componentsDataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", componentsDataGridView.SelectedRows[0].Cells[1].Value); + _PackageComponents?.Remove(Convert.ToInt32(componentsDataGridView.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 (_PackageComponents == null || _PackageComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PackageBindingModel + { + Id = _id ?? 0, + PackageName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PackageComponents = _PackageComponents + }; + 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 _PackageComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackage.resx b/SoftwareInstallation/SoftwareInstallationView/FormPackage.resx new file mode 100644 index 0000000..524a4e1 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackage.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/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs new file mode 100644 index 0000000..62406d4 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace SoftwareInstallationView +{ + partial class FormPackageComponent + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(301, 117); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(392, 117); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 29); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(59, 15); + labelComponent.TabIndex = 2; + labelComponent.Text = "Название"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 82); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(72, 15); + labelCount.TabIndex = 3; + labelCount.Text = "Количество"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 26); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(364, 23); + comboBoxComponent.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 79); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(364, 23); + textBoxCount.TabIndex = 5; + // + // FormPackageComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(479, 151); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormPackageComponent"; + Text = "Компоненты изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.cs new file mode 100644 index 0000000..efc6c44 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.cs @@ -0,0 +1,89 @@ +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormPackageComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormPackageComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.resx b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.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/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs new file mode 100644 index 0000000..9361772 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs @@ -0,0 +1,112 @@ +namespace SoftwareInstallationView +{ + partial class FormPackages + { + /// + /// 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(); + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(552, 460); + dataGridView.TabIndex = 0; + // + // button1 + // + button1.Location = new Point(570, 104); + button1.Name = "button1"; + button1.Size = new Size(137, 36); + button1.TabIndex = 1; + button1.Text = "Добавить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonAdd_Click; + // + // button2 + // + button2.Location = new Point(570, 175); + button2.Name = "button2"; + button2.Size = new Size(137, 36); + button2.TabIndex = 2; + button2.Text = "Изменить"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonUpdate_Click; + // + // button3 + // + button3.Location = new Point(570, 248); + button3.Name = "button3"; + button3.Size = new Size(137, 36); + button3.TabIndex = 3; + button3.Text = "Удалить"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonDelete_Click; + // + // button4 + // + button4.Location = new Point(570, 319); + button4.Name = "button4"; + button4.Size = new Size(137, 36); + button4.TabIndex = 4; + button4.Text = "Обновить "; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonRefresh_Click; + // + // FormPackages + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(728, 463); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(dataGridView); + Name = "FormPackages"; + Text = "Изделия"; + Load += FormPackages_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button button1; + private Button button2; + private Button button3; + private Button button4; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs new file mode 100644 index 0000000..88ae4b8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs @@ -0,0 +1,122 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormPackages : Form + { + private readonly ILogger _logger; + private readonly IPackageLogic _logic; + + public FormPackages(ILogger logger, IPackageLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + LoadData(); + } + + private void FormPackages_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["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PackageComponents"].Visible = false; + } + + _logger.LogInformation("Загрузка изделий"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + + if (service is FormPackage form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + + if (service is FormPackage form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + + try + { + if (!_logic.Delete(new PackageBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + 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/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx b/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.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/SoftwareInstallation/SoftwareInstallationView/Program.cs b/SoftwareInstallation/SoftwareInstallationView/Program.cs index 8727ef8..22c33ab 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationView/Program.cs @@ -1,7 +1,19 @@ -namespace SoftwareInstallationView +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SoftwareInstallationBusinessLogic.BusinessLogics; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationListImplement; +using SoftwareInstallationListImplement.Implements; +using SoftwareInstallationView; + +namespace SoftwareInstallation { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -10,8 +22,35 @@ namespace SoftwareInstallationView { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj b/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj index 663fdb8..2ac7669 100644 --- a/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj +++ b/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file