From 218590201926ab608f1d8a43620e8dee813b4f2a Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Tue, 11 Apr 2023 01:53:51 +0400 Subject: [PATCH] lab2hard vrode work --- .../BusinessLogics/OrderLogic.cs | 28 +- .../BusinessLogics/ShopLogic.cs | 79 ++++- .../BindingModels/ShopBindingModel.cs | 3 +- .../BusinessLogicsContracts/IShopLogic.cs | 4 +- .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 4 +- LawFirm/LawFirmDataModel/Models/IShopModel.cs | 3 +- .../LawFirmFileImplement/DataFileSingleton.cs | 19 +- .../Implements/DocumentStorage.cs | 8 +- .../Implements/OrderStorage.cs | 6 +- .../Implements/ShopStorage.cs | 129 ++++++++ LawFirm/LawFirmFileImplement/Models/Shop.cs | 108 ++++++ .../Implements/ShopStorage.cs | 6 + LawFirm/LawFirmListImplement/Models/Shop.cs | 3 +- LawFirm/LawFirmView/FormAddDocument.cs | 4 +- LawFirm/LawFirmView/FormMain.Designer.cs | 310 +++++++++--------- LawFirm/LawFirmView/FormMain.cs | 12 +- .../LawFirmView/FormSellDocuments.Designer.cs | 120 +++++++ LawFirm/LawFirmView/FormSellDocuments.cs | 86 +++++ LawFirm/LawFirmView/FormSellDocuments.resx | 60 ++++ LawFirm/LawFirmView/FormShop.Designer.cs | 305 +++++++++-------- LawFirm/LawFirmView/FormShop.cs | 22 +- LawFirm/LawFirmView/FormShops.cs | 2 +- LawFirm/LawFirmView/Program.cs | 3 +- 24 files changed, 994 insertions(+), 332 deletions(-) create mode 100644 LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Shop.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.Designer.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.resx diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index a87b215..cb2e310 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,10 +12,17 @@ namespace LawFirmBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + private readonly IDocumentStorage _documentStorage; + public OrderLogic(ILogger logger, + IOrderStorage orderStorage, + IShopLogic shopLogic, + IDocumentStorage documentStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _documentStorage = documentStorage; } public bool CreateOrder(OrderBindingModel model) { @@ -47,16 +54,29 @@ namespace LawFirmBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) + { + + model.DateImplement = DateTime.Now; + var document = _documentStorage.GetElement(new() { Id = viewModel.DocumentId }); + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + if (!_shopLogic.AddDocuments(document, viewModel.Count)) + { + throw new Exception($"AddDocuments operation failed - нет места"); + } + } else { model.DateImplement = viewModel.DateImplement; } - CheckModel(model); + CheckModel(model, false); if (_orderStorage.Update(model) == null) { model.Status--; - _logger.LogWarning("Update operation failed"); + _logger.LogWarning("Change status operation failed"); return false; } return true; diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index e07d5bb..5dec67d 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -107,7 +107,7 @@ namespace LawFirmBusinessLogic.BusinessLogics } } - public bool AddDocument(ShopSearchModel model, IDocumentModel ship, int count) + public bool AddDocument(ShopSearchModel model, IDocumentModel document, int count) { if (model == null) { @@ -115,6 +115,7 @@ namespace LawFirmBusinessLogic.BusinessLogics } if (count <= 0) { + return false; throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count)); } _logger.LogInformation("AddDocument. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); @@ -124,19 +125,22 @@ namespace LawFirmBusinessLogic.BusinessLogics _logger.LogWarning("AddDocument element not found"); return false; } - _logger.LogInformation("AddDocument find. Id:{Id}", element.Id); + if (element.Capacity - element.ShopDocuments.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("В магазине не хватает места", nameof(count)); + } - if (element.ShopDocuments.TryGetValue(ship.Id, out var pair)) + if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) { - element.ShopDocuments[ship.Id] = (ship, count + pair.Item2); - _logger.LogInformation("AddDocument. Added {count} {ship} to '{ShopName}' shop", - count, ship.DocumentName, element.ShopName); + element.ShopDocuments[document.Id] = (document, count + pair.Item2); + _logger.LogInformation("AddDocument. Added {count} {document} to '{ShopName}' shop", + count, document.DocumentName, element.ShopName); } else { - element.ShopDocuments[ship.Id] = (ship, count); - _logger.LogInformation("AddDocument. Added {count} new ship {ship} to '{ShopName}' shop", - count, ship.DocumentName, element.ShopName); + element.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("AddDocument. Added {count} new document {document} to '{ShopName}' shop", + count, document.DocumentName, element.ShopName); } _shopStorage.Update(new() { @@ -144,9 +148,64 @@ namespace LawFirmBusinessLogic.BusinessLogics Address = element.Address, ShopName = element.ShopName, DateOpen = element.DateOpen, + Capacity = element.Capacity, ShopDocuments = element.ShopDocuments }); return true; } - } + public bool AddDocuments(IDocumentModel model, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество документов должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddDocuments. ShopName:{ShopName}. Id:{Id}", model.DocumentName, model.Id); + var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopDocuments.Select(x => x.Value.Item2).Sum()).Sum(); + if (allFreeQuantity < count) + { + _logger.LogWarning("AddTravels operation failed."); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + int freeQuantity = shop.Capacity - shop.ShopDocuments.Select(x => x.Value.Item2).Sum(); + if (freeQuantity <= 0) + { + continue; + } + if (freeQuantity < count) + { + if (!AddDocument(new() { Id = shop.Id }, model, freeQuantity)) + { + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + count -= freeQuantity; + } + else + { + if (!AddDocument(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + count = 0; + } + if (count == 0) + { + return true; + } + } + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + public bool SellDocuments(IDocumentModel model, int count) + { + return _shopStorage.SellDocuments(model, count); + } + } } diff --git a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs index 4eff95f..6cc0b4e 100644 --- a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs +++ b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs @@ -12,7 +12,8 @@ namespace LawFirmContracts.BindingModels public string ShopName { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public DateTime DateOpen { get; set; } = DateTime.Now; - public Dictionary ShopDocuments { get; set; } = new(); + public int Capacity { get; set; } + public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs index a4c15d2..60c4985 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,8 @@ namespace LawFirmContracts.BusinessLogicsContracts bool Create(ShopBindingModel model); bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); - bool AddDocument(ShopSearchModel model, IDocumentModel document, int count); + bool AddDocuments(IDocumentModel model, int count); + bool SellDocuments(IDocumentModel model, int count); + bool AddDocument(ShopSearchModel model, IDocumentModel document, int count); } } diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs index 0bc1574..4fb68eb 100644 --- a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs +++ b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.SearchModels; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace LawFirmContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDocuments(IDocumentModel model, int count); } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs index 9334e2d..2f021bd 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs @@ -18,7 +18,9 @@ namespace LawFirmContracts.ViewModels [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } = DateTime.Now; - public Dictionary ShopDocuments { get; set; } = new(); + [DisplayName("Вместимость магазина")] + public int Capacity { get; set; } + public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } } } diff --git a/LawFirm/LawFirmDataModel/Models/IShopModel.cs b/LawFirm/LawFirmDataModel/Models/IShopModel.cs index 783e810..4049c17 100644 --- a/LawFirm/LawFirmDataModel/Models/IShopModel.cs +++ b/LawFirm/LawFirmDataModel/Models/IShopModel.cs @@ -8,6 +8,7 @@ namespace LawFirmDataModels.Models string ShopName { get; } string Address { get; } DateTime DateOpen { get; } - Dictionary ShopDocuments { get; } + public int Capacity { get; } + Dictionary ShopDocuments { get; } } } diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs index dba4b10..96f7113 100644 --- a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -9,10 +9,14 @@ namespace LawFirmFileImplement private readonly string BlankFileName = "Blank.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DocumentFileName = "Document.xml"; - public List Blanks { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + + public List Blanks { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } - public static DataFileSingleton GetInstance() + public List Shops { get; private set; } + + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -23,13 +27,16 @@ namespace LawFirmFileImplement public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", 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() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + + private DataFileSingleton() { Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; - Orders = new List(); - } - private static List? LoadData(string filename, string xmlNodeName, + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 559f389..7a0d8da 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -50,14 +50,14 @@ namespace LawFirmFileImplement.Implements } public DocumentViewModel? Update(DocumentBindingModel model) { - var ship = source.Documents.FirstOrDefault(x => x.Id == model.Id); - if (ship == null) + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) { return null; } - ship.Update(model); + document.Update(model); source.SaveDocuments(); - return ship.GetViewModel; + return document.GetViewModel; } public DocumentViewModel? Delete(DocumentBindingModel model) { diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 783ef1a..0a958dc 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -38,10 +38,10 @@ namespace LawFirmFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - var ship = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); - if (ship != null) + var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); + if (document != null) { - viewModel.DocumentName = ship.DocumentName; + viewModel.DocumentName = document.DocumentName; } return viewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..156ac44 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,129 @@ + +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + /*return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList();*/ + return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + public bool SellDocuments(IDocumentModel model, int count) + { + int availableQuantity = source.Shops.Select(x => x.ShopDocuments.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum(); + if (availableQuantity < count) + { + return false; + } + var shops = source.Shops.Where(x => x.ShopDocuments.ContainsKey(model.Id)); + foreach (var shop in shops) + { + int countInCurrentShop = shop.ShopDocuments[model.Id].Item2; + if (countInCurrentShop <= count) + { + shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, 0); + count -= countInCurrentShop; + } + else + { + shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, countInCurrentShop - count); + count = 0; + } + Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + ShopDocuments = shop.ShopDocuments, + Capacity = shop.Capacity + }); + if (count == 0) + { + return true; + } + } + return false; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs new file mode 100644 index 0000000..b8d1a9f --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs @@ -0,0 +1,108 @@ +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 +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpen { get; private set; } + public int Capacity { get; private set; } + public Dictionary DocumentsCount = new(); + public Dictionary? _documents = null; + public Dictionary ShopDocuments + { + get + { + if (_documents == null) + { + var source = DataFileSingleton.GetInstance(); + _documents = DocumentsCount.ToDictionary( + x => x.Key, + y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!, + y.Value) + ); + } + return _documents; + } + } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Capacity = model.Capacity, + DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpening")!.Value), + Capacity = Convert.ToInt32(element.Element("Capacity")!.Value), + DocumentsCount = element.Element("Documents")!.Elements("Document") + .ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + Capacity = model.Capacity; + DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); + _documents = null; + + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + Capacity = Capacity, + ShopDocuments = ShopDocuments + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpen.ToString()), + new XElement("Capacity", Capacity.ToString()), + new XElement("Documents", DocumentsCount.Select(x => + new XElement("Document", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs index dd23b9e..c1b39ff 100644 --- a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using LawFirmListImplement.Models; using System; using System.Collections.Generic; @@ -108,5 +109,10 @@ namespace LawFirmListImplement.Implements } return null; } + + public bool SellDocuments(IDocumentModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/LawFirm/LawFirmListImplement/Models/Shop.cs b/LawFirm/LawFirmListImplement/Models/Shop.cs index 4b18e0d..4703cc8 100644 --- a/LawFirm/LawFirmListImplement/Models/Shop.cs +++ b/LawFirm/LawFirmListImplement/Models/Shop.cs @@ -15,7 +15,8 @@ namespace LawFirmListImplement.Models public string Address { get; set; } = string.Empty; public DateTime DateOpen { get; set; } - public int Id { get; set; } + public int Capacity { get; private set; } + public int Id { get; set; } public Dictionary ShopDocuments { get; private set; } = new Dictionary(); public static Shop? Create(ShopBindingModel? model) diff --git a/LawFirm/LawFirmView/FormAddDocument.cs b/LawFirm/LawFirmView/FormAddDocument.cs index 27add3d..10ad81f 100644 --- a/LawFirm/LawFirmView/FormAddDocument.cs +++ b/LawFirm/LawFirmView/FormAddDocument.cs @@ -19,7 +19,7 @@ namespace LawFirmView private void FormAddDocument_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка списка кораблей для пополнения"); + _logger.LogInformation("Загрузка списка документов для пополнения"); try { var list = _logicDocument.ReadList(null); @@ -33,7 +33,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/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index 3738201..5aa99c0 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -28,157 +28,170 @@ /// 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.магазины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.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonAddDocument = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.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.магазины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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonAddDocument = new System.Windows.Forms.Button(); + this.buttonSellDocument = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(800, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(800, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.бланкиToolStripMenuItem, this.документыToolStripMenuItem, this.магазиныToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочники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.BlanksToolStripMenuItem_Click); - // - // документыToolStripMenuItem - // - this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.документыToolStripMenuItem.Text = "Документы"; - this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); - // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(566, 411); - this.dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(605, 85); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(168, 23); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonIssuedOrder - // - this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23); - this.buttonIssuedOrder.TabIndex = 5; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(605, 143); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(168, 23); - this.buttonUpdate.TabIndex = 6; - this.buttonUpdate.Text = "Обновить список"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonAddDocument - // - this.buttonAddDocument.Location = new System.Drawing.Point(605, 172); - this.buttonAddDocument.Name = "buttonAddDocument"; - this.buttonAddDocument.Size = new System.Drawing.Size(168, 23); - this.buttonAddDocument.TabIndex = 7; - this.buttonAddDocument.Text = "Добавить документ"; - this.buttonAddDocument.UseVisualStyleBackColor = true; - this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonAddDocument); - this.Controls.Add(this.buttonUpdate); - 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 = "Юридическая фирма"; - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // бланкиToolStripMenuItem + // + this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.бланкиToolStripMenuItem.Text = "Бланки"; + this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click); + // + // документыToolStripMenuItem + // + this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; + this.документыToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.документыToolStripMenuItem.Text = "Документы"; + this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); + // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(566, 411); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(605, 85); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(168, 23); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(605, 143); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(168, 23); + this.buttonUpdate.TabIndex = 6; + this.buttonUpdate.Text = "Обновить список"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAddDocument + // + this.buttonAddDocument.Location = new System.Drawing.Point(605, 172); + this.buttonAddDocument.Name = "buttonAddDocument"; + this.buttonAddDocument.Size = new System.Drawing.Size(168, 23); + this.buttonAddDocument.TabIndex = 7; + this.buttonAddDocument.Text = "Добавить документ"; + this.buttonAddDocument.UseVisualStyleBackColor = true; + this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click); + // + // buttonSellDocument + // + this.buttonSellDocument.Location = new System.Drawing.Point(605, 201); + this.buttonSellDocument.Name = "buttonSellDocument"; + this.buttonSellDocument.Size = new System.Drawing.Size(168, 23); + this.buttonSellDocument.TabIndex = 8; + this.buttonSellDocument.Text = "Продать документ"; + this.buttonSellDocument.UseVisualStyleBackColor = true; + this.buttonSellDocument.Click += new System.EventHandler(this.ButtonSellDocument_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSellDocument); + this.Controls.Add(this.buttonAddDocument); + this.Controls.Add(this.buttonUpdate); + 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 = "Юридическая фирма"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -196,5 +209,6 @@ private ToolStripMenuItem документыToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonAddDocument; - } + private Button buttonSellDocument; + } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 319d0d6..c855f61 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -181,5 +181,15 @@ namespace LawFirmView LoadData(); } } - } + + private void ButtonSellDocument_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellDocuments)); + if (service is FormSellDocuments form) + { + form.ShowDialog(); + LoadData(); + } + } + } } diff --git a/LawFirm/LawFirmView/FormSellDocuments.Designer.cs b/LawFirm/LawFirmView/FormSellDocuments.Designer.cs new file mode 100644 index 0000000..1d5afea --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.Designer.cs @@ -0,0 +1,120 @@ +namespace LawFirmView +{ + partial class FormSellDocuments + { + /// + /// 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.ButtonCancel = new System.Windows.Forms.Button(); + this.comboBoxDocuments = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.labelDocument = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.ButtonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(266, 153); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 1; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxDocuments + // + this.comboBoxDocuments.FormattingEnabled = true; + this.comboBoxDocuments.Location = new System.Drawing.Point(144, 38); + this.comboBoxDocuments.Name = "comboBoxDocuments"; + this.comboBoxDocuments.Size = new System.Drawing.Size(216, 28); + this.comboBoxDocuments.TabIndex = 2; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(144, 102); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(216, 27); + this.numericUpDownCount.TabIndex = 3; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(34, 38); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(69, 20); + this.labelDocument.TabIndex = 4; + this.labelDocument.Text = "Корабль"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(34, 109); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 5; + this.labelCount.Text = "Количество"; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(144, 153); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormSellDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 194); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxDocuments); + this.Controls.Add(this.ButtonCancel); + this.Name = "FormSellDocuments"; + this.Text = "Продажа документов"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button ButtonCancel; + private ComboBox comboBoxDocuments; + private NumericUpDown numericUpDownCount; + private Label labelDocument; + private Label labelCount; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormSellDocuments.cs b/LawFirm/LawFirmView/FormSellDocuments.cs new file mode 100644 index 0000000..1d479fb --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormSellDocuments : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IDocumentLogic _documentLogic; + private readonly List? _listDocument; + public FormSellDocuments(ILogger logger, IShopLogic shopLogic, IDocumentLogic documentLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _documentLogic = documentLogic; + _listDocument = documentLogic.ReadList(null); + if (_listDocument != null) + { + comboBoxDocuments.DisplayMember = "DocumentName"; + comboBoxDocuments.ValueMember = "Id"; + comboBoxDocuments.DataSource=_listDocument; + comboBoxDocuments.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxDocuments.SelectedValue == null) + { + MessageBox.Show("Выберите корабль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(numericUpDownCount.Text)) + { + MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа поездок"); + try + { + var document = _documentLogic.ReadElement(new() + { + Id = (int)comboBoxDocuments.SelectedValue + }); + if (document == null) + { + throw new Exception("Корабль не найден. Дополнительная информация в логах."); + } + var operationResult = _shopLogic.SellDocuments( + model: document, + count: (int)numericUpDownCount.Value + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже корабля. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения корабля"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormSellDocuments.resx b/LawFirm/LawFirmView/FormSellDocuments.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.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/FormShop.Designer.cs b/LawFirm/LawFirmView/FormShop.Designer.cs index 6762acc..aaa3e36 100644 --- a/LawFirm/LawFirmView/FormShop.Designer.cs +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -28,145 +28,174 @@ /// private void InitializeComponent() { - this.labelShop = new System.Windows.Forms.Label(); - this.labelAddress = new System.Windows.Forms.Label(); - this.labelDate = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxAddress = new System.Windows.Forms.TextBox(); - this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // labelShop - // - this.labelShop.AutoSize = true; - this.labelShop.Location = new System.Drawing.Point(12, 21); - this.labelShop.Name = "labelShop"; - this.labelShop.Size = new System.Drawing.Size(69, 20); - this.labelShop.TabIndex = 0; - this.labelShop.Text = "Магазин"; - // - // labelAddress - // - this.labelAddress.AutoSize = true; - this.labelAddress.Location = new System.Drawing.Point(195, 21); - this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(51, 20); - this.labelAddress.TabIndex = 1; - this.labelAddress.Text = "Адрес"; - // - // labelDate - // - this.labelDate.AutoSize = true; - this.labelDate.Location = new System.Drawing.Point(474, 21); - this.labelDate.Name = "labelDate"; - this.labelDate.Size = new System.Drawing.Size(110, 20); - this.labelDate.TabIndex = 2; - this.labelDate.Text = "Дата открытия"; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(12, 44); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(160, 27); - this.textBoxName.TabIndex = 3; - // - // textBoxAddress - // - this.textBoxAddress.Location = new System.Drawing.Point(195, 44); - this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(246, 27); - this.textBoxAddress.TabIndex = 4; - // - // dateTimePickerDateOpen - // - this.dateTimePickerDateOpen.Location = new System.Drawing.Point(474, 44); - this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen"; - this.dateTimePickerDateOpen.Size = new System.Drawing.Size(250, 27); - this.dateTimePickerDateOpen.TabIndex = 5; - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.labelShop = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.numericUpDownCapacity = new System.Windows.Forms.NumericUpDown(); + this.labelCapacity = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).BeginInit(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(10, 16); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(156, 16); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 1; + this.labelAddress.Text = "Адрес"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(375, 16); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(87, 15); + this.labelDate.TabIndex = 2; + this.labelDate.Text = "Дата открытия"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(10, 33); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(140, 23); + this.textBoxName.TabIndex = 3; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(156, 33); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(216, 23); + this.textBoxAddress.TabIndex = 4; + // + // dateTimePickerDateOpen + // + this.dateTimePickerDateOpen.Location = new System.Drawing.Point(375, 33); + this.dateTimePickerDateOpen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen"; + this.dateTimePickerDateOpen.Size = new System.Drawing.Size(123, 23); + this.dateTimePickerDateOpen.TabIndex = 5; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ID, this.DocumentName, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 77); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(712, 330); - this.dataGridView.TabIndex = 6; - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(490, 413); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(111, 29); - this.ButtonSave.TabIndex = 7; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(630, 413); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(94, 29); - this.ButtonCancel.TabIndex = 8; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // ID - // - this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ID.HeaderText = "ID"; - this.ID.MinimumWidth = 6; - this.ID.Name = "ID"; - this.ID.Visible = false; - // - // DocumentName - // - this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.DocumentName.HeaderText = "DocumentName"; - this.DocumentName.MinimumWidth = 6; - this.DocumentName.Name = "DocumentName"; - // - // Count - // - this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Count.HeaderText = "Count"; - this.Count.MinimumWidth = 6; - this.Count.Name = "Count"; - // - // FormShop - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(740, 450); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.dateTimePickerDateOpen); - this.Controls.Add(this.textBoxAddress); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelDate); - this.Controls.Add(this.labelAddress); - this.Controls.Add(this.labelShop); - this.Name = "FormShop"; - this.Text = "Магазин"; - this.Load += new System.EventHandler(this.FormShop_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.dataGridView.Location = new System.Drawing.Point(10, 58); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(623, 248); + this.dataGridView.TabIndex = 6; + // + // ID + // + this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // DocumentName + // + this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.DocumentName.HeaderText = "DocumentName"; + this.DocumentName.MinimumWidth = 6; + this.DocumentName.Name = "DocumentName"; + // + // Count + // + this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Count.HeaderText = "Count"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(429, 310); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 22); + this.ButtonSave.TabIndex = 7; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(551, 310); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownCapacity + // + this.numericUpDownCapacity.Location = new System.Drawing.Point(504, 33); + this.numericUpDownCapacity.Name = "numericUpDownCapacity"; + this.numericUpDownCapacity.Size = new System.Drawing.Size(120, 23); + this.numericUpDownCapacity.TabIndex = 9; + // + // labelCapacity + // + this.labelCapacity.AutoSize = true; + this.labelCapacity.Location = new System.Drawing.Point(504, 16); + this.labelCapacity.Name = "labelCapacity"; + this.labelCapacity.Size = new System.Drawing.Size(134, 15); + this.labelCapacity.TabIndex = 10; + this.labelCapacity.Text = "Вместимость магазина"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(648, 338); + this.Controls.Add(this.labelCapacity); + this.Controls.Add(this.numericUpDownCapacity); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePickerDateOpen); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.labelShop); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -184,5 +213,7 @@ private DataGridViewTextBoxColumn ID; private DataGridViewTextBoxColumn DocumentName; private DataGridViewTextBoxColumn Count; - } + private NumericUpDown numericUpDownCapacity; + private Label labelCapacity; + } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs index 4229ec1..5243b19 100644 --- a/LawFirm/LawFirmView/FormShop.cs +++ b/LawFirm/LawFirmView/FormShop.cs @@ -37,7 +37,8 @@ namespace LawFirmView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address.ToString(); dateTimePickerDateOpen.Text = view.DateOpen.ToString(); - _shopDocuments = view.ShopDocuments ?? new Dictionary(); + numericUpDownCapacity.Value = view.Capacity; + _shopDocuments = view.ShopDocuments ?? new Dictionary(); LoadData(); } } @@ -50,7 +51,7 @@ namespace LawFirmView } private void LoadData() { - _logger.LogInformation("Загрузка кораблей магазина"); + _logger.LogInformation("Загрузка документов магазина"); try { if (_shopDocuments != null) @@ -64,7 +65,7 @@ namespace LawFirmView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки кораблей магазина"); + _logger.LogError(ex, "Ошибка загрузки документов магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -91,12 +92,13 @@ namespace LawFirmView { var model = new ShopBindingModel { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Address = textBoxAddress.Text, - DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text), - ShopDocuments = _shopDocuments - }; + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text), + Capacity = (int)numericUpDownCapacity.Value, + ShopDocuments = _shopDocuments + }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { @@ -118,5 +120,5 @@ namespace LawFirmView DialogResult = DialogResult.Cancel; Close(); } - } + } } diff --git a/LawFirm/LawFirmView/FormShops.cs b/LawFirm/LawFirmView/FormShops.cs index d685835..ed08f38 100644 --- a/LawFirm/LawFirmView/FormShops.cs +++ b/LawFirm/LawFirmView/FormShops.cs @@ -89,7 +89,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/Program.cs b/LawFirm/LawFirmView/Program.cs index f86d2bc..9fb2eea 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -53,6 +53,7 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file