From 9cdd674d2b531fc2ad3afe60fc8d6cfb71b21e47 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Mon, 12 Feb 2024 01:33:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractLawFirmBusinessLogic.csproj | 17 ++ .../BusinessLogic/ComponentLogic.cs | 116 +++++++++ .../BusinessLogic/DocumentLogic.cs | 114 +++++++++ .../BusinessLogic/OrderLogic.cs | 111 ++++++++ .../AbstractLawFirmContracts.csproj | 4 +- .../BindingModels/ComponentBindingModel.cs | 4 +- .../BindingModels/DocumentBindingModel.cs | 10 +- .../BindingModels/OrderBindingModel.cs | 6 +- .../IComponentLogic.cs | 8 +- .../BusinessLogicsContracts/IDocumentLogic.cs | 8 +- .../BusinessLogicsContracts/IOrderLogic.cs | 8 +- .../SearchModels/ComponentSearchModel.cs | 2 +- .../SearchModels/DocumentSearchModel.cs | 4 +- .../SearchModels/OrderSearchModel.cs | 2 +- .../StoragesContracts/IComponentStorage.cs | 8 +- .../StoragesContracts/IDocumentStorage.cs | 13 +- .../StoragesContracts/IOrderStorage.cs | 8 +- .../ViewModels/ComponentViewModel.cs | 6 +- .../ViewModels/DocumentViewModel.cs | 4 +- .../ViewModels/OrderViewModel.cs | 8 +- .../Enums/OrderStatus.cs | 2 +- .../AbstractLawFirmDataModels/IId.cs | 2 +- .../Models/IComponentModel.cs | 4 +- .../Models/IDocumentModel.cs | 4 +- .../Models/IOrderModel.cs | 6 +- .../AbstractLawFirmListImplement.csproj | 14 ++ .../DataListSingleton.cs | 31 +++ .../Implements/ComponentStorage.cs | 108 ++++++++ .../Implements/DocumentStorage.cs | 109 ++++++++ .../Implements/OrderStorage.cs | 118 +++++++++ .../Models/Component.cs | 47 ++++ .../Models/Document.cs | 55 ++++ .../Models/Order.cs | 65 +++++ LawFirm/LawFirm.sln | 18 +- LawFirm/LawFirmView/Form1.Designer.cs | 39 --- LawFirm/LawFirmView/Form1.cs | 10 - LawFirm/LawFirmView/FormComponent.Designer.cs | 119 +++++++++ LawFirm/LawFirmView/FormComponent.cs | 100 ++++++++ LawFirm/LawFirmView/FormComponent.resx | 60 +++++ .../LawFirmView/FormComponents.Designer.cs | 114 +++++++++ LawFirm/LawFirmView/FormComponents.cs | 124 +++++++++ LawFirm/LawFirmView/FormComponents.resx | 60 +++++ .../LawFirmView/FormCreateOrder.Designer.cs | 145 +++++++++++ LawFirm/LawFirmView/FormCreateOrder.cs | 140 +++++++++++ LawFirm/LawFirmView/FormCreateOrder.resx | 60 +++++ LawFirm/LawFirmView/FormDocument.Designer.cs | 226 +++++++++++++++++ LawFirm/LawFirmView/FormDocument.cs | 236 ++++++++++++++++++ LawFirm/LawFirmView/FormDocument.resx | 78 ++++++ .../FormDocumentComponent.Designer.cs | 119 +++++++++ LawFirm/LawFirmView/FormDocumentComponent.cs | 95 +++++++ .../LawFirmView/FormDocumentComponent.resx | 60 +++++ LawFirm/LawFirmView/FormDocuments.Designer.cs | 114 +++++++++ LawFirm/LawFirmView/FormDocuments.cs | 116 +++++++++ LawFirm/LawFirmView/FormDocuments.resx | 60 +++++ LawFirm/LawFirmView/FormMain.Designer.cs | 174 +++++++++++++ LawFirm/LawFirmView/FormMain.cs | 180 +++++++++++++ LawFirm/LawFirmView/FormMain.resx | 66 +++++ LawFirm/LawFirmView/LawFirmView.csproj | 10 + LawFirm/LawFirmView/Program.cs | 38 ++- 59 files changed, 3472 insertions(+), 115 deletions(-) create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/AbstractLawFirmBusinessLogic.csproj create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ComponentLogic.cs create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/AbstractLawFirmListImplement.csproj create mode 100644 LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Implements/ComponentStorage.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Models/Component.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Models/Document.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Models/Order.cs delete mode 100644 LawFirm/LawFirmView/Form1.Designer.cs delete mode 100644 LawFirm/LawFirmView/Form1.cs create mode 100644 LawFirm/LawFirmView/FormComponent.Designer.cs create mode 100644 LawFirm/LawFirmView/FormComponent.cs create mode 100644 LawFirm/LawFirmView/FormComponent.resx create mode 100644 LawFirm/LawFirmView/FormComponents.Designer.cs create mode 100644 LawFirm/LawFirmView/FormComponents.cs create mode 100644 LawFirm/LawFirmView/FormComponents.resx create mode 100644 LawFirm/LawFirmView/FormCreateOrder.Designer.cs create mode 100644 LawFirm/LawFirmView/FormCreateOrder.cs create mode 100644 LawFirm/LawFirmView/FormCreateOrder.resx create mode 100644 LawFirm/LawFirmView/FormDocument.Designer.cs create mode 100644 LawFirm/LawFirmView/FormDocument.cs create mode 100644 LawFirm/LawFirmView/FormDocument.resx create mode 100644 LawFirm/LawFirmView/FormDocumentComponent.Designer.cs create mode 100644 LawFirm/LawFirmView/FormDocumentComponent.cs create mode 100644 LawFirm/LawFirmView/FormDocumentComponent.resx create mode 100644 LawFirm/LawFirmView/FormDocuments.Designer.cs create mode 100644 LawFirm/LawFirmView/FormDocuments.cs create mode 100644 LawFirm/LawFirmView/FormDocuments.resx create mode 100644 LawFirm/LawFirmView/FormMain.Designer.cs create mode 100644 LawFirm/LawFirmView/FormMain.cs create mode 100644 LawFirm/LawFirmView/FormMain.resx diff --git a/LawFirm/AbstractLawFirmBusinessLogic/AbstractLawFirmBusinessLogic.csproj b/LawFirm/AbstractLawFirmBusinessLogic/AbstractLawFirmBusinessLogic.csproj new file mode 100644 index 0000000..e7fbd8e --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/AbstractLawFirmBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ComponentLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..e62b209 --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,116 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.BusinessLogic +{ + 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/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs new file mode 100644 index 0000000..60eb54e --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs @@ -0,0 +1,114 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.BusinessLogic +{ + public class DocumentLogic : IDocumentLogic + { + private readonly ILogger _logger; + private readonly IDocumentStorage _documentStorage; + public DocumentLogic(ILogger logger, IDocumentStorage + documentStorage) + { + _logger = logger; + _documentStorage = documentStorage; + } + public List? ReadList(DocumentSearchModel? model) + { + _logger.LogInformation("ReadList. DocumentName:{DocumentName}.Id:{ Id}", model?.DocumentName, model?.Id); + var list = model == null ? _documentStorage.GetFullList() : _documentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DocumentViewModel? ReadElement(DocumentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DocumentName:{DocumentName}.Id:{ Id}", model.DocumentName, model.Id); + var element = _documentStorage.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(DocumentBindingModel model) + { + CheckModel(model); + if (_documentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DocumentBindingModel model) + { + CheckModel(model); + if (_documentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DocumentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_documentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DocumentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DocumentName)) + { + throw new ArgumentNullException("Нет названия пакета документов", + nameof(model.DocumentName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена пакета документов должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Document. DocumentName:{DocumentName}.Cost:{ Cost}. Id: { Id}", model.DocumentName, model.Price, model.Id); + var element = _documentStorage.GetElement(new DocumentSearchModel + { + DocumentName = model.DocumentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пакет документов с таким названием уже есть"); + } + } + } +} diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..cf6376c --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,111 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + 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.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/AbstractLawFirmContracts.csproj b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/AbstractLawFirmContracts.csproj index a57d78e..74a87d8 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/AbstractLawFirmContracts.csproj +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/AbstractLawFirmContracts.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ComponentBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ComponentBindingModel.cs index f228855..0546eb8 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ComponentBindingModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ComponentBindingModel.cs @@ -1,11 +1,11 @@ -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BindingModels.BindingModels +namespace AbstractLawFirmContracts.BindingModels.BindingModels { public class ComponentBindingModel : IComponentModel { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/DocumentBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/DocumentBindingModel.cs index a6dc178..d4c2535 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/DocumentBindingModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/DocumentBindingModel.cs @@ -1,21 +1,17 @@ -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BindingModels +namespace AbstractLawFirmContracts.BindingModels { public class DocumentBindingModel : IDocumentModel { public int Id { get; set; } public string DocumentName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary DocumentComponents - { - get; - set; - } = new(); + public Dictionary DocumentComponents { get; set; } = new(); } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/OrderBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/OrderBindingModel.cs index 6390494..e3fa2fd 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/OrderBindingModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/OrderBindingModel.cs @@ -1,12 +1,12 @@ -using LawFirmDataModels.Enums; -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BindingModels +namespace AbstractLawFirmContracts.BindingModels { public class OrderBindingModel : IOrderModel { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IComponentLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IComponentLogic.cs index 9eb0bcf..ec69938 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -1,13 +1,13 @@ -using LawFirmContracts.BindingModels.BindingModels; -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BusinessLogicsContracts +namespace AbstractLawFirmContracts.BusinessLogicsContracts { public interface IComponentLogic { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs index aaf409e..38550db 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs @@ -1,13 +1,13 @@ -using LawFirmContracts.BindingModels; -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BusinessLogicsContracts +namespace AbstractLawFirmContracts.BusinessLogicsContracts { public interface IDocumentLogic { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs index d6a638b..ab78985 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,13 +1,13 @@ -using LawFirmContracts.BindingModels; -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.BusinessLogicsContracts +namespace AbstractLawFirmContracts.BusinessLogicsContracts { public interface IOrderLogic { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ComponentSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ComponentSearchModel.cs index 9a0c136..378b6ab 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ComponentSearchModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ComponentSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.SearchModels +namespace AbstractLawFirmContracts.SearchModels { public class ComponentSearchModel { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/DocumentSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/DocumentSearchModel.cs index c93b00c..9481c87 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/DocumentSearchModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/DocumentSearchModel.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.SearchModels +namespace AbstractLawFirmContracts.SearchModels { public class DocumentSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? DocumentName { get; set; } } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs index 13da352..d568495 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.SearchModels +namespace AbstractLawFirmContracts.SearchModels { public class OrderSearchModel { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IComponentStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IComponentStorage.cs index 1cd97bf..a1932c8 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IComponentStorage.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IComponentStorage.cs @@ -1,13 +1,13 @@ -using LawFirmContracts.BindingModels.BindingModels; -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.StoragesContracts +namespace AbstractLawFirmContracts.StoragesContracts { public interface IComponentStorage { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IDocumentStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IDocumentStorage.cs index ee76bf8..4e8e876 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IDocumentStorage.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IDocumentStorage.cs @@ -1,20 +1,21 @@ -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.StoragesContracts +namespace AbstractLawFirmContracts.StoragesContracts { public interface IDocumentStorage { List GetFullList(); List GetFilteredList(DocumentSearchModel model); DocumentViewModel? GetElement(DocumentSearchModel model); - DocumentViewModel? Insert(DocumentSearchModel model); - DocumentViewModel? Update(DocumentSearchModel model); - DocumentViewModel? Delete(DocumentSearchModel model); + DocumentViewModel? Insert(DocumentBindingModel model); + DocumentViewModel? Update(DocumentBindingModel model); + DocumentViewModel? Delete(DocumentBindingModel model); } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IOrderStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IOrderStorage.cs index f2b62b9..60e7dc1 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IOrderStorage.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IOrderStorage.cs @@ -1,13 +1,13 @@ -using LawFirmContracts.BindingModels; -using LawFirmContracts.SearchModels; -using LawFirmContracts.ViewModels; +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.StoragesContracts +namespace AbstractLawFirmContracts.StoragesContracts { public interface IOrderStorage { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ComponentViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ComponentViewModel.cs index 2008a60..0843b72 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ComponentViewModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,4 @@ -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -6,12 +6,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.ViewModels +namespace AbstractLawFirmContracts.ViewModels { public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название бланка")] + [DisplayName("Название компонента")] public string ComponentName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/DocumentViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/DocumentViewModel.cs index b1c6e52..74d0e5f 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/DocumentViewModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/DocumentViewModel.cs @@ -1,4 +1,4 @@ -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.ViewModels +namespace AbstractLawFirmContracts.ViewModels { public class DocumentViewModel : IDocumentModel { diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/OrderViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/OrderViewModel.cs index b4a1103..2acfb53 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/OrderViewModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/OrderViewModel.cs @@ -1,5 +1,5 @@ -using LawFirmDataModels.Enums; -using LawFirmDataModels.Models; +using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmContracts.ViewModels +namespace AbstractLawFirmContracts.ViewModels { public class OrderViewModel : IOrderModel { @@ -15,7 +15,7 @@ namespace LawFirmContracts.ViewModels public int Id { get; set; } public int DocumentId { get; set; } [DisplayName("Пакет документов")] - public string ProductName { get; set; } = string.Empty; + public string DocumentName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Enums/OrderStatus.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Enums/OrderStatus.cs index afb4ab0..6837f42 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Enums/OrderStatus.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Enums/OrderStatus.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmDataModels.Enums +namespace AbstractLawFirmDataModels.Enums { public enum OrderStatus { diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/IId.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/IId.cs index 1af150c..52061ba 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/IId.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/IId.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmDataModels +namespace AbstractLawFirmDataModels { public interface IId { diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IComponentModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IComponentModel.cs index 2031eb5..d2e8e39 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IComponentModel.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IComponentModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using LawFirmDataModels; +using AbstractLawFirmDataModels; -namespace LawFirmDataModels.Models +namespace AbstractLawFirmDataModels.Models { public interface IComponentModel : IId { diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IDocumentModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IDocumentModel.cs index 52039de..3e330c3 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IDocumentModel.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IDocumentModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using LawFirmDataModels; +using AbstractLawFirmDataModels; -namespace LawFirmDataModels.Models +namespace AbstractLawFirmDataModels.Models { public interface IDocumentModel : IId { diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IOrderModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IOrderModel.cs index 728eb34..126df76 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IOrderModel.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IOrderModel.cs @@ -1,12 +1,12 @@ -using LawFirmDataModels; -using LawFirmDataModels.Enums; +using AbstractLawFirmDataModels; +using AbstractLawFirmDataModels.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace LawFirmDataModels.Models +namespace AbstractLawFirmDataModels.Models { public interface IOrderModel : IId { diff --git a/LawFirm/AbstractLawFirmListImplement/AbstractLawFirmListImplement.csproj b/LawFirm/AbstractLawFirmListImplement/AbstractLawFirmListImplement.csproj new file mode 100644 index 0000000..f54052f --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/AbstractLawFirmListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs new file mode 100644 index 0000000..ca1efab --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Documents { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Documents = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..4ef797e --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.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/LawFirm/AbstractLawFirmListImplement/Implements/DocumentStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..40ffe93 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/DocumentStorage.cs @@ -0,0 +1,109 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Implements +{ + public class DocumentStorage : IDocumentStorage + { + private readonly DataListSingleton _source; + public DocumentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var document in _source.Documents) + { + result.Add(document.GetViewModel); + } + return result; + } + public List GetFilteredList(DocumentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.DocumentName)) + { + return result; + } + foreach (var document in _source.Documents) + { + if (document.DocumentName.Contains(model.DocumentName)) + { + result.Add(document.GetViewModel); + } + } + return result; + } + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + foreach (var document in _source.Documents) + { + if ((!string.IsNullOrEmpty(model.DocumentName) && + document.DocumentName == model.DocumentName) || + (model.Id.HasValue && document.Id == model.Id)) + { + return document.GetViewModel; + } + } + return null; + } + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = 1; + foreach (var document in _source.Documents) + { + if (model.Id <= document.Id) + { + model.Id = document.Id + 1; + } + } + var newDocument = Document.Create(model); + if (newDocument == null) + { + return null; + } + _source.Documents.Add(newDocument); + return newDocument.GetViewModel; + } + public DocumentViewModel? Update(DocumentBindingModel model) + { + foreach (var document in _source.Documents) + { + if (document.Id == model.Id) + { + document.Update(model); + return document.GetViewModel; + } + } + return null; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + for (int i = 0; i < _source.Documents.Count; ++i) + { + if (_source.Documents[i].Id == model.Id) + { + var element = _source.Documents[i]; + _source.Documents.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..82a0ece --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs @@ -0,0 +1,118 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using AbstractLawFirmContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.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(AccessDocumentStorage(order.GetViewModel)); + } + return result; + } + public List GetFilteredList(OrderSearchModel + model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AccessDocumentStorage(order.GetViewModel)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public OrderViewModel AccessDocumentStorage(OrderViewModel model) + { + foreach (var document in _source.Documents) + { + if (document.Id == model.DocumentId) + { + model.DocumentName = document.DocumentName; + break; + } + } + return model; + } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Component.cs b/LawFirm/AbstractLawFirmListImplement/Models/Component.cs new file mode 100644 index 0000000..f30a28d --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Document.cs b/LawFirm/AbstractLawFirmListImplement/Models/Document.cs new file mode 100644 index 0000000..9569f94 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Document.cs @@ -0,0 +1,55 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Document : IDocumentModel + { + public int Id { get; private set; } + public string DocumentName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary DocumentComponents + { + get; + private set; + } = new Dictionary(); + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + DocumentComponents = model.DocumentComponents + }; + } + public void Update(DocumentBindingModel? model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + DocumentComponents = model.DocumentComponents; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentComponents = DocumentComponents + }; + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Order.cs b/LawFirm/AbstractLawFirmListImplement/Models/Order.cs new file mode 100644 index 0000000..f2c291d --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int DocumentId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + DocumentId = model.DocumentId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + DocumentId = model.DocumentId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + DocumentId = DocumentId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + + } +} diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 3eca375..09da4ff 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -3,11 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmView", "LawFirmView\LawFirmView.csproj", "{32CEC3FF-22BE-4DCD-8955-E3B14953EA67}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmView", "LawFirmView\LawFirmView.csproj", "{32CEC3FF-22BE-4DCD-8955-E3B14953EA67}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmDataModels", "AbstractLawFirmDataModels\AbstractLawFirmDataModels\LawFirmDataModels.csproj", "{99CE17B9-0CCE-42B6-B73F-61E8D49F1AAB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmDataModels", "AbstractLawFirmDataModels\AbstractLawFirmDataModels\AbstractLawFirmDataModels.csproj", "{99CE17B9-0CCE-42B6-B73F-61E8D49F1AAB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "AbstractLawFirmContracts\AbstractLawFirmContracts\LawFirmContracts.csproj", "{C0155B2E-5974-4835-996B-6FDF0F5BC06B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmContracts", "AbstractLawFirmContracts\AbstractLawFirmContracts\AbstractLawFirmContracts.csproj", "{C0155B2E-5974-4835-996B-6FDF0F5BC06B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmBusinessLogic", "AbstractLawFirmBusinessLogic\AbstractLawFirmBusinessLogic.csproj", "{E48808B1-5381-4774-97B6-CDB107DCF98C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmListImplement", "AbstractLawFirmListImplement\AbstractLawFirmListImplement.csproj", "{86D5FC6F-B262-44A0-9D30-970F9EA93E0A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +31,14 @@ Global {C0155B2E-5974-4835-996B-6FDF0F5BC06B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C0155B2E-5974-4835-996B-6FDF0F5BC06B}.Release|Any CPU.ActiveCfg = Release|Any CPU {C0155B2E-5974-4835-996B-6FDF0F5BC06B}.Release|Any CPU.Build.0 = Release|Any CPU + {E48808B1-5381-4774-97B6-CDB107DCF98C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E48808B1-5381-4774-97B6-CDB107DCF98C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E48808B1-5381-4774-97B6-CDB107DCF98C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E48808B1-5381-4774-97B6-CDB107DCF98C}.Release|Any CPU.Build.0 = Release|Any CPU + {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmView/Form1.Designer.cs b/LawFirm/LawFirmView/Form1.Designer.cs deleted file mode 100644 index fd02f9f..0000000 --- a/LawFirm/LawFirmView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace LawFirmView -{ - 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/LawFirm/LawFirmView/Form1.cs b/LawFirm/LawFirmView/Form1.cs deleted file mode 100644 index 6a975a7..0000000 --- a/LawFirm/LawFirmView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace LawFirmView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormComponent.Designer.cs b/LawFirm/LawFirmView/FormComponent.Designer.cs new file mode 100644 index 0000000..2704664 --- /dev/null +++ b/LawFirm/LawFirmView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace LawFirmView +{ + 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(72, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(267, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(72, 55); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(143, 23); + this.textBoxCost.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(2, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 55); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(38, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Цена:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(159, 101); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + 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(264, 101); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + 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(456, 139); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxCost; + private Label label1; + private Label label2; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormComponent.cs b/LawFirm/LawFirmView/FormComponent.cs new file mode 100644 index 0000000..9e6014b --- /dev/null +++ b/LawFirm/LawFirmView/FormComponent.cs @@ -0,0 +1,100 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + 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/LawFirm/LawFirmView/FormComponent.resx b/LawFirm/LawFirmView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormComponents.Designer.cs b/LawFirm/LawFirmView/FormComponents.Designer.cs new file mode 100644 index 0000000..5c5db9f --- /dev/null +++ b/LawFirm/LawFirmView/FormComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace LawFirmView +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(439, 442); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(486, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(102, 40); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(486, 58); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(102, 41); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(486, 105); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(102, 42); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(486, 153); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(102, 39); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(632, 443); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "FormComponents"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormComponents.cs b/LawFirm/LawFirmView/FormComponents.cs new file mode 100644 index 0000000..b5111e9 --- /dev/null +++ b/LawFirm/LawFirmView/FormComponents.cs @@ -0,0 +1,124 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + 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/LawFirm/LawFirmView/FormComponents.resx b/LawFirm/LawFirmView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormCreateOrder.Designer.cs b/LawFirm/LawFirmView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..4145c5f --- /dev/null +++ b/LawFirm/LawFirmView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace LawFirmView +{ + 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.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(116, 12); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(198, 23); + this.comboBoxDocument.TabIndex = 0; + this.comboBoxDocument.SelectedIndexChanged += new System.EventHandler(this.comboBoxDocument_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(116, 41); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(198, 23); + this.textBoxCount.TabIndex = 1; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(116, 70); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(198, 23); + this.textBoxSum.TabIndex = 2; + this.textBoxSum.TextChanged += new System.EventHandler(this.textBoxSum_TextChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 15); + this.label1.TabIndex = 3; + this.label1.Text = "Пакет документов:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 44); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 4; + this.label2.Text = "Количество:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(3, 70); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(48, 15); + this.label3.TabIndex = 5; + this.label3.Text = "Сумма:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(180, 122); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(282, 122); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(445, 158); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Label label1; + private Label label2; + private Label label3; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormCreateOrder.cs b/LawFirm/LawFirmView/FormCreateOrder.cs new file mode 100644 index 0000000..6f6a410 --- /dev/null +++ b/LawFirm/LawFirmView/FormCreateOrder.cs @@ -0,0 +1,140 @@ +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using AbstractLawFirmContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using AbstractLawFirmContracts.BindingModels; + +namespace LawFirmView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IDocumentLogic logicD, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка пакетов документов для заказа"); + try + { + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + _logger.LogInformation("Пакеты документов загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пакетов документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxDocument.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxDocument.SelectedValue); + var product = _logicD.ReadElement(new DocumentSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.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 comboBoxDocument_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBoxSum_TextChanged(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 (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите пакет документов", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + DocumentId = Convert.ToInt32(comboBoxDocument.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/LawFirm/LawFirmView/FormCreateOrder.resx b/LawFirm/LawFirmView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocument.Designer.cs b/LawFirm/LawFirmView/FormDocument.Designer.cs new file mode 100644 index 0000000..106d77a --- /dev/null +++ b/LawFirm/LawFirmView/FormDocument.Designer.cs @@ -0,0 +1,226 @@ +namespace LawFirmView +{ + partial class FormDocument + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonRef); + this.groupBox1.Controls.Add(this.buttonDel); + this.groupBox1.Controls.Add(this.buttonUpd); + this.groupBox1.Controls.Add(this.buttonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(58, 98); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(605, 288); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты"; + // + // dataGridView + // + 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.Column1, + this.Column2, + this.Column3}); + this.dataGridView.Location = new System.Drawing.Point(3, 19); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(413, 254); + this.dataGridView.TabIndex = 0; + // + // Column1 + // + this.Column1.HeaderText = "id"; + this.Column1.Name = "Column1"; + this.Column1.Visible = false; + // + // Column2 + // + this.Column2.HeaderText = "Компонент"; + this.Column2.Name = "Column2"; + // + // Column3 + // + this.Column3.HeaderText = "Количество"; + this.Column3.Name = "Column3"; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(476, 19); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(476, 61); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(476, 108); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(476, 156); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(427, 403); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 1; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(534, 403); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 2; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(102, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(205, 23); + this.textBoxName.TabIndex = 3; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(102, 41); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(151, 23); + this.textBoxPrice.TabIndex = 4; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 5; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 41); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(70, 15); + this.label2.TabIndex = 6; + this.label2.Text = "Стоимость:"; + // + // FormDocument + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(691, 450); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBox1); + this.Name = "FormDocument"; + this.Text = "Пакет документов"; + this.Load += new System.EventHandler(this.FormDocument_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox groupBox1; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocument.cs b/LawFirm/LawFirmView/FormDocument.cs new file mode 100644 index 0000000..62697b2 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocument.cs @@ -0,0 +1,236 @@ +using AbstractLawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.BindingModels; +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 LawFirmView +{ + public partial class FormDocument : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logic; + private int? _id; + private Dictionary _documentComponents; + public int Id { set { _id = value; } } + public FormDocument(ILogger logger, IDocumentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _documentComponents = new Dictionary(); + } + + private void FormDocument_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new DocumentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.DocumentName; + textBoxPrice.Text = view.Price.ToString(); + _documentComponents = view.DocumentComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_documentComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _documentComponents) + { + 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(FormDocumentComponent)); + if (service is FormDocumentComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + if (_documentComponents.ContainsKey(form.Id)) + { + _documentComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _documentComponents.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(FormDocumentComponent)); + if (service is FormDocumentComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _documentComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName - { Count}", form.ComponentModel.ComponentName, form.Count); + _documentComponents[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); + + _documentComponents?.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 (_documentComponents == null || _documentComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new DocumentBindingModel + { + Id = _id ?? 0, + DocumentName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + DocumentComponents = _documentComponents + }; + 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 _documentComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/LawFirm/LawFirmView/FormDocument.resx b/LawFirm/LawFirmView/FormDocument.resx new file mode 100644 index 0000000..a9dc853 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocument.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs b/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs new file mode 100644 index 0000000..0fa5f66 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace LawFirmView +{ + partial class FormDocumentComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(93, 12); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(215, 23); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(93, 50); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(146, 23); + this.textBoxCount.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(72, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Компонент:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 50); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Количество:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(164, 91); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + 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(259, 91); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormProductComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(384, 136); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Name = "FormProductComponent"; + this.Text = "Компонент пакета документов"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label label1; + private Label label2; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocumentComponent.cs b/LawFirm/LawFirmView/FormDocumentComponent.cs new file mode 100644 index 0000000..eed845a --- /dev/null +++ b/LawFirm/LawFirmView/FormDocumentComponent.cs @@ -0,0 +1,95 @@ +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.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 LawFirmView +{ + public partial class FormDocumentComponent : 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 FormDocumentComponent(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/LawFirm/LawFirmView/FormDocumentComponent.resx b/LawFirm/LawFirmView/FormDocumentComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormDocumentComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocuments.Designer.cs b/LawFirm/LawFirmView/FormDocuments.Designer.cs new file mode 100644 index 0000000..40c7ac6 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocuments.Designer.cs @@ -0,0 +1,114 @@ +namespace LawFirmView +{ + partial class FormDocuments + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(445, 420); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(514, 22); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(95, 37); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(514, 80); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(95, 39); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(514, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(95, 40); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(514, 205); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(95, 39); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // FormDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(669, 432); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormDocuments"; + this.Text = "Пакеты документов"; + this.Load += new System.EventHandler(this.FormDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocuments.cs b/LawFirm/LawFirmView/FormDocuments.cs new file mode 100644 index 0000000..cbbdda6 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocuments.cs @@ -0,0 +1,116 @@ +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using AbstractLawFirmContracts.BindingModels; +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormDocuments : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logic; + public FormDocuments(ILogger logger, IDocumentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDocuments_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["DocumentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DocumentComponents"].Visible = false; + } + _logger.LogInformation("Загрузка пакетов документов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пакетов документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDocument)); + if (service is FormDocument 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(FormDocument)); + if (service is FormDocument 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 DocumentBindingModel + { + 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/LawFirm/LawFirmView/FormDocuments.resx b/LawFirm/LawFirmView/FormDocuments.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormDocuments.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs new file mode 100644 index 0000000..6d9d80f --- /dev/null +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -0,0 +1,174 @@ +namespace LawFirmView +{ + 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.toolStripMenuItemCatalogs = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пакетыДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.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.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItemCatalogs}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(910, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "Справочники"; + // + // toolStripMenuItemCatalogs + // + this.toolStripMenuItemCatalogs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.пакетыДокументовToolStripMenuItem}); + this.toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + this.toolStripMenuItemCatalogs.Size = new System.Drawing.Size(94, 20); + this.toolStripMenuItemCatalogs.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // пакетыДокументовToolStripMenuItem + // + this.пакетыДокументовToolStripMenuItem.Name = "пакетыДокументовToolStripMenuItem"; + this.пакетыДокументовToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; + this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(736, 411); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(742, 39); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(156, 26); + 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(742, 71); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(156, 23); + 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(742, 100); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(156, 23); + 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(742, 129); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(156, 23); + 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(742, 158); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(156, 23); + 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(910, 477); + 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.Name = "FormMain"; + this.Text = "FormMain"; + 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 toolStripMenuItemCatalogs; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem пакетыДокументовToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs new file mode 100644 index 0000000..134665b --- /dev/null +++ b/LawFirm/LawFirmView/FormMain.cs @@ -0,0 +1,180 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["DocumentId"].Visible = false; + dataGridView.Columns["DocumentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + + } + + private void пакетыДокументовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDocuments)); + if (service is FormDocuments form) + { + form.ShowDialog(); + } + } + + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + + } + + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + } +} diff --git a/LawFirm/LawFirmView/FormMain.resx b/LawFirm/LawFirmView/FormMain.resx new file mode 100644 index 0000000..05252e7 --- /dev/null +++ b/LawFirm/LawFirmView/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 25 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index b57c89e..b6cfc13 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -8,4 +8,14 @@ enable + + + + + + + + + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index c47930b..ab37d8c 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -1,7 +1,18 @@ +using AbstractLawFirmBusinessLogic.BusinessLogic; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace LawFirmView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,32 @@ namespace LawFirmView // 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