From 9e907e15cacd60a927128ffb0828f89676e409ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Mon, 12 Feb 2024 20:09:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=201=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 119 +++++++++ .../BusinessLogics/OrderLogic.cs | 112 +++++++++ .../BusinessLogics/RepairLogic.cs | 118 +++++++++ .../CarRepairShopBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 17 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../BindingModels/RepairBindingModel.cs | 17 ++ .../IComponentLogic.cs | 21 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 21 ++ .../BusinessLogicsContracts/IRepairLogic.cs | 21 ++ .../CarRepairShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/RepairSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 22 ++ .../StoragesContracts/IRepairStorage.cs | 22 ++ .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 39 +++ .../ViewModels/RepairViewModel.cs | 23 ++ .../CarRepairShopDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 13 + CarRepairShop/CarRepairShopDataModels/IId.cs | 14 ++ .../Models/IComponentModel.cs | 16 ++ .../Models/IOrderModel.cs | 20 ++ .../Models/IRepairModel.cs | 16 ++ .../CarRepairShopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 28 +++ .../Implements/ComponentStorage.cs | 102 ++++++++ .../Implements/OrderStorage.cs | 110 +++++++++ .../Implements/RepairStorage.cs | 106 ++++++++ .../Models/Component.cs | 46 ++++ .../Models/Order.cs | 72 ++++++ .../Models/Repair.cs | 51 ++++ .../CarRepairShopView.csproj | 24 ++ .../CarRepairShopView/Form1.Designer.cs | 39 --- CarRepairShop/CarRepairShopView/Form1.cs | 10 - .../FormComponent.Designer.cs | 118 +++++++++ .../CarRepairShopView/FormComponent.cs | 92 +++++++ .../{Form1.resx => FormComponent.resx} | 52 ++-- .../FormComponents.Designer.cs | 120 +++++++++ .../CarRepairShopView/FormComponents.cs | 109 ++++++++ .../CarRepairShopView/FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 145 +++++++++++ .../CarRepairShopView/FormCreateOrder.cs | 118 +++++++++ .../CarRepairShopView/FormCreateOrder.resx | 120 +++++++++ .../CarRepairShopView/FormMain.Designer.cs | 181 ++++++++++++++ CarRepairShop/CarRepairShopView/FormMain.cs | 170 +++++++++++++ CarRepairShop/CarRepairShopView/FormMain.resx | 123 ++++++++++ .../CarRepairShopView/FormRepair.Designer.cs | 232 ++++++++++++++++++ CarRepairShop/CarRepairShopView/FormRepair.cs | 213 ++++++++++++++++ .../CarRepairShopView/FormRepair.resx | 129 ++++++++++ .../FormRepairComponent.Designer.cs | 119 +++++++++ .../CarRepairShopView/FormRepairComponent.cs | 79 ++++++ .../FormRepairComponent.resx | 120 +++++++++ .../CarRepairShopView/FormRepairs.Designer.cs | 118 +++++++++ .../CarRepairShopView/FormRepairs.cs | 111 +++++++++ .../CarRepairShopView/FormRepairs.resx | 120 +++++++++ CarRepairShop/CarRepairShopView/Program.cs | 40 ++- CarRepairShop/CarRepairShopView/nlog.config | 13 + 61 files changed, 4089 insertions(+), 77 deletions(-) create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj create mode 100644 CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IId.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IComponentModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IRepairModel.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj create mode 100644 CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Component.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Order.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Repair.cs delete mode 100644 CarRepairShop/CarRepairShopView/Form1.Designer.cs delete mode 100644 CarRepairShop/CarRepairShopView/Form1.cs create mode 100644 CarRepairShop/CarRepairShopView/FormComponent.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormComponent.cs rename CarRepairShop/CarRepairShopView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 CarRepairShop/CarRepairShopView/FormComponents.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormComponents.cs create mode 100644 CarRepairShop/CarRepairShopView/FormComponents.resx create mode 100644 CarRepairShop/CarRepairShopView/FormCreateOrder.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormCreateOrder.cs create mode 100644 CarRepairShop/CarRepairShopView/FormCreateOrder.resx create mode 100644 CarRepairShop/CarRepairShopView/FormMain.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormMain.cs create mode 100644 CarRepairShop/CarRepairShopView/FormMain.resx create mode 100644 CarRepairShop/CarRepairShopView/FormRepair.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepair.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepair.resx create mode 100644 CarRepairShop/CarRepairShopView/FormRepairComponent.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepairComponent.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepairComponent.resx create mode 100644 CarRepairShop/CarRepairShopView/FormRepairs.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepairs.cs create mode 100644 CarRepairShop/CarRepairShopView/FormRepairs.resx create mode 100644 CarRepairShop/CarRepairShopView/nlog.config diff --git a/CarRepairShop/CarRepairShop.sln b/CarRepairShop/CarRepairShop.sln index 4957771..e51a873 100644 --- a/CarRepairShop/CarRepairShop.sln +++ b/CarRepairShop/CarRepairShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33829.357 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopView", "CarRepairShopView\CarRepairShopView.csproj", "{4D2D0140-FDA9-4052-ACF8-55C1DBF28815}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopView", "CarRepairShopView\CarRepairShopView.csproj", "{4D2D0140-FDA9-4052-ACF8-55C1DBF28815}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopDataModels", "CarRepairShopDataModels\CarRepairShopDataModels.csproj", "{A5A93D7C-8BCD-4FB9-BA33-5295FD7CBA56}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopContracts", "CarRepairShopContracts\CarRepairShopContracts.csproj", "{5CCE112B-8C32-4B40-AF0C-9E07F0AA57E6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopBusinessLogic", "CarRepairShopBusinessLogic\CarRepairShopBusinessLogic.csproj", "{7812DC03-21D5-46ED-BAB3-8D19A8062978}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopListImplement", "CarRepairShopListImplement\CarRepairShopListImplement.csproj", "{5EFAC810-3F87-4A67-B741-57B5766B4D29}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {4D2D0140-FDA9-4052-ACF8-55C1DBF28815}.Debug|Any CPU.Build.0 = Debug|Any CPU {4D2D0140-FDA9-4052-ACF8-55C1DBF28815}.Release|Any CPU.ActiveCfg = Release|Any CPU {4D2D0140-FDA9-4052-ACF8-55C1DBF28815}.Release|Any CPU.Build.0 = Release|Any CPU + {A5A93D7C-8BCD-4FB9-BA33-5295FD7CBA56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5A93D7C-8BCD-4FB9-BA33-5295FD7CBA56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5A93D7C-8BCD-4FB9-BA33-5295FD7CBA56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5A93D7C-8BCD-4FB9-BA33-5295FD7CBA56}.Release|Any CPU.Build.0 = Release|Any CPU + {5CCE112B-8C32-4B40-AF0C-9E07F0AA57E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CCE112B-8C32-4B40-AF0C-9E07F0AA57E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CCE112B-8C32-4B40-AF0C-9E07F0AA57E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CCE112B-8C32-4B40-AF0C-9E07F0AA57E6}.Release|Any CPU.Build.0 = Release|Any CPU + {7812DC03-21D5-46ED-BAB3-8D19A8062978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7812DC03-21D5-46ED-BAB3-8D19A8062978}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7812DC03-21D5-46ED-BAB3-8D19A8062978}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7812DC03-21D5-46ED-BAB3-8D19A8062978}.Release|Any CPU.Build.0 = Release|Any CPU + {5EFAC810-3F87-4A67-B741-57B5766B4D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5EFAC810-3F87-4A67-B741-57B5766B4D29}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5EFAC810-3F87-4A67-B741-57B5766B4D29}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5EFAC810-3F87-4A67-B741-57B5766B4D29}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..2b21d28 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,119 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.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. Component:{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 is 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); + 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/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..a24ea8f --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,112 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogInformation("Create operation failed"); + return false; + } + + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + + if(model.Status + 1 != newStatus) + { + _logger.LogInformation("Status update operation failed. Incorrect order status"); + return false; + } + model.Status = newStatus; + if(model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + if(_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if(model.Id < 0) + { + throw new ArgumentNullException("Некорректный номер заказа", nameof(model.Id)); + } + if (model.Count < 1) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if(model.Sum < 1) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id:{Id}. Sum:{Sum}. Count:{Count}", model.Id, model.Sum, model.Count); + } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs new file mode 100644 index 0000000..18819a3 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs @@ -0,0 +1,118 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class RepairLogic : IRepairLogic + { + private readonly ILogger _logger; + private readonly IRepairStorage _repairStorage; + + public RepairLogic(ILogger logger, IRepairStorage repairStorage) + { + _logger = logger; + _repairStorage = repairStorage; + } + + public List? ReadList(RepairSearchModel? model) + { + _logger.LogInformation("ReadList. RepairName:{RepairName}. Id:{Id}", model?.RepairName, model?.Id); + var list = model == null ? _repairStorage.GetFullList() : _repairStorage.GetFilteredList(model); + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public RepairViewModel? ReadElement(RepairSearchModel model) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. RepairName:{RepairName}. Id:{Id}", model.RepairName, model.Id); + var element = _repairStorage.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(RepairBindingModel model) + { + CheckModel(model); + if (_repairStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(RepairBindingModel model) + { + CheckModel(model, false); + if(_repairStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(RepairBindingModel model) + { + CheckModel(model); + if(_repairStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(RepairBindingModel model, bool withParams = true) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if(string.IsNullOrEmpty(model.RepairName)) + { + throw new ArgumentNullException("Нет названия продукта", nameof(model.RepairName)); + } + if(model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Repair. RepairName:{RepairName}. Price:{Price}. Id:{Id}", model.RepairName, model.Price, model.Id); + var element = _repairStorage.GetElement(new RepairSearchModel + { + RepairName = model.RepairName + }); + if(element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj b/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj new file mode 100644 index 0000000..fc431b7 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/CarRepairShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..c56b384 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..857b043 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int RepairId { get; set; } + public string RepairName { get; set; } = string.Empty; + 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/CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs new file mode 100644 index 0000000..675bb3c --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/RepairBindingModel.cs @@ -0,0 +1,17 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BindingModels +{ + public class RepairBindingModel : IRepairModel + { + public int Id { get; set; } + public string RepairName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary RepairComponents { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..71b11e0 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..8abf58f --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs new file mode 100644 index 0000000..71d2813 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IRepairLogic.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IRepairLogic + { + List? ReadList(RepairSearchModel? model); + RepairViewModel? ReadElement(RepairSearchModel model); + + bool Create(RepairBindingModel model); + bool Update(RepairBindingModel model); + bool Delete(RepairBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj new file mode 100644 index 0000000..215400f --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..96a7212 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..1344f19 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs new file mode 100644 index 0000000..a302c57 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/RepairSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class RepairSearchModel + { + public int? Id { get; set; } + public string? RepairName { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..d9a2350 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..92489ab --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs new file mode 100644 index 0000000..a5a0c7c --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IRepairStorage.cs @@ -0,0 +1,22 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IRepairStorage + { + List GetFullList(); + List GetFilteredList(RepairSearchModel model); + + RepairViewModel? GetElement(RepairSearchModel model); + RepairViewModel? Insert(RepairBindingModel model); + RepairViewModel? Update(RepairBindingModel model); + RepairViewModel? Delete(RepairBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..c7c54ef --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..114fcb3 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,39 @@ + +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int RepairId { get; set; } + + [DisplayName("Ремонт")] + public string RepairName { 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/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs new file mode 100644 index 0000000..ee30f01 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs @@ -0,0 +1,23 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class RepairViewModel : IRepairModel + { + public int Id { get; set; } + + [DisplayName("Название ремонта")] + public string RepairName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary RepairComponents { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/CarRepairShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs b/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..8c68e17 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,13 @@ +namespace CarRepairShopDataModels.Enums; +public enum OrderStatus +{ + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 +} diff --git a/CarRepairShop/CarRepairShopDataModels/IId.cs b/CarRepairShop/CarRepairShopDataModels/IId.cs new file mode 100644 index 0000000..5f3bce2 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IId.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels +{ + public interface IId + { + int Id { get; } + + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IComponentModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..6eda247 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..db50e6c --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using CarRepairShopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface IOrderModel : IId + { + int RepairId { get; } + string RepairName { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IRepairModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IRepairModel.cs new file mode 100644 index 0000000..2b153cc --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IRepairModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface IRepairModel : IId + { + string RepairName { get; } + double Price { get; } + Dictionary RepairComponents { get; } + + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj new file mode 100644 index 0000000..e49be3f --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..5e8c8c1 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Repairs { get; set; } + public List Orders { get; set; } + + private DataListSingleton() + { + Components = new List(); + Repairs = new List(); + Orders = new List(); + } + + public static DataListSingleton GetInstance() + { + if(_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..53c3a1e --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; + + +namespace CarRepairShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach(var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach(var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if(string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach(var component in _source.Components) + { + if((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach(var component in _source.Components) + { + if(model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if(newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach(var component in _source.Components) + { + if(component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for(int i = 0; i < _source.Components.Count; i++) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..4f5649b --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,110 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach(var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if(order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if(!model.Id.HasValue) + { + return null; + } + foreach(var order in _source.Orders) + { + if(order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach(var order in _source.Orders) + { + if(model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if(newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach(var order in _source.Orders) + { + if(order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for(int i = 0;i< _source.Orders.Count; i++) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..32910f4 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/RepairStorage.cs @@ -0,0 +1,106 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class RepairStorage : IRepairStorage + { + private readonly DataListSingleton _source; + public RepairStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach(var Repair in _source.Repairs) + { + result.Add(Repair.GetViewModel); + } + return result; + } + public List GetFilteredList(RepairSearchModel model) + { + var result = new List(); + if(string.IsNullOrEmpty(model.RepairName)) + { + return result; + } + foreach(var Repair in _source.Repairs) + { + if(Repair.RepairName.Contains(model.RepairName)) + { + result.Add(Repair.GetViewModel); + } + } + return result; + } + public RepairViewModel? GetElement(RepairSearchModel model) + { + if(string.IsNullOrEmpty(model.RepairName) && !model.Id.HasValue) + { + return null; + } + foreach(var Repair in _source.Repairs) + { + if((!string.IsNullOrEmpty(model.RepairName) && model.RepairName == Repair.RepairName) || (model.Id.HasValue && Repair.Id == model.Id)) + { + return Repair.GetViewModel; + } + } + return null; + } + public RepairViewModel? Insert(RepairBindingModel model) + { + model.Id = 1; + foreach(var Repair in _source.Repairs) + { + if(model.Id <= Repair.Id) + { + model.Id = Repair.Id + 1; + } + } + var newRepair = Repair.Create(model); + if(newRepair == null) + { + return null; + } + _source.Repairs.Add(newRepair); + return newRepair.GetViewModel; + } + public RepairViewModel? Update(RepairBindingModel model) + { + foreach(var Repair in _source.Repairs) + { + if(Repair.Id == model.Id) + { + Repair.Update(model); + return Repair.GetViewModel; + } + } + return null; + } + public RepairViewModel? Delete(RepairBindingModel model) + { + for(int i = 0; i< _source.Repairs.Count; i++) + { + if (_source.Repairs[i].Id == model.Id) + { + var element = _source.Repairs[i]; + _source.Repairs.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Component.cs b/CarRepairShop/CarRepairShopListImplement/Models/Component.cs new file mode 100644 index 0000000..bc747d0 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.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/CarRepairShop/CarRepairShopListImplement/Models/Order.cs b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs new file mode 100644 index 0000000..6332d2e --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs @@ -0,0 +1,72 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int RepairId { get; private set; } + public string RepairName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if(model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + RepairId = model.RepairId, + RepairName = model.RepairName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + RepairId = RepairId, + RepairName = RepairName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs new file mode 100644 index 0000000..edf3639 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Repair.cs @@ -0,0 +1,51 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class Repair + { + public int Id { get; private set; } + public string RepairName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary RepairComponents { get; private set; } = new Dictionary(); + + public static Repair? Create(RepairBindingModel? model) + { + if(model == null) + { + return null; + } + return new Repair() + { + Id = model.Id, + RepairName = model.RepairName, + Price = model.Price, + RepairComponents = model.RepairComponents + }; + } + public void Update(RepairBindingModel? model) + { + if(model == null) + { + return; + } + RepairName = model.RepairName; + Price = model.Price; + RepairComponents = model.RepairComponents; + } + public RepairViewModel GetViewModel => new() + { + Id = Id, + RepairName = RepairName, + Price = Price, + RepairComponents = RepairComponents + }; + } +} diff --git a/CarRepairShop/CarRepairShopView/CarRepairShopView.csproj b/CarRepairShop/CarRepairShopView/CarRepairShopView.csproj index b57c89e..a8fea21 100644 --- a/CarRepairShop/CarRepairShopView/CarRepairShopView.csproj +++ b/CarRepairShop/CarRepairShopView/CarRepairShopView.csproj @@ -8,4 +8,28 @@ enable + + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/Form1.Designer.cs b/CarRepairShop/CarRepairShopView/Form1.Designer.cs deleted file mode 100644 index df06bb8..0000000 --- a/CarRepairShop/CarRepairShopView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CarRepairShopView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/Form1.cs b/CarRepairShop/CarRepairShopView/Form1.cs deleted file mode 100644 index fad8a7c..0000000 --- a/CarRepairShop/CarRepairShopView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CarRepairShopView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormComponent.Designer.cs b/CarRepairShop/CarRepairShopView/FormComponent.Designer.cs new file mode 100644 index 0000000..bd5b5cb --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace CarRepairShopView +{ + 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() + { + textBoxName = new TextBox(); + label1 = new Label(); + label2 = new Label(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(78, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(247, 23); + textBoxName.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(10, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 1; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(10, 44); + label2.Name = "label2"; + label2.Size = new Size(38, 15); + label2.TabIndex = 2; + label2.Text = "Цена:"; + // + // textBoxCost + // + textBoxCost.Location = new Point(78, 41); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(124, 23); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(165, 70); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(77, 30); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(248, 71); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(77, 30); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(335, 113); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private Label label1; + private Label label2; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormComponent.cs b/CarRepairShop/CarRepairShopView/FormComponent.cs new file mode 100644 index 0000000..1aa985a --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormComponent.cs @@ -0,0 +1,92 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + 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/CarRepairShop/CarRepairShopView/Form1.resx b/CarRepairShop/CarRepairShopView/FormComponent.resx similarity index 93% rename from CarRepairShop/CarRepairShopView/Form1.resx rename to CarRepairShop/CarRepairShopView/FormComponent.resx index 1af7de1..a395bff 100644 --- a/CarRepairShop/CarRepairShopView/Form1.resx +++ b/CarRepairShop/CarRepairShopView/FormComponent.resx @@ -1,24 +1,24 @@  - diff --git a/CarRepairShop/CarRepairShopView/FormComponents.Designer.cs b/CarRepairShop/CarRepairShopView/FormComponents.Designer.cs new file mode 100644 index 0000000..798e3ac --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormComponents.Designer.cs @@ -0,0 +1,120 @@ +namespace CarRepairShopView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(618, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(651, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 35); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(651, 62); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(118, 35); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(651, 113); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(118, 35); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(651, 163); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(118, 35); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(792, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormComponents.cs b/CarRepairShop/CarRepairShopView/FormComponents.cs new file mode 100644 index 0000000..5a9f1c6 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormComponents.cs @@ -0,0 +1,109 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + 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 buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormComponents.resx b/CarRepairShop/CarRepairShopView/FormComponents.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/CarRepairShop/CarRepairShopView/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/CarRepairShop/CarRepairShopView/FormCreateOrder.Designer.cs b/CarRepairShop/CarRepairShopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..7e0bc17 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace CarRepairShopView +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + comboBoxRepair = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(10, 11); + label1.Name = "label1"; + label1.Size = new Size(51, 15); + label1.TabIndex = 0; + label1.Text = "Ремонт:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(10, 42); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(10, 69); + label3.Name = "label3"; + label3.Size = new Size(48, 15); + label3.TabIndex = 2; + label3.Text = "Сумма:"; + // + // comboBoxRepair + // + comboBoxRepair.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRepair.FormattingEnabled = true; + comboBoxRepair.Location = new Point(98, 8); + comboBoxRepair.Name = "comboBoxRepair"; + comboBoxRepair.Size = new Size(249, 23); + comboBoxRepair.TabIndex = 3; + comboBoxRepair.SelectedIndexChanged += comboBoxRepair_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(98, 37); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(249, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(98, 66); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(249, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(150, 95); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(90, 26); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(246, 95); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(90, 26); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(361, 130); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxRepair); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxRepair; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormCreateOrder.cs b/CarRepairShop/CarRepairShopView/FormCreateOrder.cs new file mode 100644 index 0000000..bb591d3 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormCreateOrder.cs @@ -0,0 +1,118 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopListImplement.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logicR; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IRepairLogic logicR, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicR = logicR; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка ремонта для заказа"); + var _list = _logicR.ReadList(null); + if (_list != null) + { + comboBoxRepair.DisplayMember = "RepairName"; + comboBoxRepair.ValueMember = "Id"; + comboBoxRepair.DataSource = _list; + comboBoxRepair.SelectedItem = null; + } + } + + private void CalcSum() + { + if (comboBoxRepair.SelectedItem != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxRepair.SelectedValue); + var repair = _logicR.ReadElement(new RepairSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (repair?.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 comboBoxRepair_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 (comboBoxRepair.SelectedValue == null) + { + MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + RepairId = Convert.ToInt32(comboBoxRepair.SelectedValue), + RepairName = comboBoxRepair.Text, + 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/CarRepairShop/CarRepairShopView/FormCreateOrder.resx b/CarRepairShop/CarRepairShopView/FormCreateOrder.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/CarRepairShop/CarRepairShopView/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/CarRepairShop/CarRepairShopView/FormMain.Designer.cs b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs new file mode 100644 index 0000000..ec5b8c0 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs @@ -0,0 +1,181 @@ +namespace CarRepairShopView +{ + 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1059, 24); + menuStrip1.TabIndex = 0; + menuStrip1.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.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 27); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(827, 349); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(844, 54); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(198, 28); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(844, 108); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(198, 28); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(844, 162); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(198, 28); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(844, 214); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(198, 28); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(844, 269); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(198, 28); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1059, 377); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Автомастерская"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs new file mode 100644 index 0000000..545de3d --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -0,0 +1,170 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + 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("Загрузка заказов"); + var _list = _orderLogic.ReadList(null); + if (_list != null) + { + dataGridView.DataSource = _list; + dataGridView.Columns["RepairId"].Visible = false; + } + } + + 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(FormRepairs)); + if (service is FormRepairs 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, + RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value), + RepairName = dataGridView.SelectedRows[0].Cells["RepairName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void 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, + RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value), + RepairName = dataGridView.SelectedRows[0].Cells["RepairName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Доп информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void 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, + RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value), + RepairName = dataGridView.SelectedRows[0].Cells["RepairName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Доп информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдаче заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormMain.resx b/CarRepairShop/CarRepairShopView/FormMain.resx new file mode 100644 index 0000000..5203d24 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/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/CarRepairShop/CarRepairShopView/FormRepair.Designer.cs b/CarRepairShop/CarRepairShopView/FormRepair.Designer.cs new file mode 100644 index 0000000..c6a589b --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepair.Designer.cs @@ -0,0 +1,232 @@ +namespace CarRepairShopView +{ + partial class FormRepair + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 16); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 45); + label2.Name = "label2"; + label2.Size = new Size(70, 15); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(91, 13); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(273, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(91, 42); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(141, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(12, 80); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(646, 319); + groupBox1.TabIndex = 4; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(500, 178); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(118, 35); + buttonRef.TabIndex = 8; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(500, 128); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(118, 35); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(500, 77); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(118, 35); + buttonUpd.TabIndex = 6; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(500, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 35); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(469, 291); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.HeaderText = "Компонент"; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 50F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // buttonSave + // + buttonSave.Location = new Point(389, 405); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(118, 35); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(513, 405); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(118, 35); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRepair + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(670, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormRepair"; + Text = "Ремонт"; + Load += FormRepair_Load; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormRepair.cs b/CarRepairShop/CarRepairShopView/FormRepair.cs new file mode 100644 index 0000000..a9f57fa --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepair.cs @@ -0,0 +1,213 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + public partial class FormRepair : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + private int? _id; + private Dictionary _repairComponents; + public int Id { set { _id = value; } } + + public FormRepair(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _repairComponents = new Dictionary(); + } + + private void FormRepair_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка ремонта"); + try + { + var view = _logic.ReadElement(new RepairSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.RepairName; + textBoxPrice.Text = view.Price.ToString(); + _repairComponents = view.RepairComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ремонта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент ремонта"); + try + { + if (_repairComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var rc in _repairComponents) + { + dataGridView.Rows.Add(new object[] { rc.Key, rc.Value.Item1.ComponentName, rc.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(FormRepairComponent)); + if (service is FormRepairComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {componentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_repairComponents.ContainsKey(form.Id)) + { + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _repairComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + if (service is FormRepairComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _repairComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {componentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); + _repairComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonRef_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 (_repairComponents == null || _repairComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение ремонта"); + try + { + var model = new RepairBindingModel + { + Id = _id ?? 0, + RepairName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + RepairComponents = _repairComponents + }; + 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 _repairComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormRepair.resx b/CarRepairShop/CarRepairShopView/FormRepair.resx new file mode 100644 index 0000000..e524ea4 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepair.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/CarRepairShop/CarRepairShopView/FormRepairComponent.Designer.cs b/CarRepairShop/CarRepairShopView/FormRepairComponent.Designer.cs new file mode 100644 index 0000000..b68365f --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace CarRepairShopView +{ + partial class FormRepairComponent + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 9); + label1.Name = "label1"; + label1.Size = new Size(72, 15); + label1.TabIndex = 0; + label1.Text = "Компонент:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 44); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(96, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(256, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(96, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(256, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(147, 70); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(98, 28); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(254, 70); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(98, 28); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormProductComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(361, 109); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormProductComponent"; + Text = "FormProductComponent"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormRepairComponent.cs b/CarRepairShop/CarRepairShopView/FormRepairComponent.cs new file mode 100644 index 0000000..923ac47 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairComponent.cs @@ -0,0 +1,79 @@ +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.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; +using System.Xml.Serialization; + +namespace CarRepairShopView +{ + public partial class FormRepairComponent : 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 FormRepairComponent(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/CarRepairShop/CarRepairShopView/FormRepairComponent.resx b/CarRepairShop/CarRepairShopView/FormRepairComponent.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairComponent.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/CarRepairShop/CarRepairShopView/FormRepairs.Designer.cs b/CarRepairShop/CarRepairShopView/FormRepairs.Designer.cs new file mode 100644 index 0000000..4476c49 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairs.Designer.cs @@ -0,0 +1,118 @@ +namespace CarRepairShopView +{ + partial class FormRepairs + { + /// + /// 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(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(529, 457); + dataGridView.TabIndex = 0; + // + // buttonRef + // + buttonRef.Location = new Point(557, 173); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(118, 35); + buttonRef.TabIndex = 8; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(557, 123); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(118, 35); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(557, 72); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(118, 35); + buttonUpd.TabIndex = 6; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(557, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 35); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormRepairs + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(703, 457); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormRepairs"; + Text = "Ремонт"; + Load += FormRepairs_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormRepairs.cs b/CarRepairShop/CarRepairShopView/FormRepairs.cs new file mode 100644 index 0000000..2d75929 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairs.cs @@ -0,0 +1,111 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarRepairShopView +{ + public partial class FormRepairs : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + public FormRepairs(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logic = logic; + _logger = logger; + } + + private void FormRepairs_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["RepairComponents"].Visible = false; + dataGridView.Columns["RepairName"].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(FormRepair)); + if (service is FormRepair form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + if (service is FormRepair form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление ремонта"); + try + { + if (!_logic.Delete(new RepairBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ремонта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormRepairs.resx b/CarRepairShop/CarRepairShopView/FormRepairs.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormRepairs.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/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index b109aeb..98202c0 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -1,7 +1,19 @@ +using CarRepairShopBusinessLogic.BusinessLogics; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + + namespace CarRepairShopView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +23,33 @@ namespace CarRepairShopView // 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/CarRepairShop/CarRepairShopView/nlog.config b/CarRepairShop/CarRepairShopView/nlog.config new file mode 100644 index 0000000..ad1c9f1 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file