From dc1e0037a5a98c91d400423882e3b545e98f18ab Mon Sep 17 00:00:00 2001 From: "nastya.girl.22@mail.ru" Date: Tue, 25 Apr 2023 22:11:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm.sln | 16 +- .../BusinessLogic/DocumentLogic.cs | 107 ++++++- .../BusinessLogic/OrderLogic.cs | 101 +++++- .../BusinessLogicsContracts/IDocumentLogic.cs | 2 + .../StoragesContracts/IOrderStorage.cs | 5 + .../LawFirmFileImplement/DataFileSingleton.cs | 66 ++++ .../Implements/ComponentStorage.cs | 89 ++++++ .../Implements/DocumentStorage.cs | 80 +++++ .../Implements/OrderStorage.cs | 91 ++++++ .../LawFirmFileImplement.csproj | 14 + .../LawFirmFileImplement/Models/Component.cs | 64 ++++ .../LawFirmFileImplement/Models/Document.cs | 99 ++++++ LawFirm/LawFirmFileImplement/Models/Order.cs | 105 +++++++ .../Implements/DocumentStorage.cs | 98 ++++-- .../Implements/OrderStorage.cs | 110 ++++++- LawFirm/LawFirmListImplement/Models/Order.cs | 59 +++- .../LawFirmView/FormComponents.Designer.cs | 22 +- LawFirm/LawFirmView/FormComponents.resx | 6 - .../LawFirmView/FormCreateOrder.Designer.cs | 33 +- LawFirm/LawFirmView/FormCreateOrder.cs | 33 +- LawFirm/LawFirmView/FormDocument.Designer.cs | 290 +++++++++--------- LawFirm/LawFirmView/FormDocument.cs | 4 +- LawFirm/LawFirmView/FormDocument.resx | 9 - .../FormDocumentComponent.Designer.cs | 119 +++---- LawFirm/LawFirmView/FormDocumentComponent.cs | 11 +- LawFirm/LawFirmView/FormDocuments.Designer.cs | 115 +++++++ LawFirm/LawFirmView/FormDocuments.cs | 112 +++++++ LawFirm/LawFirmView/FormDocuments.resx | 60 ++++ LawFirm/LawFirmView/FormMain.Designer.cs | 278 +++++++---------- LawFirm/LawFirmView/FormMain.cs | 20 ++ LawFirm/LawFirmView/FormMain.resx | 24 -- LawFirm/LawFirmView/LawFirmView.csproj | 1 + LawFirm/LawFirmView/Program.cs | 4 +- 33 files changed, 1724 insertions(+), 523 deletions(-) create mode 100644 LawFirm/LawFirmFileImplement/DataFileSingleton.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/ComponentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj create mode 100644 LawFirm/LawFirmFileImplement/Models/Component.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Document.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Order.cs create mode 100644 LawFirm/LawFirmView/FormDocuments.Designer.cs create mode 100644 LawFirm/LawFirmView/FormDocuments.cs create mode 100644 LawFirm/LawFirmView/FormDocuments.resx diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index d1f87b5..85a406b 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmView", "LawFirmView\LawFirmView.csproj", "{15EE7231-6283-4A53-AD30-F1E446471C6B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmView", "LawFirmView\LawFirmView.csproj", "{15EE7231-6283-4A53-AD30-F1E446471C6B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmDataModels", "LawFirmDataModels\LawFirmDataModels.csproj", "{7C356B57-C3B5-45C1-987A-9D7755161EB6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmDataModels", "LawFirmDataModels\LawFirmDataModels.csproj", "{7C356B57-C3B5-45C1-987A-9D7755161EB6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmContracts", "LawFirmContracts\LawFirmContracts.csproj", "{DA3562B0-F5B0-4513-B53F-3161AB3B8F78}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirmContracts\LawFirmContracts.csproj", "{DA3562B0-F5B0-4513-B53F-3161AB3B8F78}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplement", "LawFirmListImplement\LawFirmListImplement.csproj", "{F2ECDD91-4CA4-4BDF-8EFF-F2CC80DFDFE7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplement", "LawFirmListImplement\LawFirmListImplement.csproj", "{F2ECDD91-4CA4-4BDF-8EFF-F2CC80DFDFE7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{E09C46AA-9871-4B96-BC73-CCD93918AEE1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{E09C46AA-9871-4B96-BC73-CCD93918AEE1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E5961797-2975-425F-B5DD-FC92947C54E7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {E09C46AA-9871-4B96-BC73-CCD93918AEE1}.Debug|Any CPU.Build.0 = Debug|Any CPU {E09C46AA-9871-4B96-BC73-CCD93918AEE1}.Release|Any CPU.ActiveCfg = Release|Any CPU {E09C46AA-9871-4B96-BC73-CCD93918AEE1}.Release|Any CPU.Build.0 = Release|Any CPU + {E5961797-2975-425F-B5DD-FC92947C54E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5961797-2975-425F-B5DD-FC92947C54E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5961797-2975-425F-B5DD-FC92947C54E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5961797-2975-425F-B5DD-FC92947C54E7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs index 93405b8..4fe023a 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/DocumentLogic.cs @@ -1,7 +1,9 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,24 +14,107 @@ namespace LawFirmBusinessLogic.BusinessLogic { public class DocumentLogic : IDocumentLogic { - public bool Create(DocumentBindingModel model) + private readonly ILogger _logger; + + private readonly IDocumentStorage _documentStorage; + + public DocumentLogic(ILogger logger, IDocumentStorage documentStorage) { - throw new NotImplementedException(); + _logger = logger; + _documentStorage = documentStorage; } - - public DocumentViewModel? ReadElement(DocumentSearchModel model) - { - throw new NotImplementedException(); - } - + public List? ReadList(DocumentSearchModel? model) { - throw new NotImplementedException(); + _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) { - throw new NotImplementedException(); + 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}.Price:{ Price}. 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/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs index cc85d14..905b7fa 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,7 +1,10 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,29 +15,105 @@ namespace LawFirmBusinessLogic.BusinessLogic { public class OrderLogic : IOrderLogic { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } public bool CreateOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Update operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } - public bool DeliveryOrder(OrderBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, OrderStatus.Выдан); } public bool FinishOrder(OrderBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, OrderStatus.Готов); } - - public List? ReadList(OrderSearchModel? model) - { - throw new NotImplementedException(); - } - public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, OrderStatus.Выполняется); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.DocumentId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.DocumentId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество документов в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); } } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs index 86d8e8f..5819bfd 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IDocumentLogic.cs @@ -18,5 +18,7 @@ namespace LawFirmContracts.BusinessLogicsContracts bool Create(DocumentBindingModel model); bool Update(DocumentBindingModel model); + + bool Delete(DocumentBindingModel model); } } diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IOrderStorage.cs b/LawFirm/LawFirmContracts/StoragesContracts/IOrderStorage.cs index 7c6c955..2e21a3b 100644 --- a/LawFirm/LawFirmContracts/StoragesContracts/IOrderStorage.cs +++ b/LawFirm/LawFirmContracts/StoragesContracts/IOrderStorage.cs @@ -11,6 +11,11 @@ namespace LawFirmContracts.StoragesContracts { public interface IOrderStorage { + + + + + List GetFullList(); List GetFilteredList(OrderSearchModel model); diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..c7b816d --- /dev/null +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -0,0 +1,66 @@ +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + + private readonly string ComponentFileName = "Component.xml"; + + private readonly string DocumentFileName = "Document.xml"; + + private readonly string OrderFileName = "Order.xml"; + + public List Components { get; private set; } + + public List Orders { get; private set; } + + public List Documents { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); + + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/ComponentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e762e2c --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,89 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Components + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..73d8da7 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -0,0 +1,80 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class DocumentStorage : IDocumentStorage + { + private readonly DataFileSingleton source; + public DocumentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Documents + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + return source.Documents + .Select(x => x.GetViewModel) + .ToList(); + } + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + return source.Documents.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1; + var newDocument = Document.Create(model); + if (newDocument == null) + { + return null; + } + source.Documents.Add(newDocument); + source.SaveDocuments(); + return newDocument.GetViewModel; + } + public DocumentViewModel? Update(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + var element = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Documents.Remove(element); + source.SaveDocuments(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..14d0d60 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,91 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + private OrderViewModel AddManufactureName(OrderViewModel model) + { + model.DocumentName = source.Documents.SingleOrDefault(x => x.Id == model.DocumentId)?.DocumentName ?? string.Empty; + return model; + } + public List GetFullList() + { + return source.Orders + .Select(x => AddManufactureName(x.GetViewModel)) + .ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + if (model.Id == null) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AddManufactureName(x.GetViewModel)) + .ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + var order = source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + if (order == null) + { + return null; + } + return AddManufactureName(order); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj new file mode 100644 index 0000000..77fe5b1 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Component.cs b/LawFirm/LawFirmFileImplement/Models/Component.cs new file mode 100644 index 0000000..b666758 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Component.cs @@ -0,0 +1,64 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + internal 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 static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + 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 + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs new file mode 100644 index 0000000..e025120 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -0,0 +1,99 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + internal 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 Components { get; private set; } = new(); + + private Dictionary? _documentComponents = null; + + public Dictionary DocumentComponents + { + get + { + if (_documentComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _documentComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + } + return _documentComponents; + } + } + + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Components = model.DocumentComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Document? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Document() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("DocumentComponents")!.Elements("DocumentComponent") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + + public void Update(DocumentBindingModel? model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + Components = model.DocumentComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _documentComponents = null; + } + + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentComponents = DocumentComponents + }; + + public XElement GetXElement => new("Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentComponents", Components.Select(x => new XElement("DocumentComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs new file mode 100644 index 0000000..dcbaad9 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + internal 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; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + DocumentId = model.DocumentId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) + }; + + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + return order; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + 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 + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("DocumentId", DocumentId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/LawFirm/LawFirmListImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmListImplement/Implements/DocumentStorage.cs index 6b1599e..2cc295b 100644 --- a/LawFirm/LawFirmListImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmListImplement/Implements/DocumentStorage.cs @@ -2,7 +2,9 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using LawFirmListImplement.Models; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,34 +14,94 @@ namespace LawFirmListImplement.Implements { public class DocumentStorage : IDocumentStorage { - public DocumentViewModel? Delete(DocumentBindingModel model) + private readonly DataListSingleton _source; + public DocumentStorage() { - throw new NotImplementedException(); + _source = DataListSingleton.GetInstance(); } - - public DocumentViewModel? GetElement(DocumentSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(DocumentSearchModel model) - { - throw new NotImplementedException(); - } - public List GetFullList() { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + 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/LawFirmListImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmListImplement/Implements/OrderStorage.cs index 6300ce2..4e3428c 100644 --- a/LawFirm/LawFirmListImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmListImplement/Implements/OrderStorage.cs @@ -2,7 +2,9 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using LawFirmListImplement.Models; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,34 +14,112 @@ namespace LawFirmListImplement.Implements { public class OrderStorage : IOrderStorage { - public OrderViewModel? Delete(OrderBindingModel model) + private readonly DataListSingleton _source; + + public OrderStorage() { - throw new NotImplementedException(); - } - - public OrderViewModel? GetElement(OrderSearchModel model) - { - throw new NotImplementedException(); - } - - public List GetFilteredList(OrderSearchModel model) - { - throw new NotImplementedException(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() { - throw new NotImplementedException(); + var result = new List(); + foreach (var order in _source.Orders) + { + OrderViewModel thisorder = order.GetViewModel; + Document? computer = _source.Documents.Find(x => x.Id == order.DocumentId); + string computerName = computer?.DocumentName ?? string.Empty; + thisorder.DocumentName = computerName; + result.Add(thisorder); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + OrderViewModel thisorder = order.GetViewModel; + Document? computer = _source.Documents.Find(x => x.Id == order.DocumentId); + string computerName = computer?.DocumentName ?? string.Empty; + thisorder.DocumentName = computerName; + result.Add(thisorder); + } + } + 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)) + { + OrderViewModel thisorder = order.GetViewModel; + Document? computer = _source.Documents.Find(x => x.Id == order.DocumentId); + string computerName = computer?.DocumentName ?? string.Empty; + thisorder.DocumentName = computerName; + return thisorder; + } + } + return null; } public OrderViewModel? Insert(OrderBindingModel model) { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + 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.Documents.RemoveAt(i); + return element.GetViewModel; + } + } + return null; } } } diff --git a/LawFirm/LawFirmListImplement/Models/Order.cs b/LawFirm/LawFirmListImplement/Models/Order.cs index fc6266a..1ebc33d 100644 --- a/LawFirm/LawFirmListImplement/Models/Order.cs +++ b/LawFirm/LawFirmListImplement/Models/Order.cs @@ -1,4 +1,6 @@ -using LawFirmDataModels.Enums; +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; using LawFirmDataModels.Models; using System; using System.Collections.Generic; @@ -10,18 +12,59 @@ namespace LawFirmListImplement.Models { internal class Order : IOrderModel { - public int DocumentId => throw new NotImplementedException(); + public int Id { get; private set; } - public int Count => throw new NotImplementedException(); + public int DocumentId { get; private set; } - public double Sum => throw new NotImplementedException(); + public int Count { get; private set; } - public OrderStatus Status => throw new NotImplementedException(); + public double Sum { get; private set; } - public DateTime DateCreate => throw new NotImplementedException(); + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime? DateImplement => throw new NotImplementedException(); + public DateTime DateCreate { get; set; } = DateTime.Now; - public int Id => throw new NotImplementedException(); + public DateTime? DateImplement { get; 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; + } + Status = model.Status; + if (model.DateImplement != null) + { + 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/LawFirmView/FormComponents.Designer.cs b/LawFirm/LawFirmView/FormComponents.Designer.cs index 6c0c46d..24bd48e 100644 --- a/LawFirm/LawFirmView/FormComponents.Designer.cs +++ b/LawFirm/LawFirmView/FormComponents.Designer.cs @@ -34,10 +34,9 @@ this.buttonDel = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormComponents_Load); // // dataGridView // @@ -46,9 +45,7 @@ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.Column1, - this.Column2}); + this.ColumnId}); this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; this.dataGridView.Location = new System.Drawing.Point(0, 0); this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); @@ -108,19 +105,6 @@ this.ColumnId.ReadOnly = true; this.ColumnId.Visible = false; // - // Column1 - // - this.Column1.HeaderText = "Название компонента"; - this.Column1.Name = "Column1"; - this.Column1.ReadOnly = true; - this.Column1.Width = 383; - // - // Column2 - // - this.Column2.HeaderText = "Цена"; - this.Column2.Name = "Column2"; - this.Column2.ReadOnly = true; - // // FormComponents // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -146,7 +130,5 @@ private Button buttonDel; private Button buttonRef; private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn Column1; - private DataGridViewTextBoxColumn Column2; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormComponents.resx b/LawFirm/LawFirmView/FormComponents.resx index 24bef36..1f60a5e 100644 --- a/LawFirm/LawFirmView/FormComponents.resx +++ b/LawFirm/LawFirmView/FormComponents.resx @@ -60,10 +60,4 @@ True - - True - - - True - \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormCreateOrder.Designer.cs b/LawFirm/LawFirmView/FormCreateOrder.Designer.cs index 1204ac4..0743876 100644 --- a/LawFirm/LawFirmView/FormCreateOrder.Designer.cs +++ b/LawFirm/LawFirmView/FormCreateOrder.Designer.cs @@ -31,12 +31,13 @@ this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); - this.comboBoxProduct = new System.Windows.Forms.ComboBox(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); this.textBoxCount = new System.Windows.Forms.TextBox(); this.textBoxSum = new System.Windows.Forms.TextBox(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormCreateOrder_Load); // // label1 // @@ -50,7 +51,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 37); + this.label2.Location = new System.Drawing.Point(12, 42); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(75, 15); this.label2.TabIndex = 1; @@ -59,25 +60,25 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(12, 64); + this.label3.Location = new System.Drawing.Point(12, 74); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(48, 15); this.label3.TabIndex = 2; this.label3.Text = "Сумма:"; // - // comboBoxProduct + // comboBoxDocument // - this.comboBoxProduct.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxProduct.FormattingEnabled = true; - this.comboBoxProduct.Location = new System.Drawing.Point(93, 6); - this.comboBoxProduct.Name = "comboBoxProduct"; - this.comboBoxProduct.Size = new System.Drawing.Size(270, 23); - this.comboBoxProduct.TabIndex = 3; - this.comboBoxProduct.SelectedIndexChanged += new System.EventHandler(this.ComboBoxProduct_SelectedIndexChanged); + this.comboBoxDocument.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(93, 6); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(270, 23); + this.comboBoxDocument.TabIndex = 5; + this.comboBoxDocument.SelectedIndexChanged += new System.EventHandler(this.ComboBoxDocument_SelectedIndexChanged); // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(93, 34); + this.textBoxCount.Location = new System.Drawing.Point(93, 39); this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(270, 23); this.textBoxCount.TabIndex = 4; @@ -85,7 +86,7 @@ // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(93, 61); + this.textBoxSum.Location = new System.Drawing.Point(93, 71); this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.ReadOnly = true; this.textBoxSum.Size = new System.Drawing.Size(270, 23); @@ -120,12 +121,12 @@ this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxSum); this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.comboBoxProduct); + this.Controls.Add(this.comboBoxDocument); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "FormCreateOrder"; - this.Text = "FormCreateOrder"; + this.Text = "Заказ"; this.ResumeLayout(false); this.PerformLayout(); @@ -136,7 +137,7 @@ private Label label1; private Label label2; private Label label3; - private ComboBox comboBoxProduct; + private ComboBox comboBoxDocument; private TextBox textBoxCount; private TextBox textBoxSum; private Button buttonSave; diff --git a/LawFirm/LawFirmView/FormCreateOrder.cs b/LawFirm/LawFirmView/FormCreateOrder.cs index fbcfbcb..7444f2d 100644 --- a/LawFirm/LawFirmView/FormCreateOrder.cs +++ b/LawFirm/LawFirmView/FormCreateOrder.cs @@ -18,34 +18,42 @@ namespace LawFirmView { private readonly ILogger _logger; - private readonly IDocumentLogic _logicP; + private readonly IDocumentLogic _logicD; private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IDocumentLogic logicP, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IDocumentLogic logicD, IOrderLogic logicO) { InitializeComponent(); _logger = logger; - _logicP = logicP; + _logicD = logicD; _logicO = logicO; } private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - // прописать логику + + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } } private void CalcSum() { - if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + if (comboBoxDocument.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) { try { - int id = Convert.ToInt32(comboBoxProduct.SelectedValue); - var product = _logicP.ReadElement(new DocumentSearchModel { Id = id }); + int id = Convert.ToInt32(comboBoxDocument.SelectedValue); + var document = _logicD.ReadElement(new DocumentSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + textBoxSum.Text = Math.Round(count * (document?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) @@ -61,7 +69,7 @@ namespace LawFirmView CalcSum(); } - private void ComboBoxProduct_SelectedIndexChanged(object sender, EventArgs e) + private void ComboBoxDocument_SelectedIndexChanged(object sender, EventArgs e) { CalcSum(); } @@ -73,7 +81,7 @@ namespace LawFirmView MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxProduct.SelectedValue == null) + if (comboBoxDocument.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -81,9 +89,12 @@ namespace LawFirmView _logger.LogInformation("Создание заказа"); try { + int id = Convert.ToInt32(comboBoxDocument.SelectedValue); + int counr = Convert.ToInt32(textBoxCount.Text); + double sum = Convert.ToDouble(textBoxSum.Text); var operationResult = _logicO.CreateOrder(new OrderBindingModel { - DocumentId = Convert.ToInt32(comboBoxProduct.SelectedValue), + DocumentId = Convert.ToInt32(comboBoxDocument.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/LawFirm/LawFirmView/FormDocument.Designer.cs b/LawFirm/LawFirmView/FormDocument.Designer.cs index 772c072..fc9055a 100644 --- a/LawFirm/LawFirmView/FormDocument.Designer.cs +++ b/LawFirm/LawFirmView/FormDocument.Designer.cs @@ -28,192 +28,206 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxPrice = new System.Windows.Forms.TextBox(); - this.groupBoxComponents = new System.Windows.Forms.GroupBox(); - this.buttonRef = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.groupBoxComponents.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // label1 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(62, 15); - this.label1.TabIndex = 0; - this.label1.Text = "Название:"; + label1.AutoSize = true; + label1.Location = new Point(14, 12); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 0; + label1.Text = "Название:"; // // label2 // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 40); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(70, 15); - this.label2.TabIndex = 1; - this.label2.Text = "Стоимость:"; + label2.AutoSize = true; + label2.Location = new Point(14, 53); + label2.Name = "label2"; + label2.Size = new Size(86, 20); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(80, 6); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(256, 23); - this.textBoxName.TabIndex = 2; + textBoxName.Location = new Point(91, 8); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(292, 27); + textBoxName.TabIndex = 2; // // textBoxPrice // - this.textBoxPrice.Enabled = false; - this.textBoxPrice.Location = new System.Drawing.Point(80, 37); - this.textBoxPrice.Name = "textBoxPrice"; - this.textBoxPrice.Size = new System.Drawing.Size(132, 23); - this.textBoxPrice.TabIndex = 3; + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(91, 49); + textBoxPrice.Margin = new Padding(3, 4, 3, 4); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(150, 27); + textBoxPrice.TabIndex = 3; // // groupBoxComponents // - this.groupBoxComponents.Controls.Add(this.buttonRef); - this.groupBoxComponents.Controls.Add(this.buttonDel); - this.groupBoxComponents.Controls.Add(this.buttonUpd); - this.groupBoxComponents.Controls.Add(this.buttonAdd); - this.groupBoxComponents.Controls.Add(this.dataGridView); - this.groupBoxComponents.Location = new System.Drawing.Point(12, 73); - this.groupBoxComponents.Name = "groupBoxComponents"; - this.groupBoxComponents.Size = new System.Drawing.Size(561, 311); - this.groupBoxComponents.TabIndex = 4; - this.groupBoxComponents.TabStop = false; - this.groupBoxComponents.Text = "Компоненты"; + groupBoxComponents.Controls.Add(buttonRef); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(14, 97); + groupBoxComponents.Margin = new Padding(3, 4, 3, 4); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(3, 4, 3, 4); + groupBoxComponents.Size = new Size(641, 415); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(428, 136); - 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); + buttonRef.Location = new Point(489, 181); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(86, 31); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; // // buttonDel // - this.buttonDel.Location = new System.Drawing.Point(428, 98); - 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); + buttonDel.Location = new Point(489, 131); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(86, 31); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; // // buttonUpd // - this.buttonUpd.Location = new System.Drawing.Point(428, 60); - 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); + buttonUpd.Location = new Point(489, 80); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(86, 31); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(428, 22); - 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); + buttonAdd.Location = new Point(489, 29); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(86, 31); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // dataGridView // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.ColumnName, - this.ColumnCount}); - this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; - this.dataGridView.Location = new System.Drawing.Point(3, 19); - this.dataGridView.MultiSelect = false; - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowHeadersVisible = false; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(408, 289); - this.dataGridView.TabIndex = 0; + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(3, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(433, 387); + dataGridView.TabIndex = 0; // // ColumnId // - this.ColumnId.HeaderText = "Id"; - this.ColumnId.Name = "ColumnId"; - this.ColumnId.ReadOnly = true; - this.ColumnId.Visible = false; + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; // // ColumnName // - this.ColumnName.HeaderText = "Компонент"; - this.ColumnName.Name = "ColumnName"; - this.ColumnName.ReadOnly = true; - this.ColumnName.Width = 305; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + ColumnName.Width = 305; // // ColumnCount // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.Name = "ColumnCount"; - this.ColumnCount.ReadOnly = true; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(377, 397); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(75, 23); - this.buttonSave.TabIndex = 5; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + buttonSave.Location = new Point(431, 529); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(86, 31); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(458, 397); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(75, 23); - this.buttonCancel.TabIndex = 6; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + buttonCancel.Location = new Point(523, 529); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormDocument // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(586, 432); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.groupBoxComponents); - this.Controls.Add(this.textBoxPrice); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Name = "FormDocument"; - this.Text = "Изделие"; - this.groupBoxComponents.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(670, 576); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Margin = new Padding(3, 4, 3, 4); + Name = "FormDocument"; + Text = "Изделие"; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/LawFirm/LawFirmView/FormDocument.cs b/LawFirm/LawFirmView/FormDocument.cs index 1bfd0ce..377c90e 100644 --- a/LawFirm/LawFirmView/FormDocument.cs +++ b/LawFirm/LawFirmView/FormDocument.cs @@ -43,7 +43,7 @@ namespace LawFirmView { textBoxName.Text = view.DocumentName; textBoxPrice.Text = view.Price.ToString(); - _documentComponents = view.DocumentComponents ?? new Dictionary(); + _documentComponents = view.DocumentComponents ?? new Dictionary(); LoadData(); } } @@ -191,7 +191,7 @@ namespace LawFirmView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/LawFirm/LawFirmView/FormDocument.resx b/LawFirm/LawFirmView/FormDocument.resx index 256dbcb..72380a4 100644 --- a/LawFirm/LawFirmView/FormDocument.resx +++ b/LawFirm/LawFirmView/FormDocument.resx @@ -66,13 +66,4 @@ True - - True - - - True - - - True - \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs b/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs index ab118c0..f3d16ef 100644 --- a/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs +++ b/LawFirm/LawFirmView/FormDocumentComponent.Designer.cs @@ -28,84 +28,89 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.comboBoxComponent = new System.Windows.Forms.ComboBox(); - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); + label1 = new Label(); + label2 = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); // // label1 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(21, 18); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(72, 15); - this.label1.TabIndex = 0; - this.label1.Text = "Компонент:"; + label1.AutoSize = true; + label1.Location = new Point(24, 24); + label1.Name = "label1"; + label1.Size = new Size(91, 20); + label1.TabIndex = 0; + label1.Text = "Компонент:"; // // label2 // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(18, 46); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(75, 15); - this.label2.TabIndex = 1; - this.label2.Text = "Количество:"; + label2.AutoSize = true; + label2.Location = new Point(21, 61); + label2.Name = "label2"; + label2.Size = new Size(93, 20); + label2.TabIndex = 1; + label2.Text = "Количество:"; // // comboBoxComponent // - this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxComponent.FormattingEnabled = true; - this.comboBoxComponent.Location = new System.Drawing.Point(99, 15); - this.comboBoxComponent.Name = "comboBoxComponent"; - this.comboBoxComponent.Size = new System.Drawing.Size(249, 23); - this.comboBoxComponent.TabIndex = 2; + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(113, 20); + comboBoxComponent.Margin = new Padding(3, 4, 3, 4); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(284, 28); + comboBoxComponent.TabIndex = 4; + comboBoxComponent.SelectedIndexChanged += comboBoxComponent_SelectedIndexChanged; // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(99, 43); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(249, 23); - this.textBoxCount.TabIndex = 3; + textBoxCount.Location = new Point(113, 57); + textBoxCount.Margin = new Padding(3, 4, 3, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(284, 27); + textBoxCount.TabIndex = 3; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(132, 81); - 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); + buttonSave.Location = new Point(151, 108); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(86, 31); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(213, 81); - 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); + buttonCancel.Location = new Point(243, 108); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormDocumentComponent // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(369, 124); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.comboBoxComponent); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Name = "FormDocumentComponent"; - this.Text = "FormDocumentComponent"; - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(422, 165); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(label2); + Controls.Add(label1); + Margin = new Padding(3, 4, 3, 4); + Name = "FormDocumentComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/LawFirm/LawFirmView/FormDocumentComponent.cs b/LawFirm/LawFirmView/FormDocumentComponent.cs index b49e113..bdcc271 100644 --- a/LawFirm/LawFirmView/FormDocumentComponent.cs +++ b/LawFirm/LawFirmView/FormDocumentComponent.cs @@ -17,13 +17,13 @@ namespace LawFirmView public partial class FormDocumentComponent : Form { private readonly List? _list; - - public int Id + + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } - + public IComponentModel? ComponentModel { get @@ -84,5 +84,10 @@ namespace LawFirmView DialogResult = DialogResult.Cancel; Close(); } + + private void comboBoxComponent_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/LawFirm/LawFirmView/FormDocuments.Designer.cs b/LawFirm/LawFirmView/FormDocuments.Designer.cs new file mode 100644 index 0000000..7383088 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocuments.Designer.cs @@ -0,0 +1,115 @@ +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(); + this.Load += new System.EventHandler(this.FormDocuments_Load); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 1); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(457, 450); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(483, 12); + 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(483, 51); + 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(483, 90); + 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(483, 129); + 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); + // + // FormDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(589, 450); + 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 = "Изделия"; + ((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..23338e5 --- /dev/null +++ b/LawFirm/LawFirmView/FormDocuments.cs @@ -0,0 +1,112 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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 index 6fe8aaa..bcefe25 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -28,211 +28,152 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = 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.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // menuStrip1 // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(870, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(7, 3, 0, 3); + menuStrip1.Size = new Size(1150, 30); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; // // компонентыToolStripMenuItem // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click_1); + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click_1; // // изделияToolStripMenuItem // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.изделияToolStripMenuItem.Text = "Изделия"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click_1); - // - // dataGridView - // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnId, - this.Column1, - this.Column2, - this.Column3, - this.Column4, - this.Column5, - this.Column6, - this.Column7}); - this.dataGridView.Location = new System.Drawing.Point(0, 27); - this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowHeadersVisible = false; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(702, 353); - this.dataGridView.TabIndex = 1; + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(182, 26); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click_1; // // buttonCreateOrder // - this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCreateOrder.Location = new System.Drawing.Point(709, 56); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(149, 23); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(966, 75); + buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(170, 31); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; // // buttonTakeOrderInWork // - this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(709, 95); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(149, 23); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(966, 127); + buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(170, 54); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // buttonOrderReady // - this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOrderReady.Location = new System.Drawing.Point(709, 133); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(149, 23); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(966, 189); + buttonOrderReady.Margin = new Padding(3, 4, 3, 4); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(170, 31); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; // // buttonIssuedOrder // - this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonIssuedOrder.Location = new System.Drawing.Point(709, 171); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(149, 23); - this.buttonIssuedOrder.TabIndex = 5; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(966, 228); + buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(170, 31); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // // buttonRef // - this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRef.Location = new System.Drawing.Point(709, 210); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(149, 23); - this.buttonRef.TabIndex = 6; - this.buttonRef.Text = "Обновить список"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(966, 280); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(170, 31); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; // - // ColumnId + // dataGridView // - this.ColumnId.HeaderText = "ID"; - this.ColumnId.Name = "ColumnId"; - this.ColumnId.Visible = false; - // - // Column1 - // - this.Column1.HeaderText = "Номер"; - this.Column1.Name = "Column1"; - // - // Column2 - // - this.Column2.HeaderText = "Изделие"; - this.Column2.Name = "Column2"; - // - // Column3 - // - this.Column3.HeaderText = "Количество"; - this.Column3.Name = "Column3"; - // - // Column4 - // - this.Column4.HeaderText = "Сумма"; - this.Column4.Name = "Column4"; - // - // Column5 - // - this.Column5.HeaderText = "Статус"; - this.Column5.Name = "Column5"; - // - // Column6 - // - this.Column6.HeaderText = "Дата создания"; - this.Column6.Name = "Column6"; - // - // Column7 - // - this.Column7.HeaderText = "Дата выполнения"; - this.Column7.Name = "Column7"; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 36); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(959, 512); + dataGridView.TabIndex = 7; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(870, 379); - 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.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1150, 545); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + Text = "Юридическая фирма"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion private MenuStrip menuStrip1; - private DataGridView dataGridView; private Button buttonCreateOrder; private Button buttonTakeOrderInWork; private Button buttonOrderReady; @@ -249,5 +190,6 @@ private DataGridViewTextBoxColumn Column5; private DataGridViewTextBoxColumn Column6; private DataGridViewTextBoxColumn Column7; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 9da4769..462319b 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -35,6 +35,21 @@ namespace LawFirmView { _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; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void компонентыToolStripMenuItem_Click_1(object sender, EventArgs e) { @@ -48,6 +63,11 @@ namespace LawFirmView private void изделияToolStripMenuItem_Click_1(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) diff --git a/LawFirm/LawFirmView/FormMain.resx b/LawFirm/LawFirmView/FormMain.resx index eeb0e0d..a7878a9 100644 --- a/LawFirm/LawFirmView/FormMain.resx +++ b/LawFirm/LawFirmView/FormMain.resx @@ -60,30 +60,6 @@ 17, 17 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - 75 diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index 83cfa95..0951ee9 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -28,6 +28,7 @@ + diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index 2e550df..5b14d07 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -1,7 +1,7 @@ using LawFirmBusinessLogic.BusinessLogic; using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.StoragesContracts; -using LawFirmListImplement.Implements; +using LawFirmFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -51,7 +51,9 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + } } \ No newline at end of file