From adafe6d8eab380b81fa1d73155b94d5ce24a4cc5 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Mar 2023 16:01:12 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssemFileImplement/Implements/ShopStorage.cs | 3 ++- FurnitureAssembly/FurnitureAssembly/FormSell.cs | 1 + FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs index 7b77cdc..f90fe45 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs @@ -124,6 +124,7 @@ namespace FurnitureAssemFileImplement.Implements }); break; } + count -= shop.Furnitures[furniture.Id].Item2; shop.Furnitures[furniture.Id] = (shop.Furnitures[furniture.Id].Item1, 0); shop.Update(new ShopBindingModel { @@ -134,7 +135,7 @@ namespace FurnitureAssemFileImplement.Implements Address = shop.Address, DateOpening = shop.DateOpening, }); - count -= shop.Furnitures[furniture.Id].Item2; + } } source.SaveShops(); diff --git a/FurnitureAssembly/FurnitureAssembly/FormSell.cs b/FurnitureAssembly/FurnitureAssembly/FormSell.cs index 7a5fe9f..efe5584 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormSell.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormSell.cs @@ -106,6 +106,7 @@ namespace FurnitureAssembly { MessageBox.Show("Не удалось продать изделие " + FurnitureModel.FurnitureName, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs index 52d32f1..ba32c9c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs @@ -154,9 +154,9 @@ this.labelMaxCount.AutoSize = true; this.labelMaxCount.Location = new System.Drawing.Point(35, 141); this.labelMaxCount.Name = "labelMaxCount"; - this.labelMaxCount.Size = new System.Drawing.Size(40, 15); + this.labelMaxCount.Size = new System.Drawing.Size(80, 15); this.labelMaxCount.TabIndex = 10; - this.labelMaxCount.Text = "Адрес"; + this.labelMaxCount.Text = "Вместимость"; // // FormShop // From 511bdf96b78e5f23f5584e4f18bfa55fee9731bf Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Mar 2023 16:19:26 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/FormMain.cs | 25 +------ .../FormReplenishmentShop.cs | 66 ++++++++----------- 2 files changed, 27 insertions(+), 64 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 78005a7..2ec8027 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -171,30 +171,7 @@ namespace FurnitureAssembly var service = Program.ServiceProvider?.GetService(typeof(FormReplenishmentShop)); if (service is FormReplenishmentShop form) { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ShopModel == null || form.FurnitureModel == null) - { - return; - } - _logger.LogInformation("Добавление в магазин {ShopName} изделия: { FurnitureName}- { Count}", form.ShopModel.ShopName, form.FurnitureModel.FurnitureName, form.Count); - - var modelShop = new ShopBindingModel - { - Id = form.Id - }; - - var modelFurn = new FurnitureBindingModel - { - Id = form.FurnitureId - }; - - var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count); - if (!operationResult) - { - throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); - } - } + form.ShowDialog(); } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormReplenishmentShop.cs b/FurnitureAssembly/FurnitureAssembly/FormReplenishmentShop.cs index 4ae0fb4..e08dfc7 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormReplenishmentShop.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormReplenishmentShop.cs @@ -2,6 +2,7 @@ using FurnitureAssemblyContracts.BusinessLogicsContarcts; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; using System; using System.Collections; using System.Collections.Generic; @@ -21,6 +22,9 @@ namespace FurnitureAssembly private readonly List? _listShops; private readonly List? _listFurnitures; + private IShopLogic _shopLogic; + private ILogger _logger; + public int Id { get @@ -32,25 +36,7 @@ namespace FurnitureAssembly comboBoxShop.SelectedValue = value; } } - public IShopModel? ShopModel - { - get - { - if (_listShops == null) - { - return null; - } - foreach (var elem in _listShops) - { - if (elem.Id == Id) - { - return elem; - } - } - return null; - } - } - + public int FurnitureId { get @@ -62,24 +48,6 @@ namespace FurnitureAssembly comboBoxFurniture.SelectedValue = value; } } - public IFurnitureModel? FurnitureModel - { - get - { - if (_listFurnitures == null) - { - return null; - } - foreach (var elem in _listFurnitures) - { - if (elem.Id == Id) - { - return elem; - } - } - return null; - } - } public int Count { @@ -87,9 +55,11 @@ namespace FurnitureAssembly set { textBoxCount.Text = value.ToString(); } } - public FormReplenishmentShop(IShopLogic shopLogic, IFurnitureLogic furnitureLogic) + public FormReplenishmentShop(ILogger logger, IShopLogic shopLogic, IFurnitureLogic furnitureLogic) { - InitializeComponent(); + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; _listShops = shopLogic.ReadList(null); _listFurnitures = furnitureLogic.ReadList(null); if (_listShops != null) @@ -134,7 +104,23 @@ namespace FurnitureAssembly MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - + + try + { + _logger.LogInformation("Добавление в магазин с id = {ShopName} изделия: id = { FurnitureName} - { Count}", Id, FurnitureId, Count); + var operationResult = _shopLogic.AddFurniture(new ShopBindingModel { Id = Id }, new FurnitureBindingModel { Id = FurnitureId }, Count); + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при пополнении магазина c id = " + Id); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); }