From f3cf15a27a2f54030ea421c9f910c44ca3914a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Sat, 22 Jun 2024 10:15:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MotorPlantBusinessLogic.csproj | 2 +- .../MotorPlantBusinessLogic/OrderLogic.cs | 32 +- .../MotorPlantBusinessLogic/ShopLogic.cs | 303 +++++++------ .../BindingModels/ShopBindingModel.cs | 17 +- .../BindingModels/SupplyBindingModel.cs | 12 +- .../BusinessLogicsContracts/IShopLogic.cs | 19 +- .../MotorPlantContracts.csproj | 32 +- .../SearchModels/ShopSearchModel.cs | 10 +- .../SearchModels/SupplySearchModel.cs | 14 + .../StoragesContracts/IShopStorage.cs | 20 +- .../ViewModels/ShopViewModel.cs | 24 +- MotorPlant/MotorPlantDataModels/IShopModel.cs | 15 +- .../MotorPlantDataModels/ISupplyModel.cs | 14 +- .../MotorPlantDataModels.csproj | 26 +- .../DataFileSingleton.cs | 4 + .../MotorPlantFileImplement.csproj | 18 +- .../MotorPlantFileImplement/OrderStorage.cs | 10 +- MotorPlant/MotorPlantFileImplement/Shop.cs | 103 +++++ .../MotorPlantFileImplement/ShopStorage.cs | 145 +++++++ .../DataListSingleton.cs | 8 +- .../MotorPlantListImplement.csproj | 18 +- MotorPlant/MotorPlantListImplement/Order.cs | 4 - MotorPlant/MotorPlantListImplement/Shop.cs | 85 ++-- .../MotorPlantListImplement/ShopStorage.cs | 192 +++++---- .../FormCreateSupply.Designer.cs | 270 ++++++------ MotorPlant/MotorPlantView/FormCreateSupply.cs | 154 +++---- .../MotorPlantView/FormMain.Designer.cs | 401 ++++++++--------- MotorPlant/MotorPlantView/FormMain.cs | 312 +++++++------- MotorPlant/MotorPlantView/FormMain.resx | 53 ++- .../FormSellEngines.Designer.cs | 124 ++++++ MotorPlant/MotorPlantView/FormSellEngines.cs | 82 ++++ .../MotorPlantView/FormSellEngines.resx | 120 ++++++ .../MotorPlantView/FormShop.Designer.cs | 404 ++++++++++-------- MotorPlant/MotorPlantView/FormShop.cs | 214 +++++----- .../MotorPlantView/FormShops.Designer.cs | 244 +++++------ MotorPlant/MotorPlantView/FormShops.cs | 188 ++++---- .../MotorPlantView/MotorPlantView.csproj | 42 +- MotorPlant/MotorPlantView/Program.cs | 13 +- 38 files changed, 2214 insertions(+), 1534 deletions(-) create mode 100644 MotorPlant/MotorPlantContracts/SearchModels/SupplySearchModel.cs create mode 100644 MotorPlant/MotorPlantFileImplement/Shop.cs create mode 100644 MotorPlant/MotorPlantFileImplement/ShopStorage.cs create mode 100644 MotorPlant/MotorPlantView/FormSellEngines.Designer.cs create mode 100644 MotorPlant/MotorPlantView/FormSellEngines.cs create mode 100644 MotorPlant/MotorPlantView/FormSellEngines.resx diff --git a/MotorPlant/MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj b/MotorPlant/MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj index c0409c5..dc2780a 100644 --- a/MotorPlant/MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj +++ b/MotorPlant/MotorPlantBusinessLogic/MotorPlantBusinessLogic.csproj @@ -17,7 +17,7 @@ - + diff --git a/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs b/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs index 7b27063..4a36a77 100644 --- a/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs @@ -12,13 +12,13 @@ namespace MotorPlantBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopStorage _shopStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; } - public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); @@ -31,7 +31,6 @@ namespace MotorPlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -48,22 +47,34 @@ namespace MotorPlantBusinessLogic.BusinessLogics } return true; } - public bool TakeOrderInWork(OrderBindingModel model) { return ToNextStatus(model, OrderStatus.Выполняется); } - public bool FinishOrder(OrderBindingModel model) { return ToNextStatus(model, OrderStatus.Готов); } - public bool DeliveryOrder(OrderBindingModel model) { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + EngineId = order.EngineId, + Count = order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } return ToNextStatus(model, OrderStatus.Выдан); } - public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) { CheckModel(model, false); @@ -75,26 +86,22 @@ namespace MotorPlantBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(element)); } - model.EngineId = element.EngineId; model.DateCreate = element.DateCreate; model.DateImplement = element.DateImplement; model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; - if (model.Status != orderStatus - 1) { _logger.LogWarning("Status update to " + orderStatus + " operation failed"); return false; } model.Status = orderStatus; - if (model.Status == OrderStatus.Выдан) { model.DateImplement = DateTime.Now; } - if (_orderStorage.Update(model) == null) { model.Status--; @@ -103,7 +110,6 @@ namespace MotorPlantBusinessLogic.BusinessLogics } return true; } - private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) diff --git a/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs b/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs index db28630..114fef4 100644 --- a/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs @@ -12,141 +12,170 @@ using System.Threading.Tasks; namespace MotorPlantBusinessLogic.BusinessLogics { - public class ShopLogic : IShopLogic - { - private readonly ILogger _logger; - private readonly IShopStorage _shopStorage; - private readonly IEngineStorage _EngineStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage, IEngineStorage EngineStorage) - { - _logger = logger; - _shopStorage = shopStorage; - _EngineStorage = EngineStorage; - } - public List? ReadList(ShopSearchModel? model) - { - _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ShopViewModel? ReadElement(ShopSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); - var element = _shopStorage.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(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ShopBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_shopStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public bool MakeSupply(SupplyBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (model.Count <= 0) - { - throw new ArgumentException("Количество изделий должно быть больше 0"); - } - var shop = _shopStorage.GetElement(new ShopSearchModel - { - Id = model.ShopId - }); - if (shop == null) - { - throw new ArgumentException("Магазина не существует"); - } - if (shop.ShopEngines.ContainsKey(model.EngineId)) - { - var oldValue = shop.ShopEngines[model.EngineId]; - oldValue.Item2 += model.Count; - shop.ShopEngines[model.EngineId] = oldValue; - } - else - { - var Engine = _EngineStorage.GetElement(new EngineSearchModel - { - Id = model.EngineId - }); - if (Engine == null) - { - throw new ArgumentException($"Поставка: Товар с id:{model.EngineId} не найденн"); - } - shop.ShopEngines.Add(model.EngineId, (Engine, model.Count)); - } - return true; - } - private void CheckModel(ShopBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.Adress)) - { - throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - ShopName = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - } + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IEngineStorage _EngineStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage, IEngineStorage EngineStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _EngineStorage = EngineStorage; + } + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.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(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopEngines.ContainsKey(model.EngineId)) + { + var oldValue = shop.ShopEngines[model.EngineId]; + oldValue.Item2 += model.Count; + shop.ShopEngines[model.EngineId] = oldValue; + } + else + { + var Engine = _EngineStorage.GetElement(new EngineSearchModel + { + Id = model.EngineId + }); + if (Engine == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.EngineId} не найденн"); + } + if (shop.ShopEngines.Sum(kv => kv.Value.Item2) + model.Count > shop.EngineMaxCount) + { + throw new ArgumentException("Превышена максимальная вместимость магазина"); + } + shop.ShopEngines.Add(model.EngineId, (Engine, model.Count)); + } + _shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + ShopEngines = shop.ShopEngines, + EngineMaxCount = shop.EngineMaxCount, + }); + + return true; + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool Sale(SupplySearchModel model) + { + if (!model.EngineId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check Engine count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } + } } diff --git a/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs index fe0d7a5..b6e8e1c 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs @@ -7,12 +7,13 @@ using System.Threading.Tasks; namespace MotorPlantContracts.BindingModels { - public class ShopBindingModel : IShopModel - { - public int Id { get; set; } - public string ShopName { get; set; } = string.Empty; - public string Adress { get; set; } = string.Empty; - public DateTime OpeningDate { get; set; } = DateTime.Now; - public Dictionary ShopEngines { get; set; } = new(); - } + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopEngines { get; set; } = new(); + public int EngineMaxCount { get; set; } + } } diff --git a/MotorPlant/MotorPlantContracts/BindingModels/SupplyBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/SupplyBindingModel.cs index 14baa50..332cfee 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/SupplyBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/SupplyBindingModel.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; namespace MotorPlantContracts.BindingModels { - public class SupplyBindingModel : ISupplyModel - { - public int ShopId { get; set; } - public int EngineId { get; set; } - public int Count { get; set; } - } + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int EngineId { get; set; } + public int Count { get; set; } + } } diff --git a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs index dd629ca..d2b2694 100644 --- a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -9,13 +9,14 @@ using System.Threading.Tasks; namespace MotorPlantContracts.BusinessLogicsContracts { - public interface IShopLogic - { - List? ReadList(ShopSearchModel? model); - ShopViewModel? ReadElement(ShopSearchModel model); - bool Create(ShopBindingModel model); - bool Update(ShopBindingModel model); - bool Delete(ShopBindingModel model); - bool MakeSupply(SupplyBindingModel model); - } + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); + } } diff --git a/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj b/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj index 7491766..cf4fc11 100644 --- a/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj +++ b/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj @@ -1,22 +1,22 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - - - - - + + + + + + + + - - - + + + diff --git a/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs b/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs index a3622ca..3ab99aa 100644 --- a/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs +++ b/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace MotorPlantContracts.SearchModels { - public class ShopSearchModel - { - public int? Id { get; set; } - public string? ShopName { get; set; } - } + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } } diff --git a/MotorPlant/MotorPlantContracts/SearchModels/SupplySearchModel.cs b/MotorPlant/MotorPlantContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..b7dc7e7 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.SearchModels +{ + public class SupplySearchModel + { + public int? EngineId { get; set; } + public int? Count { get; set; } + } +} diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs index 0d721d1..bd578e9 100644 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs @@ -9,13 +9,15 @@ using System.Threading.Tasks; namespace MotorPlantContracts.StoragesContracts { - public interface IShopStorage - { - List GetFullList(); - List GetFilteredList(ShopSearchModel model); - ShopViewModel? GetElement(ShopSearchModel model); - ShopViewModel? Insert(ShopBindingModel model); - ShopViewModel? Update(ShopBindingModel model); - ShopViewModel? Delete(ShopBindingModel model); - } + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); + } } diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs index 1a086a5..c5bc8c6 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs @@ -8,15 +8,17 @@ using System.Threading.Tasks; namespace MotorPlantContracts.ViewModels { - public class ShopViewModel : IShopModel - { - public int Id { get; set; } - [DisplayName("Название")] - public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес")] - public string Adress { get; set; } = string.Empty; - [DisplayName("Дата открытия")] - public DateTime OpeningDate { get; set; } - public Dictionary ShopEngines { get; set; } = new(); - } + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopEngines { get; set; } = new(); + [DisplayName("Вместимость")] + public int EngineMaxCount { get; set; } + } } diff --git a/MotorPlant/MotorPlantDataModels/IShopModel.cs b/MotorPlant/MotorPlantDataModels/IShopModel.cs index e096086..6a4ef33 100644 --- a/MotorPlant/MotorPlantDataModels/IShopModel.cs +++ b/MotorPlant/MotorPlantDataModels/IShopModel.cs @@ -8,11 +8,12 @@ using System.Threading.Tasks; namespace MotorPlantDataModels.Models { - public interface IShopModel : IId - { - string ShopName { get; } - string Adress { get; } - DateTime OpeningDate { get; } - Dictionary ShopEngines { get; } - } + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopEngines { get; } + public int EngineMaxCount { get; } + } } diff --git a/MotorPlant/MotorPlantDataModels/ISupplyModel.cs b/MotorPlant/MotorPlantDataModels/ISupplyModel.cs index 7258ec4..f243749 100644 --- a/MotorPlant/MotorPlantDataModels/ISupplyModel.cs +++ b/MotorPlant/MotorPlantDataModels/ISupplyModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace MotorPlantDataModels.Models { - public interface ISupplyModel - { - int ShopId { get; } - int EngineId { get; } - int Count { get; } - } -} \ No newline at end of file + public interface ISupplyModel + { + int ShopId { get; } + int EngineId { get; } + int Count { get; } + } +} diff --git a/MotorPlant/MotorPlantDataModels/MotorPlantDataModels.csproj b/MotorPlant/MotorPlantDataModels/MotorPlantDataModels.csproj index d80c28f..5dae00e 100644 --- a/MotorPlant/MotorPlantDataModels/MotorPlantDataModels.csproj +++ b/MotorPlant/MotorPlantDataModels/MotorPlantDataModels.csproj @@ -1,18 +1,18 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - - - - - + + + + + + + + diff --git a/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs b/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs index a448669..c5610e4 100644 --- a/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs +++ b/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace MotorPlantFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string EngineFileName = "Engine.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Engines { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -23,11 +25,13 @@ namespace MotorPlantFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveEngines() => SaveData(Engines, EngineFileName, "Engines", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Engines = LoadData(EngineFileName, "Engine", x => Engine.Create(x)!)!; 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) { diff --git a/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj b/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj index 4da00b3..9bc6d04 100644 --- a/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj +++ b/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj @@ -1,14 +1,14 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - + + + + diff --git a/MotorPlant/MotorPlantFileImplement/OrderStorage.cs b/MotorPlant/MotorPlantFileImplement/OrderStorage.cs index 5fdd024..8aff0bf 100644 --- a/MotorPlant/MotorPlantFileImplement/OrderStorage.cs +++ b/MotorPlant/MotorPlantFileImplement/OrderStorage.cs @@ -71,14 +71,8 @@ namespace MotorPlantFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var comp in source.Engines) - { - if (comp.Id == order.EngineId) - { - viewModel.EngineName = comp.EngineName; - break; - } - } + var engine = source.Engines.FirstOrDefault(x => x.Id == order.EngineId); + viewModel.EngineName = engine?.EngineName; return viewModel; } } diff --git a/MotorPlant/MotorPlantFileImplement/Shop.cs b/MotorPlant/MotorPlantFileImplement/Shop.cs new file mode 100644 index 0000000..344360d --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/Shop.cs @@ -0,0 +1,103 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Engines { get; private set; } = new(); + private Dictionary? _shopEngines = null; + public Dictionary ShopEngines + { + get + { + if (_shopEngines == null) + { + var source = DataFileSingleton.GetInstance(); + _shopEngines = Engines.ToDictionary(x => x.Key, y => ((source.Engines.FirstOrDefault(z => z.Id == y.Key) as IEngineModel)!, y.Value)); + } + return _shopEngines; + } + } + public int EngineMaxCount { get; private set; } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Engines = model.ShopEngines.ToDictionary(x => x.Key, x => x.Value.Item2), + EngineMaxCount = model.EngineMaxCount + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Adress = element.Element("Adress")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Engines = element.Element("ShopEngines")!.Elements("ShopEngine")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + EngineMaxCount = Convert.ToInt32(element.Element("EngineMaxCount")!.Value) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + EngineMaxCount = model.EngineMaxCount; + Engines = model.ShopEngines.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopEngines = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopEngines = ShopEngines, + EngineMaxCount = EngineMaxCount + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopEngines", Engines.Select( + x => new XElement("ShopEngine", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("EngineMaxCount", EngineMaxCount.ToString()) + ); + public void EnginesUpdate() + { + _shopEngines = null; + } + } +} diff --git a/MotorPlant/MotorPlantFileImplement/ShopStorage.cs b/MotorPlant/MotorPlantFileImplement/ShopStorage.cs new file mode 100644 index 0000000..7323c04 --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/ShopStorage.cs @@ -0,0 +1,145 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + 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(); + } + 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 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 Sale(SupplySearchModel model) + { + if (model == null || !model.EngineId.HasValue || !model.Count.HasValue) + return false; + int remainingSpace = source.Shops.Select(x => x.Engines.ContainsKey(model.EngineId.Value) ? x.Engines[model.EngineId.Value] : 0).Sum(); + if (remainingSpace < model.Count) + { + return false; + } + var shops = source.Shops.Where(x => x.Engines.ContainsKey(model.EngineId.Value)).OrderByDescending(x => x.Engines[model.EngineId.Value]).ToList(); + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Engines[model.EngineId.Value]; + if (residue > 0) + { + shop.Engines.Remove(model.EngineId.Value); + shop.EnginesUpdate(); + model.Count = residue; + } + else + { + if (residue == 0) + { + shop.Engines.Remove(model.EngineId.Value); + } + else + { + shop.Engines[model.EngineId.Value] = -residue; + } + shop.EnginesUpdate(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + public bool RestockingShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.EngineMaxCount - x.ShopEngines.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + { + return false; + } + foreach (Shop shop in source.Shops) + { + int free_places = shop.EngineMaxCount - shop.ShopEngines.Select(x => x.Value.Item2).Sum(); + if (free_places <= 0) + continue; + free_places = Math.Min(free_places, model.Count); + model.Count -= free_places; + if (shop.Engines.ContainsKey(model.EngineId)) + { + shop.Engines[model.EngineId] += free_places; + } + else + { + shop.Engines.Add(model.EngineId, free_places); + } + shop.EnginesUpdate(); + if (model.Count == 0) + { + source.SaveShops(); + return true; + } + } + return false; + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/DataListSingleton.cs b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs index 483ba13..c1ee27d 100644 --- a/MotorPlant/MotorPlantListImplement/DataListSingleton.cs +++ b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs @@ -8,14 +8,14 @@ namespace MotorPlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Engines { get; set; } - public List Shops { get; set; } - private DataListSingleton() + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Engines = new List(); - Shops = new List(); - } + Shops = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj index 4da00b3..9bc6d04 100644 --- a/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj +++ b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj @@ -1,14 +1,14 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - + + + + diff --git a/MotorPlant/MotorPlantListImplement/Order.cs b/MotorPlant/MotorPlantListImplement/Order.cs index f9bc63b..176124c 100644 --- a/MotorPlant/MotorPlantListImplement/Order.cs +++ b/MotorPlant/MotorPlantListImplement/Order.cs @@ -37,11 +37,7 @@ namespace MotorPlantListImplement.Models { return; } - EngineId = model.EngineId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() diff --git a/MotorPlant/MotorPlantListImplement/Shop.cs b/MotorPlant/MotorPlantListImplement/Shop.cs index 0336273..b6f9455 100644 --- a/MotorPlant/MotorPlantListImplement/Shop.cs +++ b/MotorPlant/MotorPlantListImplement/Shop.cs @@ -9,44 +9,49 @@ using System.Threading.Tasks; namespace MotorPlantListImplement.Models { - public class Shop : IShopModel - { - public int Id { get; private set; } - public string ShopName { get; private set; } = string.Empty; - public string Adress { get; private set; } = string.Empty; - public DateTime OpeningDate { get; private set; } - public Dictionary ShopEngines { get; private set; } = new(); - public static Shop? Create(ShopBindingModel? model) - { - if (model == null) - { - return null; - } - return new Shop() - { - Id = model.Id, - ShopName = model.ShopName, - Adress = model.Adress, - OpeningDate = model.OpeningDate - }; - } - public void Update(ShopBindingModel? model) - { - if (model == null) - { - return; - } - ShopName = model.ShopName; - Adress = model.Adress; - OpeningDate = model.OpeningDate; - } - public ShopViewModel GetViewModel => new() - { - Id = Id, - ShopName = ShopName, - Adress = Adress, - OpeningDate = OpeningDate, - ShopEngines = ShopEngines - }; - } + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopEngines { get; private set; } = new(); + public int EngineMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + EngineMaxCount = model.EngineMaxCount, + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + EngineMaxCount = model.EngineMaxCount; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopEngines = ShopEngines, + EngineMaxCount = EngineMaxCount, + }; + } } diff --git a/MotorPlant/MotorPlantListImplement/ShopStorage.cs b/MotorPlant/MotorPlantListImplement/ShopStorage.cs index 1cb6df0..7206dc5 100644 --- a/MotorPlant/MotorPlantListImplement/ShopStorage.cs +++ b/MotorPlant/MotorPlantListImplement/ShopStorage.cs @@ -11,96 +11,104 @@ using System.Threading.Tasks; namespace MotorPlantListImplement.Implements { - public class ShopStorage : IShopStorage - { - private readonly DataListSingleton _source; - public ShopStorage() - { - _source = DataListSingleton.GetInstance(); - } - public List GetFullList() - { - var result = new List(); - foreach (var shop in _source.Shops) - { - result.Add(shop.GetViewModel); - } - return result; - } - public List GetFilteredList(ShopSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.ShopName)) - { - return result; - } - foreach (var shop in _source.Shops) - { - if (shop.ShopName.Contains(model.ShopName)) - { - result.Add(shop.GetViewModel); - } - } - return result; - } - public ShopViewModel? GetElement(ShopSearchModel model) - { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) - { - return null; - } - foreach (var shop in _source.Shops) - { - if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || - (model.Id.HasValue && shop.Id == model.Id)) - { - return shop.GetViewModel; - } - } - return null; - } - public ShopViewModel? Insert(ShopBindingModel model) - { - model.Id = 1; - foreach (var shop in _source.Shops) - { - if (model.Id <= shop.Id) - { - model.Id = shop.Id + 1; - } - } - var newShop = Shop.Create(model); - if (newShop == null) - { - return null; - } - _source.Shops.Add(newShop); - return newShop.GetViewModel; - } - public ShopViewModel? Update(ShopBindingModel model) - { - foreach (var shop in _source.Shops) - { - if (shop.Id == model.Id) - { - shop.Update(model); - return shop.GetViewModel; - } - } - return null; - } - public ShopViewModel? Delete(ShopBindingModel model) - { - for (int i = 0; i < _source.Shops.Count; ++i) - { - if (_source.Shops[i].Id == model.Id) - { - var element = _source.Shops[i]; - _source.Shops.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - } + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public bool Sale(SupplySearchModel model) + { + throw new NotImplementedException(); + } + public bool RestockingShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } + } } diff --git a/MotorPlant/MotorPlantView/FormCreateSupply.Designer.cs b/MotorPlant/MotorPlantView/FormCreateSupply.Designer.cs index 9fa4872..d66a9fb 100644 --- a/MotorPlant/MotorPlantView/FormCreateSupply.Designer.cs +++ b/MotorPlant/MotorPlantView/FormCreateSupply.Designer.cs @@ -1,143 +1,143 @@ -namespace MotorPlantView +namespace MotorPlantView.Forms { - partial class FormCreateSupply - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormCreateSupply + { + /// + /// 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); - } + /// + /// 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 + #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.comboBoxShop = new System.Windows.Forms.ComboBox(); - this.labelShop = new System.Windows.Forms.Label(); - this.labelEngine = new System.Windows.Forms.Label(); - this.comboBoxEngine = new System.Windows.Forms.ComboBox(); - this.labelCount = new System.Windows.Forms.Label(); - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // comboBoxShop - // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(115, 12); - this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(344, 28); - this.comboBoxShop.TabIndex = 0; - // - // labelShop - // - this.labelShop.AutoSize = true; - this.labelShop.Location = new System.Drawing.Point(12, 15); - this.labelShop.Name = "labelShop"; - this.labelShop.Size = new System.Drawing.Size(76, 20); - this.labelShop.TabIndex = 1; - this.labelShop.Text = "Магазин: "; - // - // labelEngine - // - this.labelEngine.AutoSize = true; - this.labelEngine.Location = new System.Drawing.Point(12, 49); - this.labelEngine.Name = "labelEngine"; - this.labelEngine.Size = new System.Drawing.Size(75, 20); - this.labelEngine.TabIndex = 2; - this.labelEngine.Text = "Изделие: "; - // - // comboBoxEngine - // - this.comboBoxEngine.FormattingEnabled = true; - this.comboBoxEngine.Location = new System.Drawing.Point(115, 46); - this.comboBoxEngine.Name = "comboBoxEngine"; - this.comboBoxEngine.Size = new System.Drawing.Size(344, 28); - this.comboBoxEngine.TabIndex = 3; - // - // labelCount - // - this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(12, 83); - this.labelCount.Name = "labelCount"; - this.labelCount.Size = new System.Drawing.Size(97, 20); - this.labelCount.TabIndex = 4; - this.labelCount.Text = "Количество: "; - // - // textBoxCount - // - this.textBoxCount.Location = new System.Drawing.Point(115, 80); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(344, 27); - this.textBoxCount.TabIndex = 5; - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(300, 113); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(116, 39); - this.buttonCancel.TabIndex = 6; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(168, 113); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(116, 39); - this.buttonSave.TabIndex = 7; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // FormCreateSupply - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(471, 164); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.labelCount); - this.Controls.Add(this.comboBoxEngine); - this.Controls.Add(this.labelEngine); - this.Controls.Add(this.labelShop); - this.Controls.Add(this.comboBoxShop); - this.Name = "FormCreateSupply"; - this.Text = "Создание поставки"; - this.Load += new System.EventHandler(this.FormCreateSupply_Load); - this.ResumeLayout(false); - this.PerformLayout(); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.labelEngine = new System.Windows.Forms.Label(); + this.comboBoxEngine = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(115, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(344, 28); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(76, 20); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelEngine + // + this.labelEngine.AutoSize = true; + this.labelEngine.Location = new System.Drawing.Point(12, 49); + this.labelEngine.Name = "labelEngine"; + this.labelEngine.Size = new System.Drawing.Size(75, 20); + this.labelEngine.TabIndex = 2; + this.labelEngine.Text = "Изделие: "; + // + // comboBoxEngine + // + this.comboBoxEngine.FormattingEnabled = true; + this.comboBoxEngine.Location = new System.Drawing.Point(115, 46); + this.comboBoxEngine.Name = "comboBoxEngine"; + this.comboBoxEngine.Size = new System.Drawing.Size(344, 28); + this.comboBoxEngine.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 83); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 80); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(344, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(300, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(116, 39); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(116, 39); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 164); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxEngine); + this.Controls.Add(this.labelEngine); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); - } + } - #endregion + #endregion - private ComboBox comboBoxShop; - private Label labelShop; - private Label labelEngine; - private ComboBox comboBoxEngine; - private Label labelCount; - private TextBox textBoxCount; - private Button buttonCancel; - private Button buttonSave; - } + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelEngine; + private ComboBox comboBoxEngine; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormCreateSupply.cs b/MotorPlant/MotorPlantView/FormCreateSupply.cs index 9d510a0..444d84d 100644 --- a/MotorPlant/MotorPlantView/FormCreateSupply.cs +++ b/MotorPlant/MotorPlantView/FormCreateSupply.cs @@ -12,82 +12,82 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace MotorPlantView +namespace MotorPlantView.Forms { - public partial class FormCreateSupply : Form - { - private readonly ILogger _logger; - private readonly IEngineLogic _logicP; - private readonly IShopLogic _logicS; - private List _shopList = new List(); - private List _EngineList = new List(); - public FormCreateSupply(ILogger logger, IEngineLogic logicP, IShopLogic logicS) - { - InitializeComponent(); - _logger = logger; - _logicP = logicP; - _logicS = logicS; - } - private void FormCreateSupply_Load(object sender, EventArgs e) - { - _shopList = _logicS.ReadList(null); - _EngineList = _logicP.ReadList(null); - if (_shopList != null) - { - comboBoxShop.DisplayMember = "ShopName"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _shopList; - comboBoxShop.SelectedItem = null; - _logger.LogInformation("Загрузка магазинов для поставок"); - } - if (_EngineList != null) - { - comboBoxEngine.DisplayMember = "EngineName"; - comboBoxEngine.ValueMember = "Id"; - comboBoxEngine.DataSource = _EngineList; - comboBoxEngine.SelectedItem = null; - _logger.LogInformation("Загрузка пиццы для поставок"); - } - } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (comboBoxShop.SelectedValue == null) - { - MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxEngine.SelectedValue == null) - { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Создание поставки"); - try - { - var operationResult = _logicS.MakeSupply(new SupplyBindingModel - { - ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), - EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue), - Count = Convert.ToInt32(textBoxCount.Text) - }); - if (!operationResult) - { - throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания поставки"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IEngineLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _EngineList = new List(); + public FormCreateSupply(ILogger logger, IEngineLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _EngineList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_EngineList != null) + { + comboBoxEngine.DisplayMember = "EngineName"; + comboBoxEngine.ValueMember = "Id"; + comboBoxEngine.DataSource = _EngineList; + comboBoxEngine.SelectedItem = null; + _logger.LogInformation("Загрузка двигателей для поставок"); + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/MotorPlant/MotorPlantView/FormMain.Designer.cs b/MotorPlant/MotorPlantView/FormMain.Designer.cs index db2de8d..fd8cd1f 100644 --- a/MotorPlant/MotorPlantView/FormMain.Designer.cs +++ b/MotorPlant/MotorPlantView/FormMain.Designer.cs @@ -1,204 +1,213 @@ namespace MotorPlantView.Forms { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// 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 + #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() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); - toolStrip1 = new ToolStrip(); - toolStripDropDownButton1 = new ToolStripDropDownButton(); - Компоненты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(); - operationToolStripMenuItem = new ToolStripMenuItem(); - transactionToolStripMenuItem = new ToolStripMenuItem(); - toolStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // toolStrip1 - // - toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, operationToolStripMenuItem }); - toolStrip1.Location = new Point(0, 0); - toolStrip1.Name = "toolStrip1"; - toolStrip1.Size = new Size(969, 25); - toolStrip1.TabIndex = 0; - toolStrip1.Text = "toolStrip1"; - // - // toolStripDropDownButton1 - // - toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, магазиныToolStripMenuItem }); - toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); - toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; - toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - toolStripDropDownButton1.Size = new Size(88, 22); - toolStripDropDownButton1.Text = "Справочник"; - // - // КомпонентыToolStripMenuItem - // - КомпонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - КомпонентыToolStripMenuItem.Size = new Size(174, 22); - КомпонентыToolStripMenuItem.Text = "Компоненты"; - КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; - // - // ДвигателиToolStripMenuItem - // - ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; - ДвигателиToolStripMenuItem.Size = new Size(174, 22); - ДвигателиToolStripMenuItem.Text = "Двигатели"; - ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; - // - // магазиныToolStripMenuItem - // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(180, 22); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(800, 56); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(141, 24); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += buttonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(800, 100); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(141, 24); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(800, 142); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(141, 24); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += buttonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(800, 181); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(141, 24); - buttonIssuedOrder.TabIndex = 4; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += buttonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(800, 222); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(141, 24); - buttonRef.TabIndex = 5; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += buttonRef_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 26); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(763, 435); - dataGridView.TabIndex = 6; - // - // operationToolStripMenuItem - // - operationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { transactionToolStripMenuItem }); - operationToolStripMenuItem.Name = "operationToolStripMenuItem"; - operationToolStripMenuItem.Size = new Size(75, 25); - operationToolStripMenuItem.Text = "Операции"; - // - // transactionToolStripMenuItem - // - transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; - transactionToolStripMenuItem.Size = new Size(180, 22); - transactionToolStripMenuItem.Text = "Поставка"; - transactionToolStripMenuItem.Click += transactionToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(969, 461); - Controls.Add(dataGridView); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(toolStrip1); - Name = "FormMain"; - Text = "Моторный завод"; - Load += FormMain_Load; - toolStrip1.ResumeLayout(false); - toolStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + ДвигателиToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + operationToolStripMenuItem = new ToolStripMenuItem(); + transactionToolStripMenuItem = new ToolStripMenuItem(); + продажаToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + toolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, operationToolStripMenuItem }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(969, 25); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, магазиныToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(88, 22); + toolStripDropDownButton1.Text = "Справочник"; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // ДвигателиToolStripMenuItem + // + ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; + ДвигателиToolStripMenuItem.Size = new Size(180, 22); + ДвигателиToolStripMenuItem.Text = "Двигатели"; + ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(800, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(141, 24); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(800, 100); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(141, 24); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(800, 142); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(141, 24); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(800, 181); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(141, 24); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(800, 222); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(141, 24); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(763, 435); + dataGridView.TabIndex = 6; + // + // operationToolStripMenuItem + // + operationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { transactionToolStripMenuItem, продажаToolStripMenuItem }); + operationToolStripMenuItem.Name = "operationToolStripMenuItem"; + operationToolStripMenuItem.Size = new Size(75, 25); + operationToolStripMenuItem.Text = "Операции"; + // + // transactionToolStripMenuItem + // + transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; + transactionToolStripMenuItem.Size = new Size(180, 22); + transactionToolStripMenuItem.Text = "Поставка"; + transactionToolStripMenuItem.Click += transactionToolStripMenuItem_Click; + // + // продажаToolStripMenuItem + // + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(180, 22); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(180, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(969, 461); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(toolStrip1); + Name = "FormMain"; + Text = "Моторный завод"; + Load += FormMain_Load; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ToolStrip toolStrip1; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private DataGridView dataGridView; - private ToolStripDropDownButton toolStripDropDownButton1; - private ToolStripMenuItem КомпонентыToolStripMenuItem; - private ToolStripMenuItem ДвигателиToolStripMenuItem; - private ToolStripMenuItem магазиныToolStripMenuItem; - private ToolStripMenuItem operationToolStripMenuItem; - private ToolStripMenuItem transactionToolStripMenuItem; - } + private ToolStrip toolStrip1; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem ДвигателиToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem operationToolStripMenuItem; + private ToolStripMenuItem transactionToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormMain.cs b/MotorPlant/MotorPlantView/FormMain.cs index 5b9a158..4c036a0 100644 --- a/MotorPlant/MotorPlantView/FormMain.cs +++ b/MotorPlant/MotorPlantView/FormMain.cs @@ -4,159 +4,167 @@ using MotorPlantContracts.BusinessLogicsContracts; namespace MotorPlantView.Forms { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["EngineId"].Visible = false; - dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["EngineId"].Visible = false; + dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - } - } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormEngines)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEngines)); - if (service is FormEngines form) - { - form.ShowDialog(); - } - } - private void buttonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void buttonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void shopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - private void transactionToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); - if (service is FormCreateSupply form) - { - form.ShowDialog(); - } - } - } + if (service is FormEngines form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellEngines)); + if (service is FormSellEngines form) + { + form.ShowDialog(); + } + } + } } diff --git a/MotorPlant/MotorPlantView/FormMain.resx b/MotorPlant/MotorPlantView/FormMain.resx index c354583..1af7de1 100644 --- a/MotorPlant/MotorPlantView/FormMain.resx +++ b/MotorPlant/MotorPlantView/FormMain.resx @@ -1,17 +1,17 @@  - @@ -117,7 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormSellEngines.Designer.cs b/MotorPlant/MotorPlantView/FormSellEngines.Designer.cs new file mode 100644 index 0000000..4cf010d --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSellEngines.Designer.cs @@ -0,0 +1,124 @@ +namespace MotorPlantView.Forms +{ + partial class FormSellEngines + { + /// + /// 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() + { + labelEngine = new Label(); + comboBoxEngine = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSell = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelEngine + // + labelEngine.AutoSize = true; + labelEngine.Location = new Point(10, 10); + labelEngine.Name = "labelEngine"; + labelEngine.Size = new Size(69, 15); + labelEngine.TabIndex = 0; + labelEngine.Text = "Двигатель: "; + // + // comboBoxEngine + // + comboBoxEngine.FormattingEnabled = true; + comboBoxEngine.Location = new Point(101, 8); + comboBoxEngine.Margin = new Padding(3, 2, 3, 2); + comboBoxEngine.Name = "comboBoxEngine"; + comboBoxEngine.Size = new Size(210, 23); + comboBoxEngine.TabIndex = 1; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(10, 41); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 2; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new Point(101, 39); + textBoxCount.Margin = new Padding(3, 2, 3, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(210, 23); + textBoxCount.TabIndex = 3; + // + // buttonSell + // + buttonSell.Location = new Point(112, 74); + buttonSell.Margin = new Padding(3, 2, 3, 2); + buttonSell.Name = "buttonSell"; + buttonSell.Size = new Size(82, 22); + buttonSell.TabIndex = 4; + buttonSell.Text = "Продать"; + buttonSell.UseVisualStyleBackColor = true; + buttonSell.Click += ButtonSell_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(212, 74); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 22); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellEngines + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(320, 105); + Controls.Add(buttonCancel); + Controls.Add(buttonSell); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxEngine); + Controls.Add(labelEngine); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellEngines"; + Text = "Продажа двигателей"; + Load += FormSellingEngine_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelEngine; + private ComboBox comboBoxEngine; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormSellEngines.cs b/MotorPlant/MotorPlantView/FormSellEngines.cs new file mode 100644 index 0000000..397170e --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSellEngines.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.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 MotorPlantView.Forms +{ + public partial class FormSellEngines : Form + { + private readonly ILogger _logger; + private readonly IEngineLogic _logicP; + private readonly IShopLogic _logicS; + private List _EngineList = new List(); + public FormSellEngines(ILogger logger, IEngineLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + private void FormSellingEngine_Load(object sender, EventArgs e) + { + _EngineList = _logicP.ReadList(null); + if (_EngineList != null) + { + comboBoxEngine.DisplayMember = "EngineName"; + comboBoxEngine.ValueMember = "Id"; + comboBoxEngine.DataSource = _EngineList; + comboBoxEngine.SelectedItem = null; + _logger.LogInformation("Загрузка двигателей для продажи"); + } + } + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sale(new SupplySearchModel + { + EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + 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/MotorPlant/MotorPlantView/FormSellEngines.resx b/MotorPlant/MotorPlantView/FormSellEngines.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSellEngines.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShop.Designer.cs b/MotorPlant/MotorPlantView/FormShop.Designer.cs index e594bf7..7001a3d 100644 --- a/MotorPlant/MotorPlantView/FormShop.Designer.cs +++ b/MotorPlant/MotorPlantView/FormShop.Designer.cs @@ -1,196 +1,222 @@ -namespace MotorPlantView +namespace MotorPlantView.Forms { - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormShop + { + /// + /// 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); - } + /// + /// 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 + #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() - { - labelName = new Label(); - textBoxName = new TextBox(); - textBoxAdress = new TextBox(); - labelAdress = new Label(); - buttonCancel = new Button(); - buttonSave = new Button(); - dataGridView = new DataGridView(); - label1 = new Label(); - dateTimeOpen = new DateTimePicker(); - id = new DataGridViewTextBoxColumn(); - EngineName = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(10, 11); - labelName.Name = "labelName"; - labelName.Size = new Size(65, 15); - labelName.TabIndex = 0; - labelName.Text = "Название: "; - // - // textBoxName - // - textBoxName.Location = new Point(89, 9); - textBoxName.Margin = new Padding(3, 2, 3, 2); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(242, 23); - textBoxName.TabIndex = 1; - // - // textBoxAdress - // - textBoxAdress.Location = new Point(89, 44); - textBoxAdress.Margin = new Padding(3, 2, 3, 2); - textBoxAdress.Name = "textBoxAdress"; - textBoxAdress.Size = new Size(374, 23); - textBoxAdress.TabIndex = 3; - // - // labelAdress - // - labelAdress.AutoSize = true; - labelAdress.Location = new Point(10, 46); - labelAdress.Name = "labelAdress"; - labelAdress.Size = new Size(46, 15); - labelAdress.TabIndex = 2; - labelAdress.Text = "Адрес: "; - // - // buttonCancel - // - buttonCancel.Location = new Point(395, 343); - buttonCancel.Margin = new Padding(3, 2, 3, 2); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(114, 33); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // buttonSave - // - buttonSave.Location = new Point(276, 343); - buttonSave.Margin = new Padding(3, 2, 3, 2); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(114, 33); - buttonSave.TabIndex = 6; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, EngineName, Count }); - dataGridView.Location = new Point(10, 108); - dataGridView.Margin = new Padding(3, 2, 3, 2); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; - dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(498, 230); - dataGridView.TabIndex = 7; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(10, 77); - label1.Name = "label1"; - label1.Size = new Size(87, 15); - label1.TabIndex = 8; - label1.Text = "Дата открытия"; - // - // dateTimeOpen - // - dateTimeOpen.Location = new Point(112, 77); - dateTimeOpen.Margin = new Padding(3, 2, 3, 2); - dateTimeOpen.Name = "dateTimeOpen"; - dateTimeOpen.Size = new Size(351, 23); - dateTimeOpen.TabIndex = 9; - // - // id - // - id.HeaderText = "id"; - id.MinimumWidth = 6; - id.Name = "id"; - id.ReadOnly = true; - id.Visible = false; - // - // EngineName - // - EngineName.HeaderText = "Двигатель"; - EngineName.MinimumWidth = 6; - EngineName.Name = "EngineName"; - EngineName.ReadOnly = true; - // - // Count - // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.ReadOnly = true; - // - // FormShop - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(519, 385); - Controls.Add(dateTimeOpen); - Controls.Add(label1); - Controls.Add(dataGridView); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxAdress); - Controls.Add(labelAdress); - Controls.Add(textBoxName); - Controls.Add(labelName); - Margin = new Padding(3, 2, 3, 2); - Name = "FormShop"; - Text = "Магазин"; - Load += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.labelAdress = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.EngineName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimeOpen = new System.Windows.Forms.DateTimePicker(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpEngineMaxCount = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpEngineMaxCount)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(11, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(102, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 27); + this.textBoxName.TabIndex = 1; + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(102, 59); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(427, 27); + this.textBoxAdress.TabIndex = 3; + // + // labelAdress + // + this.labelAdress.AutoSize = true; + this.labelAdress.Location = new System.Drawing.Point(11, 61); + this.labelAdress.Name = "labelAdress"; + this.labelAdress.Size = new System.Drawing.Size(58, 20); + this.labelAdress.TabIndex = 2; + this.labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(451, 457); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(130, 44); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(315, 457); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 44); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.EngineName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 185); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(569, 266); + this.dataGridView.TabIndex = 7; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // EngineName + // + this.EngineName.HeaderText = "Двигатель"; + this.EngineName.MinimumWidth = 6; + this.EngineName.Name = "EngineName"; + this.EngineName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 103); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 20); + this.label1.TabIndex = 8; + this.label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + this.dateTimeOpen.Location = new System.Drawing.Point(128, 103); + this.dateTimeOpen.Name = "dateTimeOpen"; + this.dateTimeOpen.Size = new System.Drawing.Size(401, 27); + this.dateTimeOpen.TabIndex = 9; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 148); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 20); + this.label2.TabIndex = 10; + this.label2.Text = "Вместимость"; + // + // numericUpEngineMaxCount + // + this.numericUpEngineMaxCount.Location = new System.Drawing.Point(128, 146); + this.numericUpEngineMaxCount.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.numericUpEngineMaxCount.Name = "numericUpEngineMaxCount"; + this.numericUpEngineMaxCount.Size = new System.Drawing.Size(401, 27); + this.numericUpEngineMaxCount.TabIndex = 11; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(593, 513); + this.Controls.Add(this.numericUpEngineMaxCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.dateTimeOpen); + this.Controls.Add(this.label1); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.labelAdress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpEngineMaxCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); - #endregion + } - private Label labelName; - private TextBox textBoxName; - private TextBox textBoxAdress; - private Label labelAdress; - private Button buttonCancel; - private Button buttonSave; - private DataGridView dataGridView; - private Label label1; - private DateTimePicker dateTimeOpen; - private DataGridViewTextBoxColumn id; - private DataGridViewTextBoxColumn EngineName; - private DataGridViewTextBoxColumn Count; - } + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn EngineName; + private DataGridViewTextBoxColumn Count; + private Label label1; + private DateTimePicker dateTimeOpen; + private Label label2; + private NumericUpDown numericUpEngineMaxCount; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShop.cs b/MotorPlant/MotorPlantView/FormShop.cs index 061b129..9325dcf 100644 --- a/MotorPlant/MotorPlantView/FormShop.cs +++ b/MotorPlant/MotorPlantView/FormShop.cs @@ -13,111 +13,113 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace MotorPlantView +namespace MotorPlantView.Forms { - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - private int? _id; - public int Id { set { _id = value; } } - private Dictionary _ShopEngines; - private DateTime? _openingDate = null; - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _ShopEngines = new Dictionary(); - } - private void FormShop_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка магазина"); - try - { - var view = _logic.ReadElement(new ShopSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.ShopName; - textBoxAdress.Text = view.Adress; - dateTimeOpen.Value = view.OpeningDate; - _ShopEngines = view.ShopEngines ?? new Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка изделий в магазине"); - try - { - if (_ShopEngines != null) - { - dataGridView.Rows.Clear(); - foreach (var sr in _ShopEngines) - { - dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.EngineName, sr.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделий магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void buttonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAdress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение магазина"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Adress = textBoxAdress.Text, - OpeningDate = dateTimeOpen.Value - }; - var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void buttonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopEngines; + private DateTime? _openingDate = null; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopEngines = new Dictionary(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + numericUpEngineMaxCount.Value = view.EngineMaxCount; + _ShopEngines = view.ShopEngines ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopEngines != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopEngines) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.EngineName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.Value, + EngineMaxCount = (int)numericUpEngineMaxCount.Value + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/MotorPlant/MotorPlantView/FormShops.Designer.cs b/MotorPlant/MotorPlantView/FormShops.Designer.cs index 7060727..b8349d6 100644 --- a/MotorPlant/MotorPlantView/FormShops.Designer.cs +++ b/MotorPlant/MotorPlantView/FormShops.Designer.cs @@ -1,130 +1,130 @@ -namespace MotorPlantView +namespace MotorPlantView.Forms { - partial class FormShops - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormShops + { + /// + /// 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); - } + /// + /// 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 + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.ToolsPanel = new System.Windows.Forms.Panel(); - this.buttonRef = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ToolsPanel.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // ToolsPanel - // - this.ToolsPanel.Controls.Add(this.buttonRef); - this.ToolsPanel.Controls.Add(this.buttonDel); - this.ToolsPanel.Controls.Add(this.buttonUpd); - this.ToolsPanel.Controls.Add(this.buttonAdd); - this.ToolsPanel.Location = new System.Drawing.Point(608, 12); - this.ToolsPanel.Name = "ToolsPanel"; - this.ToolsPanel.Size = new System.Drawing.Size(180, 426); - this.ToolsPanel.TabIndex = 3; - // - // buttonRef - // - this.buttonRef.Location = new System.Drawing.Point(31, 206); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(126, 36); - this.buttonRef.TabIndex = 3; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonDel - // - this.buttonDel.Location = new System.Drawing.Point(31, 142); - this.buttonDel.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(126, 36); - this.buttonDel.TabIndex = 2; - this.buttonDel.Text = "Удалить"; - this.buttonDel.UseVisualStyleBackColor = true; - this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // buttonUpd - // - this.buttonUpd.Location = new System.Drawing.Point(31, 76); - this.buttonUpd.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(126, 36); - this.buttonUpd.TabIndex = 1; - this.buttonUpd.Text = "Изменить"; - this.buttonUpd.UseVisualStyleBackColor = true; - this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(31, 16); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(126, 36); - this.buttonAdd.TabIndex = 0; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // dataGridView - // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 12); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(590, 426); - this.dataGridView.TabIndex = 2; - // - // FormShops - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.ToolsPanel); - this.Controls.Add(this.dataGridView); - this.Name = "FormShops"; - this.Text = "Магазины"; - this.Load += new System.EventHandler(this.FormShops_Load); - this.ToolsPanel.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); - } + } - #endregion + #endregion - private Panel ToolsPanel; - private Button buttonRef; - private Button buttonDel; - private Button buttonUpd; - private Button buttonAdd; - private DataGridView dataGridView; - } + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShops.cs b/MotorPlant/MotorPlantView/FormShops.cs index 47d2802..7345931 100644 --- a/MotorPlant/MotorPlantView/FormShops.cs +++ b/MotorPlant/MotorPlantView/FormShops.cs @@ -11,99 +11,99 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace MotorPlantView +namespace MotorPlantView.Forms { - public partial class FormShops : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - public FormShops(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - private void FormShops_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["ShopEngines"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка магазинов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop 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(FormShop)); - if (service is FormShop 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 ShopBindingModel - { - 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(); - } - } + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormShops_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["ShopEngines"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop 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(FormShop)); + if (service is FormShop 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 ShopBindingModel + { + 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/MotorPlant/MotorPlantView/MotorPlantView.csproj b/MotorPlant/MotorPlantView/MotorPlantView.csproj index 0c7b07f..ac49f7b 100644 --- a/MotorPlant/MotorPlantView/MotorPlantView.csproj +++ b/MotorPlant/MotorPlantView/MotorPlantView.csproj @@ -1,27 +1,27 @@  - - WinExe - net6.0-windows - enable - true - enable - + + WinExe + net6.0-windows + enable + true + enable + - - - - - - - - + + + + + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/Program.cs b/MotorPlant/MotorPlantView/Program.cs index 1b8c4f5..be5aa31 100644 --- a/MotorPlant/MotorPlantView/Program.cs +++ b/MotorPlant/MotorPlantView/Program.cs @@ -49,11 +49,12 @@ namespace MotorPlantView.Forms services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file