From 5679e855c6a73fd6a8b0278f31e9d16bf609463e Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 5 Apr 2024 16:29:00 +0400 Subject: [PATCH] laba 1 --- RenovationWork/RenovationWork.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 119 +++++++++ .../BusinessLogics/OrderLogic.cs | 125 +++++++++ .../BusinessLogics/RepairLogic.cs | 116 ++++++++ .../RenovationWorkBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../BindingModels/RepairBindingModel.cs | 17 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/IRepairLogic.cs | 20 ++ .../RenovationWorkContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 14 + .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/RepairSearchModel.cs | 14 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IRepairStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 37 +++ .../ViewModels/RepairViewModel.cs | 23 ++ .../Enums/OrderStatus.cs | 17 ++ .../RenovationWorkDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 14 + .../Models/IOrderModel.cs | 19 ++ .../Models/IRepairModel.cs | 15 ++ .../RenovationWorkDataModels.csproj | 9 + .../DataListSingleton.cs | 28 ++ .../Implements/ComponentStorage.cs | 113 ++++++++ .../Implements/OrderStorage.cs | 125 +++++++++ .../Implements/RepairStorage.cs | 113 ++++++++ .../Models/Component.cs | 47 ++++ .../Models/Order.cs | 62 +++++ .../Models/Repair.cs | 53 ++++ .../RenovationWorkListImplement.csproj | 14 + .../RenovationWorkView/Form1.Designer.cs | 39 --- RenovationWork/RenovationWorkView/Form1.cs | 10 - .../FormComponent.Designer.cs | 124 +++++++++ .../RenovationWorkView/FormComponent.cs | 94 +++++++ .../RenovationWorkView/FormComponent.resx | 120 +++++++++ .../FormComponents.Designer.cs | 137 ++++++++++ .../RenovationWorkView/FormComponents.cs | 120 +++++++++ .../RenovationWorkView/FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 145 ++++++++++ .../RenovationWorkView/FormCreateOrder.cs | 121 +++++++++ .../RenovationWorkView/FormCreateOrder.resx | 120 +++++++++ .../RenovationWorkView/FormMain.Designer.cs | 187 +++++++++++++ RenovationWork/RenovationWorkView/FormMain.cs | 166 ++++++++++++ .../RenovationWorkView/FormMain.resx | 120 +++++++++ .../RenovationWorkView/FormRepair.Designer.cs | 249 ++++++++++++++++++ .../RenovationWorkView/FormRepair.cs | 223 ++++++++++++++++ .../RenovationWorkView/FormRepair.resx | 120 +++++++++ .../FormRepairComponent.Designer.cs | 119 +++++++++ .../RenovationWorkView/FormRepairComponent.cs | 89 +++++++ .../FormRepairComponent.resx | 120 +++++++++ .../FormRepairs.Designer.cs | 130 +++++++++ .../RenovationWorkView/FormRepairs.cs | 116 ++++++++ .../RenovationWorkView/FormRepairs.resx | 120 +++++++++ RenovationWork/RenovationWorkView/Program.cs | 38 ++- .../RenovationWorkView.csproj | 14 + RenovationWork/RenovationWorkView/nlog.config | 15 ++ 61 files changed, 4282 insertions(+), 51 deletions(-) create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs create mode 100644 RenovationWork/RenovationWorkDataModels/IId.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj create mode 100644 RenovationWork/RenovationWorkListImplement/DataListSingleton.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Component.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Order.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Repair.cs create mode 100644 RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj delete mode 100644 RenovationWork/RenovationWorkView/Form1.Designer.cs delete mode 100644 RenovationWork/RenovationWorkView/Form1.cs create mode 100644 RenovationWork/RenovationWorkView/FormComponent.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormComponent.cs create mode 100644 RenovationWork/RenovationWorkView/FormComponent.resx create mode 100644 RenovationWork/RenovationWorkView/FormComponents.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormComponents.cs create mode 100644 RenovationWork/RenovationWorkView/FormComponents.resx create mode 100644 RenovationWork/RenovationWorkView/FormCreateOrder.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormCreateOrder.cs create mode 100644 RenovationWork/RenovationWorkView/FormCreateOrder.resx create mode 100644 RenovationWork/RenovationWorkView/FormMain.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormMain.cs create mode 100644 RenovationWork/RenovationWorkView/FormMain.resx create mode 100644 RenovationWork/RenovationWorkView/FormRepair.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepair.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepair.resx create mode 100644 RenovationWork/RenovationWorkView/FormRepairComponent.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepairComponent.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepairComponent.resx create mode 100644 RenovationWork/RenovationWorkView/FormRepairs.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepairs.cs create mode 100644 RenovationWork/RenovationWorkView/FormRepairs.resx create mode 100644 RenovationWork/RenovationWorkView/nlog.config diff --git a/RenovationWork/RenovationWork.sln b/RenovationWork/RenovationWork.sln index 0b128b6..d46131d 100644 --- a/RenovationWork/RenovationWork.sln +++ b/RenovationWork/RenovationWork.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkView", "RenovationWorkView\RenovationWorkView.csproj", "{323FC753-D640-422A-9FB3-B5472B9143A2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkView", "RenovationWorkView\RenovationWorkView.csproj", "{323FC753-D640-422A-9FB3-B5472B9143A2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkDataModels", "RenovationWorkDataModels\RenovationWorkDataModels.csproj", "{7EED58E1-0D2D-46E5-B448-B4DF2D6B9F0D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenovationWorkContracts", "RenovationWorkContracts\RenovationWorkContracts.csproj", "{69BFF4F6-D800-4AC8-966C-722B2208C382}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkBusinessLogic", "RenovationWorkBusinessLogic\RenovationWorkBusinessLogic.csproj", "{89B17498-DBE2-4AF4-92B5-50B755E96153}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenovationWorkListImplement", "RenovationWorkListImplement\RenovationWorkListImplement.csproj", "{2BCEFE6B-BE7B-45ED-A4B9-92EC6DE8E66E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {323FC753-D640-422A-9FB3-B5472B9143A2}.Debug|Any CPU.Build.0 = Debug|Any CPU {323FC753-D640-422A-9FB3-B5472B9143A2}.Release|Any CPU.ActiveCfg = Release|Any CPU {323FC753-D640-422A-9FB3-B5472B9143A2}.Release|Any CPU.Build.0 = Release|Any CPU + {7EED58E1-0D2D-46E5-B448-B4DF2D6B9F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7EED58E1-0D2D-46E5-B448-B4DF2D6B9F0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7EED58E1-0D2D-46E5-B448-B4DF2D6B9F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7EED58E1-0D2D-46E5-B448-B4DF2D6B9F0D}.Release|Any CPU.Build.0 = Release|Any CPU + {69BFF4F6-D800-4AC8-966C-722B2208C382}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69BFF4F6-D800-4AC8-966C-722B2208C382}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69BFF4F6-D800-4AC8-966C-722B2208C382}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69BFF4F6-D800-4AC8-966C-722B2208C382}.Release|Any CPU.Build.0 = Release|Any CPU + {89B17498-DBE2-4AF4-92B5-50B755E96153}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89B17498-DBE2-4AF4-92B5-50B755E96153}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89B17498-DBE2-4AF4-92B5-50B755E96153}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89B17498-DBE2-4AF4-92B5-50B755E96153}.Release|Any CPU.Build.0 = Release|Any CPU + {2BCEFE6B-BE7B-45ED-A4B9-92EC6DE8E66E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BCEFE6B-BE7B-45ED-A4B9-92EC6DE8E66E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BCEFE6B-BE7B-45ED-A4B9-92EC6DE8E66E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BCEFE6B-BE7B-45ED-A4B9-92EC6DE8E66E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..a821148 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,119 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия расходного материала", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена расходного материала должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}.Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Расходный материал с таким названием уже есть"); + } + } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..df5741a --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.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. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество ремотных работ в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Repair. RepairId:{RepairId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.RepairId, model.Count, model.Sum, model.Id); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + model.DateCreate = element.DateCreate; + model.RepairId = element.RepairId; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (requiredStatus - model.Status == 1) + { + model.Status = requiredStatus; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs new file mode 100644 index 0000000..90c6ff3 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogics/RepairLogic.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.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 Update(RepairBindingModel model) + { + CheckModel(model); + if (_RepairStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(RepairBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_RepairStorage.Delete(model) == null) + { + _logger.LogWarning("Delete 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)); + } + if (model.RepairComponents == null || model.RepairComponents.Count == 0) + { + throw new ArgumentNullException("Перечень расходых материалов не может быть пустым", nameof(model.RepairComponents)); + } + _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/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj new file mode 100644 index 0000000..424dacb --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..4b3704b --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..e9b5db5 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int RepairId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs new file mode 100644 index 0000000..ab0047c --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/RepairBindingModel.cs @@ -0,0 +1,17 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..55ac763 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkContracts.BindingModels; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..f289da4 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs new file mode 100644 index 0000000..c6a1266 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IRepairLogic.cs @@ -0,0 +1,20 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj new file mode 100644 index 0000000..96ab30f --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..6c4981f --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..6fd313e --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs new file mode 100644 index 0000000..15d1906 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/RepairSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class RepairSearchModel + { + public int? Id { get; set; } + public string? RepairName { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..d60286b --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..e418709 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs new file mode 100644 index 0000000..f4f4be3 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IRepairStorage.cs @@ -0,0 +1,21 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..4288c6b --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..75bed25 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs new file mode 100644 index 0000000..bdb1fbe --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs @@ -0,0 +1,23 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs b/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..a401b60 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/RenovationWork/RenovationWorkDataModels/IId.cs b/RenovationWork/RenovationWorkDataModels/IId.cs new file mode 100644 index 0000000..578f505 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..852d354 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..7a2279d --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using RenovationWorkDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IOrderModel : IId + { + int RepairId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs new file mode 100644 index 0000000..19080ab --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IRepairModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IRepairModel : IId + { + string RepairName { get; } + double Price { get; } + Dictionary RepairComponents { get; } + } +} diff --git a/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj b/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/RenovationWorkDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs b/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs new file mode 100644 index 0000000..74fe752 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Repairs { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Repairs = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..09db008 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,113 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RenovationWorkListImplement.Models; + +namespace RenovationWorkListImplement.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/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..aadb3f0 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs @@ -0,0 +1,125 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.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(AttachRepairName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachRepairName(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AttachRepairName(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 AttachRepairName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachRepairName(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 AttachRepairName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachRepairName(OrderViewModel model) + { + foreach (var repair in _source.Repairs) + { + if (repair.Id == model.RepairId) + { + model.RepairName = repair.RepairName; + return model; + } + } + return model; + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs new file mode 100644 index 0000000..744cef3 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs @@ -0,0 +1,113 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Implements +{ + public class RepairStorage : IRepairStorage + { + private readonly DataListSingleton _source; + + public RepairStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var repairs in _source.Repairs) + { + result.Add(repairs.GetViewModel); + } + return result; + } + + public List GetFilteredList(RepairSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.RepairName)) + { + return result; + } + foreach (var repairs in _source.Repairs) + { + if (repairs.RepairName.Contains(model.RepairName)) + { + result.Add(repairs.GetViewModel); + } + } + return result; + } + + public RepairViewModel? GetElement(RepairSearchModel model) + { + if (string.IsNullOrEmpty(model.RepairName) && !model.Id.HasValue) + { + return null; + } + foreach (var repairs in _source.Repairs) + { + if ((!string.IsNullOrEmpty(model.RepairName) && repairs.RepairName == model.RepairName) || + (model.Id.HasValue && repairs.Id == model.Id)) + { + return repairs.GetViewModel; + } + } + return null; + } + + public RepairViewModel? Insert(RepairBindingModel model) + { + model.Id = 1; + foreach (var repairs in _source.Repairs) + { + if (model.Id <= repairs.Id) + { + model.Id = repairs.Id + 1; + } + } + var newRepairs = Repair.Create(model); + if (newRepairs == null) + { + return null; + } + _source.Repairs.Add(newRepairs); + return newRepairs.GetViewModel; + } + + public RepairViewModel? Update(RepairBindingModel model) + { + foreach (var repairs in _source.Repairs) + { + if (repairs.Id == model.Id) + { + repairs.Update(model); + return repairs.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/RenovationWork/RenovationWorkListImplement/Models/Component.cs b/RenovationWork/RenovationWorkListImplement/Models/Component.cs new file mode 100644 index 0000000..f75bb46 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; private 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/RenovationWork/RenovationWorkListImplement/Models/Order.cs b/RenovationWork/RenovationWorkListImplement/Models/Order.cs new file mode 100644 index 0000000..d6ab69d --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int RepairId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + RepairId = model.RepairId, + 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; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + RepairId = RepairId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Models/Repair.cs b/RenovationWork/RenovationWorkListImplement/Models/Repair.cs new file mode 100644 index 0000000..e97649b --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Repair.cs @@ -0,0 +1,53 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Models +{ + public class Repair : IRepairModel + { + 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/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj new file mode 100644 index 0000000..2d896a8 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/RenovationWork/RenovationWorkView/Form1.Designer.cs b/RenovationWork/RenovationWorkView/Form1.Designer.cs deleted file mode 100644 index 8e0177f..0000000 --- a/RenovationWork/RenovationWorkView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace RenovationWorkView -{ - 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/RenovationWork/RenovationWorkView/Form1.cs b/RenovationWork/RenovationWorkView/Form1.cs deleted file mode 100644 index 362a7fd..0000000 --- a/RenovationWork/RenovationWorkView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace RenovationWorkView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormComponent.Designer.cs b/RenovationWork/RenovationWorkView/FormComponent.Designer.cs new file mode 100644 index 0000000..5ec9089 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormComponent.Designer.cs @@ -0,0 +1,124 @@ +namespace RenovationWorkView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(321, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(86, 32); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(117, 23); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(10, 32); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(150, 68); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(114, 30); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(287, 68); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(119, 30); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(418, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponent"; + this.Text = "Расходный материал"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormComponent.cs b/RenovationWork/RenovationWorkView/FormComponent.cs new file mode 100644 index 0000000..8b64d2a --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormComponent.cs @@ -0,0 +1,94 @@ +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; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; + +namespace RenovationWorkView +{ + 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/RenovationWork/RenovationWorkView/FormComponent.resx b/RenovationWork/RenovationWorkView/FormComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormComponents.Designer.cs b/RenovationWork/RenovationWorkView/FormComponents.Designer.cs new file mode 100644 index 0000000..9d9717d --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormComponents.Designer.cs @@ -0,0 +1,137 @@ +namespace RenovationWorkView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 320); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonUpdate); + this.ToolsPanel.Controls.Add(this.buttonDelete); + this.ToolsPanel.Controls.Add(this.buttonEdit); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(532, 9); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(158, 320); + this.ToolsPanel.TabIndex = 1; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(27, 154); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(110, 27); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(27, 106); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(110, 27); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(27, 57); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 27); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(27, 12); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponents"; + this.Text = "Расходные материалы"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormComponents.cs b/RenovationWork/RenovationWorkView/FormComponents.cs new file mode 100644 index 0000000..eae6f7f --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormComponents.cs @@ -0,0 +1,120 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + 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/RenovationWork/RenovationWorkView/FormComponents.resx b/RenovationWork/RenovationWorkView/FormComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/FormCreateOrder.Designer.cs b/RenovationWork/RenovationWorkView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..11ed3d7 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace RenovationWorkView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelRepair = new System.Windows.Forms.Label(); + this.comboBoxRepair = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelRepair + // + this.labelRepair.AutoSize = true; + this.labelRepair.Location = new System.Drawing.Point(11, 15); + this.labelRepair.Name = "labelRepair"; + this.labelRepair.Size = new System.Drawing.Size(129, 20); + this.labelRepair.TabIndex = 0; + this.labelRepair.Text = "Ремотная работа"; + // + // comboBoxRepair + // + this.comboBoxRepair.FormattingEnabled = true; + this.comboBoxRepair.Location = new System.Drawing.Point(146, 11); + this.comboBoxRepair.Name = "comboBoxRepair"; + this.comboBoxRepair.Size = new System.Drawing.Size(358, 28); + this.comboBoxRepair.TabIndex = 1; + this.comboBoxRepair.SelectedIndexChanged += new System.EventHandler(this.ComboBoxRepair_SelectedIndexChanged); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 49); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(146, 46); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(358, 27); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(11, 80); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(62, 20); + this.labelSum.TabIndex = 4; + this.labelSum.Text = "Сумма: "; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(146, 80); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(358, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(394, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 32); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(267, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 32); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(518, 157); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxRepair); + this.Controls.Add(this.labelRepair); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelRepair; + private ComboBox comboBoxRepair; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSum; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormCreateOrder.cs b/RenovationWork/RenovationWorkView/FormCreateOrder.cs new file mode 100644 index 0000000..f9742fd --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormCreateOrder.cs @@ -0,0 +1,121 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +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 RenovationWorkView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logicP; + private readonly IOrderLogic _logicO; + private List? _list; + + public FormCreateOrder(ILogger logger, IRepairLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxRepair.DisplayMember = "RepairName"; + comboBoxRepair.ValueMember = "Id"; + comboBoxRepair.DataSource = _list; + comboBoxRepair.SelectedItem = null; + _logger.LogInformation("Загрузка ремотной работы для заказа"); + } + } + + private void CalcSum() + { + if (comboBoxRepair.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxRepair.SelectedValue); + var Repair = _logicP.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), + 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/RenovationWork/RenovationWorkView/FormCreateOrder.resx b/RenovationWork/RenovationWorkView/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/FormMain.Designer.cs b/RenovationWork/RenovationWorkView/FormMain.Designer.cs new file mode 100644 index 0000000..510832a --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormMain.Designer.cs @@ -0,0 +1,187 @@ +namespace RenovationWorkView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.bookToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.consumablesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.repairsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.bookToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(1149, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // bookToolStripMenuItem + // + this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.consumablesToolStripMenuItem, + this.repairsToolStripMenuItem}); + this.bookToolStripMenuItem.Name = "bookToolStripMenuItem"; + this.bookToolStripMenuItem.Size = new System.Drawing.Size(87, 20); + this.bookToolStripMenuItem.Text = "Справочник"; + // + // consumablesToolStripMenuItem + // + this.consumablesToolStripMenuItem.Name = "consumablesToolStripMenuItem"; + this.consumablesToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.consumablesToolStripMenuItem.Text = "Расходные материалы"; + this.consumablesToolStripMenuItem.Click += new System.EventHandler(this.СonsumablesToolStripMenuItem_Click); + // + // repairsToolStripMenuItem + // + this.repairsToolStripMenuItem.Name = "repairsToolStripMenuItem"; + this.repairsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.repairsToolStripMenuItem.Text = "Ремотные работы"; + this.repairsToolStripMenuItem.Click += new System.EventHandler(this.RepairsToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 23); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(855, 286); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(898, 53); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(898, 92); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(898, 129); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(216, 22); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(898, 169); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(898, 210); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(216, 22); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1149, 319); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormMain"; + this.Text = "Ремонтные работы в помещении"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem bookToolStripMenuItem; + private ToolStripMenuItem consumablesToolStripMenuItem; + private ToolStripMenuItem repairsToolStripMenuItem; + 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/RenovationWork/RenovationWorkView/FormMain.cs b/RenovationWork/RenovationWorkView/FormMain.cs new file mode 100644 index 0000000..e0fb804 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormMain.cs @@ -0,0 +1,166 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + 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() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["RepairId"].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 СonsumablesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void RepairsToolStripMenuItem_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("Заказ No{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No{id} выдан", id); + 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/RenovationWork/RenovationWorkView/FormMain.resx b/RenovationWork/RenovationWorkView/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormMain.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/RenovationWork/RenovationWorkView/FormRepair.Designer.cs b/RenovationWork/RenovationWorkView/FormRepair.Designer.cs new file mode 100644 index 0000000..c79c23f --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepair.Designer.cs @@ -0,0 +1,249 @@ +namespace RenovationWorkView +{ + 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() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 11); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(65, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 9); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(257, 23); + this.textBoxName.TabIndex = 1; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 38); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(73, 15); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(98, 38); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(150, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(10, 63); + this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Size = new System.Drawing.Size(578, 239); + this.groupBoxComponents.TabIndex = 4; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Расходный материал"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(439, 158); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 26); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(439, 118); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 26); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(439, 76); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 26); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(439, 35); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 26); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(416, 215); + this.dataGridView.TabIndex = 0; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(450, 313); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(322, 313); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 26); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // Component + // + this.Component.HeaderText = "Расходный материал"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // FormRepair + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(599, 347); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormRepair"; + this.Text = "Ремотные работы"; + this.Load += new System.EventHandler(this.FormRepair_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelPrice; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormRepair.cs b/RenovationWork/RenovationWorkView/FormRepair.cs new file mode 100644 index 0000000..1c7ce95 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepair.cs @@ -0,0 +1,223 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + 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 pc in _RepairComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки расходного материала"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(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); + _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/RenovationWork/RenovationWorkView/FormRepair.resx b/RenovationWork/RenovationWorkView/FormRepair.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepair.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/RenovationWork/RenovationWorkView/FormRepairComponent.Designer.cs b/RenovationWork/RenovationWorkView/FormRepairComponent.Designer.cs new file mode 100644 index 0000000..ab1d7e9 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepairComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace RenovationWorkView +{ + 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() + { + this.labelComponent = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(11, 9); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(159, 20); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Расходный материал:"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(175, 9); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(355, 28); + this.comboBoxComponent.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 51); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(173, 51); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(355, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(392, 93); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 41); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(234, 93); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(136, 41); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormRepairComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(540, 147); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelComponent); + this.Name = "FormRepairComponent"; + this.Text = "Расходный материал"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormRepairComponent.cs b/RenovationWork/RenovationWorkView/FormRepairComponent.cs new file mode 100644 index 0000000..eb7b134 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepairComponent.cs @@ -0,0 +1,89 @@ +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + 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/RenovationWork/RenovationWorkView/FormRepairComponent.resx b/RenovationWork/RenovationWorkView/FormRepairComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/FormRepairs.Designer.cs b/RenovationWork/RenovationWorkView/FormRepairs.Designer.cs new file mode 100644 index 0000000..f6da734 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepairs.Designer.cs @@ -0,0 +1,130 @@ +namespace RenovationWorkView +{ + 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() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormRepairs + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormRepairs"; + this.Text = "Ремотные работы"; + this.Load += new System.EventHandler(this.FormRepair_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormRepairs.cs b/RenovationWork/RenovationWorkView/FormRepairs.cs new file mode 100644 index 0000000..8195130 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormRepairs.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RenovationWorkView +{ + public partial class FormRepairs : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + + public FormRepairs(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormRepair_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/RenovationWork/RenovationWorkView/FormRepairs.resx b/RenovationWork/RenovationWorkView/FormRepairs.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/Program.cs b/RenovationWork/RenovationWorkView/Program.cs index edebfba..b23072d 100644 --- a/RenovationWork/RenovationWorkView/Program.cs +++ b/RenovationWork/RenovationWorkView/Program.cs @@ -1,7 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using RenovationWorkBusinessLogic.BusinessLogics; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkListImplement.Implements; + namespace RenovationWorkView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +21,33 @@ namespace RenovationWorkView // 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/RenovationWork/RenovationWorkView/RenovationWorkView.csproj b/RenovationWork/RenovationWorkView/RenovationWorkView.csproj index b57c89e..40a2c82 100644 --- a/RenovationWork/RenovationWorkView/RenovationWorkView.csproj +++ b/RenovationWork/RenovationWorkView/RenovationWorkView.csproj @@ -8,4 +8,18 @@ enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/nlog.config b/RenovationWork/RenovationWorkView/nlog.config new file mode 100644 index 0000000..ba6fc48 --- /dev/null +++ b/RenovationWork/RenovationWorkView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + -- 2.25.1