From 3e69e119b4ff3c4b92b07683ff12447cb135628a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:05:22 +0400 Subject: [PATCH 01/12] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D1=85?= =?UTF-8?q?=D0=B0=D1=80=D0=B4=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 21 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 9 + .../StoragesContracts/IShopStorage.cs | 21 +++ .../ViewModels/ShopViewModel.cs | 25 +++ .../Models/IShopModel.cs | 13 ++ .../BusinessLogics/ShopLogic.cs | 166 ++++++++++++++++++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 109 ++++++++++++ .../ConfectioneryListImplement/Models/Shop.cs | 60 +++++++ .../ConfectioneryView/FormShop.Designer.cs | 120 +++++++++++++ Confectionery/ConfectioneryView/FormShop.cs | 20 +++ Confectionery/ConfectioneryView/FormShop.resx | 60 +++++++ 13 files changed, 648 insertions(+) create mode 100644 Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs create mode 100644 Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs create mode 100644 Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs create mode 100644 Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/Models/IShopModel.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Shop.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.resx diff --git a/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs b/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..8490887 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPastries + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..c192940 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.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 MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count); + } +} diff --git a/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs b/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..f600852 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,9 @@ +namespace ConfectioneryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..04dd755 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; + +namespace ConfectioneryContracts.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); + } +} diff --git a/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..cd7f51e --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,25 @@ +using ConfectioneryDataModels.Models; +using System.ComponentModel; + +namespace ConfectioneryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPastries + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs b/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..38cc5ea --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs @@ -0,0 +1,13 @@ +namespace ConfectioneryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopPastries { get; } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..e46416e --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,166 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + 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 MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (Pastry == null) + { + throw new ArgumentNullException(nameof(Pastry)); + } + if (count <= 0) + { + throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); + } + _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("MakeShipment(GetElement). Element not found"); + return false; + } + if (shop.ShopPastries.ContainsKey(Pastry.Id)) + { + var shopIC = shop.ShopPastries[Pastry.Id]; + shopIC.Item2 += count; + shop.ShopPastries[Pastry.Id] = shopIC; + _logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + shop.ShopName); + } + else + { + shop.ShopPastries.Add(Pastry.Id, (Pastry, count)); + _logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopPastries = shop.ShopPastries, + }) == null) + { + _logger.LogWarning("MakeShipment. Update operation failed"); + return false; + } + 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.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index c823733..0243615 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -12,11 +12,13 @@ namespace ConfectioneryListImplement.Models public List Components { get; set; } public List Orders { get; set; } public List Pastries { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pastries = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2a88b9a --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,109 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; + +namespace ConfectioneryListImplement.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; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Shop.cs b/Confectionery/ConfectioneryListImplement/Models/Shop.cs new file mode 100644 index 0000000..6eecde0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Shop.cs @@ -0,0 +1,60 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopPastries + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopPastries = model.ShopPastries + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopPastries = model.ShopPastries; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopPastries = ShopPastries + }; + } +} diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs new file mode 100644 index 0000000..726492f --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -0,0 +1,120 @@ +namespace ConfectioneryView +{ + 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); + } + + #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.labelOpeningDate = new System.Windows.Forms.Label(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // labelOpeningDate + // + this.labelOpeningDate.AutoSize = true; + this.labelOpeningDate.Location = new System.Drawing.Point(31, 102); + this.labelOpeningDate.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelOpeningDate.Name = "labelOpeningDate"; + this.labelOpeningDate.Size = new System.Drawing.Size(117, 20); + this.labelOpeningDate.TabIndex = 12; + this.labelOpeningDate.Text = "Дата открытия :"; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(159, 98); + this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(249, 27); + this.dateTimePicker.TabIndex = 11; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(120, 59); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(287, 27); + this.textBoxAddress.TabIndex = 10; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(31, 63); + this.labelAddress.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(58, 20); + this.labelAddress.TabIndex = 9; + this.labelAddress.Text = "Адрес :"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(120, 19); + this.textBoxName.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(287, 27); + this.textBoxName.TabIndex = 8; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(31, 23); + this.labelName.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 7; + this.labelName.Text = "Название :"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 544); + this.Controls.Add(this.labelOpeningDate); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "FormShop"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelOpeningDate; + private DateTimePicker dateTimePicker; + private TextBox textBoxAddress; + private Label labelAddress; + private TextBox textBoxName; + private Label labelName; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs new file mode 100644 index 0000000..e872cd3 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -0,0 +1,20 @@ +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 ConfectioneryView +{ + public partial class FormShop : Form + { + public FormShop() + { + InitializeComponent(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormShop.resx b/Confectionery/ConfectioneryView/FormShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From de13199fe88a0f263250c029ba2385825229725a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:07:56 +0400 Subject: [PATCH 02/12] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormShop.Designer.cs | 104 +++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index 726492f..bb85298 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -34,6 +34,15 @@ this.labelAddress = new System.Windows.Forms.Label(); this.textBoxName = new System.Windows.Forms.TextBox(); this.labelName = new System.Windows.Forms.Label(); + this.groupBoxPastries = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxPastries.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // // labelOpeningDate @@ -90,11 +99,93 @@ this.labelName.TabIndex = 7; this.labelName.Text = "Название :"; // + // groupBoxPastries + // + this.groupBoxPastries.Controls.Add(this.dataGridView); + this.groupBoxPastries.Location = new System.Drawing.Point(31, 133); + this.groupBoxPastries.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.groupBoxPastries.Name = "groupBoxPastries"; + this.groupBoxPastries.Padding = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.groupBoxPastries.Size = new System.Drawing.Size(536, 384); + this.groupBoxPastries.TabIndex = 13; + this.groupBoxPastries.TabStop = false; + this.groupBoxPastries.Text = "Выпечка"; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(5, 24); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(522, 356); + this.dataGridView.TabIndex = 0; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(449, 529); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(330, 529); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Visible = false; + this.ColumnId.Width = 125; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnName.HeaderText = "Название выпечки"; + this.ColumnName.MinimumWidth = 6; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + this.ColumnCount.Width = 125; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 544); + this.ClientSize = new System.Drawing.Size(603, 578); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxPastries); this.Controls.Add(this.labelOpeningDate); this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.textBoxAddress); @@ -102,7 +193,9 @@ this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelName); this.Name = "FormShop"; - this.Text = "FormShop"; + this.Text = "Магазин"; + this.groupBoxPastries.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -116,5 +209,12 @@ private Label labelAddress; private TextBox textBoxName; private Label labelName; + private GroupBox groupBoxPastries; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file -- 2.25.1 From 36ed1f21b081729a4293a7c0b88246e2b5ff664f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:23:37 +0400 Subject: [PATCH 03/12] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormCreateOrder.cs | 4 +- .../ConfectioneryView/FormPastries.cs | 4 +- .../ConfectioneryView/FormShop.Designer.cs | 3 + Confectionery/ConfectioneryView/FormShop.cs | 115 +++++++++++++++- .../ConfectioneryView/FormShops.Designer.cs | 127 ++++++++++++++++++ Confectionery/ConfectioneryView/FormShops.cs | 111 +++++++++++++++ .../ConfectioneryView/FormShops.resx | 60 +++++++++ 7 files changed, 419 insertions(+), 5 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormShops.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.resx diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index a448d9b..b903b1b 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -29,7 +29,7 @@ namespace ConfectioneryView private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Loading ice cream for order"); + _logger.LogInformation("Loading pastry for order"); try { var pastryList = _logicP.ReadList(null); @@ -43,7 +43,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Error during loading ice cream for order"); + _logger.LogError(ex, "Error during loading pastry for order"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs index 7932f5b..508f6cc 100644 --- a/Confectionery/ConfectioneryView/FormPastries.cs +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -86,7 +86,7 @@ namespace ConfectioneryView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Deletion of ice cream"); + _logger.LogInformation("Deletion of pastry"); try { if (!_logic.Delete(new PastryBindingModel { Id = id })) @@ -97,7 +97,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ice cream deletion error"); + _logger.LogError(ex, "Pastry deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index bb85298..dea22e8 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -142,6 +142,7 @@ this.buttonCancel.TabIndex = 15; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -152,6 +153,7 @@ this.buttonSave.TabIndex = 14; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // ColumnId // @@ -194,6 +196,7 @@ this.Controls.Add(this.labelName); this.Name = "FormShop"; this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); this.groupBoxPastries.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs index e872cd3..b9a3230 100644 --- a/Confectionery/ConfectioneryView/FormShop.cs +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -7,14 +7,127 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; namespace ConfectioneryView { public partial class FormShop : Form { - public FormShop() + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopPastries; + + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + _shopPastries = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + _shopPastries = view.ShopPastries ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop pastries loading"); + try + { + if (_shopPastries != null) + { + dataGridView.Rows.Clear(); + foreach (var pastry in _shopPastries) + { + dataGridView.Rows.Add(new object[] { pastry.Key, pastry.Value.Item1.PastryName, pastry.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop pastries loading error"); + 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(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + ShopPastries = _shopPastries + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/Confectionery/ConfectioneryView/FormShops.Designer.cs b/Confectionery/ConfectioneryView/FormShops.Designer.cs new file mode 100644 index 0000000..301e6bf --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.Designer.cs @@ -0,0 +1,127 @@ +namespace ConfectioneryView +{ + 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); + } + + #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.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(511, 221); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(101, 36); + this.buttonUpd.TabIndex = 16; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(511, 158); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(101, 36); + this.buttonDel.TabIndex = 15; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(511, 95); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(101, 36); + this.buttonEdit.TabIndex = 14; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(511, 37); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(101, 36); + this.buttonAdd.TabIndex = 13; + 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.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(466, 538); + this.dataGridView.TabIndex = 17; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(650, 538); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShops.cs b/Confectionery/ConfectioneryView/FormShops.cs new file mode 100644 index 0000000..77f6c7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryView +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopPastries"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + 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 ButtonEdit_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("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormShops.resx b/Confectionery/ConfectioneryView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From aff701fb60610f714452aa92a88d4047c15cbe72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 19:45:16 +0400 Subject: [PATCH 04/12] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- .../BusinessLogics/ShopLogic.cs | 12 +- .../ConfectioneryView/FormMain.Designer.cs | 24 ++- Confectionery/ConfectioneryView/FormMain.cs | 18 +++ .../ConfectioneryView/FormSupply.Designer.cs | 150 ++++++++++++++++++ Confectionery/ConfectioneryView/FormSupply.cs | 124 +++++++++++++++ .../ConfectioneryView/FormSupply.resx | 60 +++++++ Confectionery/ConfectioneryView/Program.cs | 5 + 8 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormSupply.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormSupply.cs create mode 100644 Confectionery/ConfectioneryView/FormSupply.resx diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs index c192940..5cd6016 100644 --- a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,6 @@ namespace ConfectioneryContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count); + bool Supply(ShopSearchModel shopModel, IPastryModel pastry, int count); } } diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs index e46416e..47becbd 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -84,7 +84,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return true; } - public bool MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count) + public bool Supply(ShopSearchModel shopModel, IPastryModel Pastry, int count) { if (shopModel == null) { @@ -98,11 +98,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); } - _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + _logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); if (shop == null) { - _logger.LogWarning("MakeShipment(GetElement). Element not found"); + _logger.LogWarning("Supply(GetElement). Element not found"); return false; } if (shop.ShopPastries.ContainsKey(Pastry.Id)) @@ -110,13 +110,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics var shopIC = shop.ShopPastries[Pastry.Id]; shopIC.Item2 += count; shop.ShopPastries[Pastry.Id] = shopIC; - _logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } else { shop.ShopPastries.Add(Pastry.Id, (Pastry, count)); - _logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -128,7 +128,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics ShopPastries = shop.ShopPastries, }) == null) { - _logger.LogWarning("MakeShipment. Update operation failed"); + _logger.LogWarning("Supply. Update operation failed"); return false; } return true; diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index a1b389c..7356071 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -32,6 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.ButtonCreateOrder = new System.Windows.Forms.Button(); this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -46,7 +48,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1376, 28); @@ -57,7 +60,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -76,6 +80,20 @@ this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); + // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -172,5 +190,7 @@ private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index a2460ec..5aec936 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -68,6 +68,24 @@ namespace ConfectioneryView } } + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/Confectionery/ConfectioneryView/FormSupply.Designer.cs b/Confectionery/ConfectioneryView/FormSupply.Designer.cs new file mode 100644 index 0000000..040d631 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.Designer.cs @@ -0,0 +1,150 @@ +namespace ConfectioneryView +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.labelPastry = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(312, 170); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 19; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(205, 170); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 18; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(139, 128); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(287, 27); + this.textBoxCount.TabIndex = 17; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 132); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 16; + this.labelCount.Text = "Количество:"; + // + // comboBoxPastry + // + this.comboBoxPastry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(139, 80); + this.comboBoxPastry.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(287, 28); + this.comboBoxPastry.TabIndex = 15; + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(38, 85); + this.labelPastry.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(72, 20); + this.labelPastry.TabIndex = 14; + this.labelPastry.Text = "Выпечка:"; + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(139, 34); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(287, 28); + this.comboBoxShop.TabIndex = 13; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(38, 38); + this.labelShop.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(72, 20); + this.labelShop.TabIndex = 12; + this.labelShop.Text = "Магазин:"; + // + // FormSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 233); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelPastry); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormSupply"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxPastry; + private Label labelPastry; + private ComboBox comboBoxShop; + private Label labelShop; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs new file mode 100644 index 0000000..912a410 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -0,0 +1,124 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormSupply : Form + { + private readonly ILogger _logger; + + private readonly IPastryLogic _logicPastry; + + private readonly IShopLogic _logicShop; + public FormSupply(ILogger logger, IPastryLogic logicPastry, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPastry = logicPastry; + _logicShop = logicShop; + } + + private void FormSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicPastry.ReadList(null); + if (list != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = list; + comboBoxPastry.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var pastry = _logicPastry.ReadElement(new PastrySearchModel + { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }); + if (pastry == null) + { + throw new Exception("Мороженое не найдено."); + } + var operationResult = _logicShop.Supply(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + pastry, + 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, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormSupply.resx b/Confectionery/ConfectioneryView/FormSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index cebaeea..af295d5 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -36,10 +36,12 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +50,9 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From b6d44d2abd308513db44bb241602cc9e54617d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 19:58:34 +0400 Subject: [PATCH 05/12] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201=20=D1=85=D0=B0=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/ConfectioneryView/FormSupply.Designer.cs | 3 +++ Confectionery/ConfectioneryView/FormSupply.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormSupply.Designer.cs b/Confectionery/ConfectioneryView/FormSupply.Designer.cs index 040d631..e8c598d 100644 --- a/Confectionery/ConfectioneryView/FormSupply.Designer.cs +++ b/Confectionery/ConfectioneryView/FormSupply.Designer.cs @@ -47,6 +47,7 @@ this.buttonCancel.TabIndex = 19; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -57,6 +58,7 @@ this.buttonSave.TabIndex = 18; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // textBoxCount // @@ -131,6 +133,7 @@ this.Controls.Add(this.labelShop); this.Name = "FormSupply"; this.Text = "Пополнение магазина"; + this.Load += new System.EventHandler(this.FormSupply_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs index 912a410..ad01fbb 100644 --- a/Confectionery/ConfectioneryView/FormSupply.cs +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -30,7 +30,7 @@ namespace ConfectioneryView private void FormSupply_Load(object sender, EventArgs e) { - _logger.LogInformation("Ice creams loading"); + _logger.LogInformation("Pastries loading"); try { var list = _logicPastry.ReadList(null); @@ -44,7 +44,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ice creams loading error"); + _logger.LogError(ex, "Pastries loading error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } _logger.LogInformation("Shops loading"); -- 2.25.1 From 066a366922a7d2911d9fd17564017b9c669dbe9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 1 Apr 2024 13:01:23 +0400 Subject: [PATCH 06/12] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D1=85=D0=B0=D1=80?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 8 +-- .../ConfectioneryView/FormMain.Designer.cs | 2 +- .../ConfectioneryView/FormShop.Designer.cs | 62 +++++++++---------- .../ConfectioneryView/FormShops.Designer.cs | 2 +- Confectionery/ConfectioneryView/FormSupply.cs | 4 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs index 47becbd..97b650b 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -96,7 +96,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (count <= 0) { - throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); + throw new ArgumentException("Количество товаров(выпечки) в магазине должно быть больше нуля", nameof(count)); } _logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); @@ -107,9 +107,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (shop.ShopPastries.ContainsKey(Pastry.Id)) { - var shopIC = shop.ShopPastries[Pastry.Id]; - shopIC.Item2 += count; - shop.ShopPastries[Pastry.Id] = shopIC; + var shopP = shop.ShopPastries[Pastry.Id]; + shopP.Item2 += count; + shop.ShopPastries[Pastry.Id] = shopP; _logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 7356071..320c09a 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -77,7 +77,7 @@ // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Text = "Выпечка"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // магазиныToolStripMenuItem diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index dea22e8..b0a9b9a 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -36,11 +36,11 @@ this.labelName = new System.Windows.Forms.Label(); this.groupBoxPastries = new System.Windows.Forms.GroupBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); this.groupBoxPastries.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -51,9 +51,9 @@ this.labelOpeningDate.Location = new System.Drawing.Point(31, 102); this.labelOpeningDate.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelOpeningDate.Name = "labelOpeningDate"; - this.labelOpeningDate.Size = new System.Drawing.Size(117, 20); + this.labelOpeningDate.Size = new System.Drawing.Size(113, 20); this.labelOpeningDate.TabIndex = 12; - this.labelOpeningDate.Text = "Дата открытия :"; + this.labelOpeningDate.Text = "Дата открытия:"; // // dateTimePicker // @@ -77,9 +77,9 @@ this.labelAddress.Location = new System.Drawing.Point(31, 63); this.labelAddress.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(58, 20); + this.labelAddress.Size = new System.Drawing.Size(54, 20); this.labelAddress.TabIndex = 9; - this.labelAddress.Text = "Адрес :"; + this.labelAddress.Text = "Адрес:"; // // textBoxName // @@ -95,9 +95,9 @@ this.labelName.Location = new System.Drawing.Point(31, 23); this.labelName.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.Size = new System.Drawing.Size(80, 20); this.labelName.TabIndex = 7; - this.labelName.Text = "Название :"; + this.labelName.Text = "Название:"; // // groupBoxPastries // @@ -115,7 +115,7 @@ // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ColumnId, @@ -133,28 +133,6 @@ this.dataGridView.Size = new System.Drawing.Size(522, 356); this.dataGridView.TabIndex = 0; // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(449, 529); - this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(101, 36); - this.buttonCancel.TabIndex = 15; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(330, 529); - this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(101, 36); - this.buttonSave.TabIndex = 14; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // // ColumnId // this.ColumnId.HeaderText = "Id"; @@ -180,6 +158,28 @@ this.ColumnCount.ReadOnly = true; this.ColumnCount.Width = 125; // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(449, 529); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(330, 529); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); diff --git a/Confectionery/ConfectioneryView/FormShops.Designer.cs b/Confectionery/ConfectioneryView/FormShops.Designer.cs index 301e6bf..6e4e0bd 100644 --- a/Confectionery/ConfectioneryView/FormShops.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShops.Designer.cs @@ -84,7 +84,7 @@ // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; this.dataGridView.Location = new System.Drawing.Point(0, 0); diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs index ad01fbb..edba0c4 100644 --- a/Confectionery/ConfectioneryView/FormSupply.cs +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -75,7 +75,7 @@ namespace ConfectioneryView } if (comboBoxPastry.SelectedValue == null) { - MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxCount.Text)) @@ -90,7 +90,7 @@ namespace ConfectioneryView { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }); if (pastry == null) { - throw new Exception("Мороженое не найдено."); + throw new Exception("Выпечка не найдена."); } var operationResult = _logicShop.Supply(new ShopSearchModel { -- 2.25.1 From 07426d797916e8dad60e2add5463b7d5738d26f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:05:22 +0400 Subject: [PATCH 07/12] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D1=85?= =?UTF-8?q?=D0=B0=D1=80=D0=B4=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 21 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 9 + .../StoragesContracts/IShopStorage.cs | 21 +++ .../ViewModels/ShopViewModel.cs | 25 +++ .../Models/IShopModel.cs | 13 ++ .../BusinessLogics/ShopLogic.cs | 166 ++++++++++++++++++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 109 ++++++++++++ .../ConfectioneryListImplement/Models/Shop.cs | 60 +++++++ .../ConfectioneryView/FormShop.Designer.cs | 120 +++++++++++++ Confectionery/ConfectioneryView/FormShop.cs | 20 +++ Confectionery/ConfectioneryView/FormShop.resx | 60 +++++++ 13 files changed, 648 insertions(+) create mode 100644 Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs create mode 100644 Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs create mode 100644 Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs create mode 100644 Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs create mode 100644 Confectionery/ConfectionaryDataModels/Models/IShopModel.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Shop.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.cs create mode 100644 Confectionery/ConfectioneryView/FormShop.resx diff --git a/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs b/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..8490887 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPastries + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..c192940 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.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 MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count); + } +} diff --git a/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs b/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..f600852 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,9 @@ +namespace ConfectioneryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..04dd755 --- /dev/null +++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; + +namespace ConfectioneryContracts.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); + } +} diff --git a/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs b/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..cd7f51e --- /dev/null +++ b/Confectionery/ConfectionaryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,25 @@ +using ConfectioneryDataModels.Models; +using System.ComponentModel; + +namespace ConfectioneryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPastries + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs b/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..38cc5ea --- /dev/null +++ b/Confectionery/ConfectionaryDataModels/Models/IShopModel.cs @@ -0,0 +1,13 @@ +namespace ConfectioneryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopPastries { get; } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..e46416e --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,166 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + 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 MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (Pastry == null) + { + throw new ArgumentNullException(nameof(Pastry)); + } + if (count <= 0) + { + throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); + } + _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("MakeShipment(GetElement). Element not found"); + return false; + } + if (shop.ShopPastries.ContainsKey(Pastry.Id)) + { + var shopIC = shop.ShopPastries[Pastry.Id]; + shopIC.Item2 += count; + shop.ShopPastries[Pastry.Id] = shopIC; + _logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + shop.ShopName); + } + else + { + shop.ShopPastries.Add(Pastry.Id, (Pastry, count)); + _logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopPastries = shop.ShopPastries, + }) == null) + { + _logger.LogWarning("MakeShipment. Update operation failed"); + return false; + } + 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.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index c823733..0243615 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -12,11 +12,13 @@ namespace ConfectioneryListImplement.Models public List Components { get; set; } public List Orders { get; set; } public List Pastries { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pastries = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2a88b9a --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,109 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; + +namespace ConfectioneryListImplement.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; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Shop.cs b/Confectionery/ConfectioneryListImplement/Models/Shop.cs new file mode 100644 index 0000000..6eecde0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Shop.cs @@ -0,0 +1,60 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopPastries + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopPastries = model.ShopPastries + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopPastries = model.ShopPastries; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopPastries = ShopPastries + }; + } +} diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs new file mode 100644 index 0000000..726492f --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -0,0 +1,120 @@ +namespace ConfectioneryView +{ + 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); + } + + #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.labelOpeningDate = new System.Windows.Forms.Label(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // labelOpeningDate + // + this.labelOpeningDate.AutoSize = true; + this.labelOpeningDate.Location = new System.Drawing.Point(31, 102); + this.labelOpeningDate.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelOpeningDate.Name = "labelOpeningDate"; + this.labelOpeningDate.Size = new System.Drawing.Size(117, 20); + this.labelOpeningDate.TabIndex = 12; + this.labelOpeningDate.Text = "Дата открытия :"; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(159, 98); + this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(249, 27); + this.dateTimePicker.TabIndex = 11; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(120, 59); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(287, 27); + this.textBoxAddress.TabIndex = 10; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(31, 63); + this.labelAddress.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(58, 20); + this.labelAddress.TabIndex = 9; + this.labelAddress.Text = "Адрес :"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(120, 19); + this.textBoxName.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(287, 27); + this.textBoxName.TabIndex = 8; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(31, 23); + this.labelName.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 7; + this.labelName.Text = "Название :"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 544); + this.Controls.Add(this.labelOpeningDate); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "FormShop"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelOpeningDate; + private DateTimePicker dateTimePicker; + private TextBox textBoxAddress; + private Label labelAddress; + private TextBox textBoxName; + private Label labelName; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs new file mode 100644 index 0000000..e872cd3 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -0,0 +1,20 @@ +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 ConfectioneryView +{ + public partial class FormShop : Form + { + public FormShop() + { + InitializeComponent(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormShop.resx b/Confectionery/ConfectioneryView/FormShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShop.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From e0ef828fe2b6a86ad49b4523f8cef591c721e1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:07:56 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormShop.Designer.cs | 104 +++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index 726492f..bb85298 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -34,6 +34,15 @@ this.labelAddress = new System.Windows.Forms.Label(); this.textBoxName = new System.Windows.Forms.TextBox(); this.labelName = new System.Windows.Forms.Label(); + this.groupBoxPastries = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxPastries.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // // labelOpeningDate @@ -90,11 +99,93 @@ this.labelName.TabIndex = 7; this.labelName.Text = "Название :"; // + // groupBoxPastries + // + this.groupBoxPastries.Controls.Add(this.dataGridView); + this.groupBoxPastries.Location = new System.Drawing.Point(31, 133); + this.groupBoxPastries.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.groupBoxPastries.Name = "groupBoxPastries"; + this.groupBoxPastries.Padding = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.groupBoxPastries.Size = new System.Drawing.Size(536, 384); + this.groupBoxPastries.TabIndex = 13; + this.groupBoxPastries.TabStop = false; + this.groupBoxPastries.Text = "Выпечка"; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(5, 24); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(522, 356); + this.dataGridView.TabIndex = 0; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(449, 529); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(330, 529); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Visible = false; + this.ColumnId.Width = 125; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnName.HeaderText = "Название выпечки"; + this.ColumnName.MinimumWidth = 6; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + this.ColumnCount.Width = 125; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 544); + this.ClientSize = new System.Drawing.Size(603, 578); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxPastries); this.Controls.Add(this.labelOpeningDate); this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.textBoxAddress); @@ -102,7 +193,9 @@ this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelName); this.Name = "FormShop"; - this.Text = "FormShop"; + this.Text = "Магазин"; + this.groupBoxPastries.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -116,5 +209,12 @@ private Label labelAddress; private TextBox textBoxName; private Label labelName; + private GroupBox groupBoxPastries; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file -- 2.25.1 From 96500096c834265be75c8b89ddeb94e8e8a5f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:23:37 +0400 Subject: [PATCH 09/12] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormShop.Designer.cs | 3 + Confectionery/ConfectioneryView/FormShop.cs | 115 +++++++++++++++- .../ConfectioneryView/FormShops.Designer.cs | 127 ++++++++++++++++++ Confectionery/ConfectioneryView/FormShops.cs | 111 +++++++++++++++ .../ConfectioneryView/FormShops.resx | 60 +++++++++ 5 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 Confectionery/ConfectioneryView/FormShops.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.resx diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index bb85298..dea22e8 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -142,6 +142,7 @@ this.buttonCancel.TabIndex = 15; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -152,6 +153,7 @@ this.buttonSave.TabIndex = 14; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // ColumnId // @@ -194,6 +196,7 @@ this.Controls.Add(this.labelName); this.Name = "FormShop"; this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); this.groupBoxPastries.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs index e872cd3..b9a3230 100644 --- a/Confectionery/ConfectioneryView/FormShop.cs +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -7,14 +7,127 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; namespace ConfectioneryView { public partial class FormShop : Form { - public FormShop() + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopPastries; + + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + _shopPastries = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + _shopPastries = view.ShopPastries ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop pastries loading"); + try + { + if (_shopPastries != null) + { + dataGridView.Rows.Clear(); + foreach (var pastry in _shopPastries) + { + dataGridView.Rows.Add(new object[] { pastry.Key, pastry.Value.Item1.PastryName, pastry.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop pastries loading error"); + 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(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + ShopPastries = _shopPastries + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/Confectionery/ConfectioneryView/FormShops.Designer.cs b/Confectionery/ConfectioneryView/FormShops.Designer.cs new file mode 100644 index 0000000..301e6bf --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.Designer.cs @@ -0,0 +1,127 @@ +namespace ConfectioneryView +{ + 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); + } + + #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.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(511, 221); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(101, 36); + this.buttonUpd.TabIndex = 16; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(511, 158); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(101, 36); + this.buttonDel.TabIndex = 15; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(511, 95); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(101, 36); + this.buttonEdit.TabIndex = 14; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(511, 37); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(101, 36); + this.buttonAdd.TabIndex = 13; + 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.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(466, 538); + this.dataGridView.TabIndex = 17; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(650, 538); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShops.cs b/Confectionery/ConfectioneryView/FormShops.cs new file mode 100644 index 0000000..77f6c7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryView +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopPastries"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + 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 ButtonEdit_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("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormShops.resx b/Confectionery/ConfectioneryView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From b00e00ba91b01a636cf45864ab980af9dee6951f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 19:45:16 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- .../BusinessLogics/ShopLogic.cs | 12 +- .../ConfectioneryView/FormMain.Designer.cs | 24 ++- Confectionery/ConfectioneryView/FormMain.cs | 18 +++ .../ConfectioneryView/FormSupply.Designer.cs | 150 ++++++++++++++++++ Confectionery/ConfectioneryView/FormSupply.cs | 124 +++++++++++++++ .../ConfectioneryView/FormSupply.resx | 60 +++++++ Confectionery/ConfectioneryView/Program.cs | 5 + 8 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormSupply.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormSupply.cs create mode 100644 Confectionery/ConfectioneryView/FormSupply.resx diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs index c192940..5cd6016 100644 --- a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,6 @@ namespace ConfectioneryContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count); + bool Supply(ShopSearchModel shopModel, IPastryModel pastry, int count); } } diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs index e46416e..47becbd 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -84,7 +84,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return true; } - public bool MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count) + public bool Supply(ShopSearchModel shopModel, IPastryModel Pastry, int count) { if (shopModel == null) { @@ -98,11 +98,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); } - _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + _logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); if (shop == null) { - _logger.LogWarning("MakeShipment(GetElement). Element not found"); + _logger.LogWarning("Supply(GetElement). Element not found"); return false; } if (shop.ShopPastries.ContainsKey(Pastry.Id)) @@ -110,13 +110,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics var shopIC = shop.ShopPastries[Pastry.Id]; shopIC.Item2 += count; shop.ShopPastries[Pastry.Id] = shopIC; - _logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } else { shop.ShopPastries.Add(Pastry.Id, (Pastry, count)); - _logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -128,7 +128,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics ShopPastries = shop.ShopPastries, }) == null) { - _logger.LogWarning("MakeShipment. Update operation failed"); + _logger.LogWarning("Supply. Update operation failed"); return false; } return true; diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index a1b389c..7356071 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -32,6 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.ButtonCreateOrder = new System.Windows.Forms.Button(); this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -46,7 +48,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1376, 28); @@ -57,7 +60,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -76,6 +80,20 @@ this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); + // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -172,5 +190,7 @@ private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index a2460ec..5aec936 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -68,6 +68,24 @@ namespace ConfectioneryView } } + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/Confectionery/ConfectioneryView/FormSupply.Designer.cs b/Confectionery/ConfectioneryView/FormSupply.Designer.cs new file mode 100644 index 0000000..040d631 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.Designer.cs @@ -0,0 +1,150 @@ +namespace ConfectioneryView +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.labelPastry = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(312, 170); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 19; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(205, 170); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 18; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(139, 128); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(287, 27); + this.textBoxCount.TabIndex = 17; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 132); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 16; + this.labelCount.Text = "Количество:"; + // + // comboBoxPastry + // + this.comboBoxPastry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(139, 80); + this.comboBoxPastry.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(287, 28); + this.comboBoxPastry.TabIndex = 15; + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(38, 85); + this.labelPastry.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(72, 20); + this.labelPastry.TabIndex = 14; + this.labelPastry.Text = "Выпечка:"; + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(139, 34); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(287, 28); + this.comboBoxShop.TabIndex = 13; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(38, 38); + this.labelShop.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(72, 20); + this.labelShop.TabIndex = 12; + this.labelShop.Text = "Магазин:"; + // + // FormSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 233); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelPastry); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormSupply"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxPastry; + private Label labelPastry; + private ComboBox comboBoxShop; + private Label labelShop; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs new file mode 100644 index 0000000..912a410 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -0,0 +1,124 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormSupply : Form + { + private readonly ILogger _logger; + + private readonly IPastryLogic _logicPastry; + + private readonly IShopLogic _logicShop; + public FormSupply(ILogger logger, IPastryLogic logicPastry, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPastry = logicPastry; + _logicShop = logicShop; + } + + private void FormSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicPastry.ReadList(null); + if (list != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = list; + comboBoxPastry.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var pastry = _logicPastry.ReadElement(new PastrySearchModel + { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }); + if (pastry == null) + { + throw new Exception("Мороженое не найдено."); + } + var operationResult = _logicShop.Supply(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + pastry, + 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, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormSupply.resx b/Confectionery/ConfectioneryView/FormSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index cebaeea..af295d5 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -36,10 +36,12 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +50,9 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 23ef6fc7a0d76a50021e6985343dd1810c08e948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 19:58:34 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=201=20=D1=85=D0=B0=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/ConfectioneryView/FormSupply.Designer.cs | 3 +++ Confectionery/ConfectioneryView/FormSupply.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormSupply.Designer.cs b/Confectionery/ConfectioneryView/FormSupply.Designer.cs index 040d631..e8c598d 100644 --- a/Confectionery/ConfectioneryView/FormSupply.Designer.cs +++ b/Confectionery/ConfectioneryView/FormSupply.Designer.cs @@ -47,6 +47,7 @@ this.buttonCancel.TabIndex = 19; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -57,6 +58,7 @@ this.buttonSave.TabIndex = 18; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // textBoxCount // @@ -131,6 +133,7 @@ this.Controls.Add(this.labelShop); this.Name = "FormSupply"; this.Text = "Пополнение магазина"; + this.Load += new System.EventHandler(this.FormSupply_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs index 912a410..ad01fbb 100644 --- a/Confectionery/ConfectioneryView/FormSupply.cs +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -30,7 +30,7 @@ namespace ConfectioneryView private void FormSupply_Load(object sender, EventArgs e) { - _logger.LogInformation("Ice creams loading"); + _logger.LogInformation("Pastries loading"); try { var list = _logicPastry.ReadList(null); @@ -44,7 +44,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ice creams loading error"); + _logger.LogError(ex, "Pastries loading error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } _logger.LogInformation("Shops loading"); -- 2.25.1 From 092c54fc1d18a62b483b0f159e4c95aad0167f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 1 Apr 2024 13:01:23 +0400 Subject: [PATCH 12/12] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D1=85=D0=B0=D1=80?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 8 +-- .../ConfectioneryView/FormMain.Designer.cs | 2 +- .../ConfectioneryView/FormShop.Designer.cs | 62 +++++++++---------- .../ConfectioneryView/FormShops.Designer.cs | 2 +- Confectionery/ConfectioneryView/FormSupply.cs | 4 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs index 47becbd..97b650b 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -96,7 +96,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (count <= 0) { - throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); + throw new ArgumentException("Количество товаров(выпечки) в магазине должно быть больше нуля", nameof(count)); } _logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); @@ -107,9 +107,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics } if (shop.ShopPastries.ContainsKey(Pastry.Id)) { - var shopIC = shop.ShopPastries[Pastry.Id]; - shopIC.Item2 += count; - shop.ShopPastries[Pastry.Id] = shopIC; + var shopP = shop.ShopPastries[Pastry.Id]; + shopP.Item2 += count; + shop.ShopPastries[Pastry.Id] = shopP; _logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 7356071..320c09a 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -77,7 +77,7 @@ // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Text = "Выпечка"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // магазиныToolStripMenuItem diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index dea22e8..b0a9b9a 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -36,11 +36,11 @@ this.labelName = new System.Windows.Forms.Label(); this.groupBoxPastries = new System.Windows.Forms.GroupBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); this.groupBoxPastries.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -51,9 +51,9 @@ this.labelOpeningDate.Location = new System.Drawing.Point(31, 102); this.labelOpeningDate.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelOpeningDate.Name = "labelOpeningDate"; - this.labelOpeningDate.Size = new System.Drawing.Size(117, 20); + this.labelOpeningDate.Size = new System.Drawing.Size(113, 20); this.labelOpeningDate.TabIndex = 12; - this.labelOpeningDate.Text = "Дата открытия :"; + this.labelOpeningDate.Text = "Дата открытия:"; // // dateTimePicker // @@ -77,9 +77,9 @@ this.labelAddress.Location = new System.Drawing.Point(31, 63); this.labelAddress.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(58, 20); + this.labelAddress.Size = new System.Drawing.Size(54, 20); this.labelAddress.TabIndex = 9; - this.labelAddress.Text = "Адрес :"; + this.labelAddress.Text = "Адрес:"; // // textBoxName // @@ -95,9 +95,9 @@ this.labelName.Location = new System.Drawing.Point(31, 23); this.labelName.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.Size = new System.Drawing.Size(80, 20); this.labelName.TabIndex = 7; - this.labelName.Text = "Название :"; + this.labelName.Text = "Название:"; // // groupBoxPastries // @@ -115,7 +115,7 @@ // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ColumnId, @@ -133,28 +133,6 @@ this.dataGridView.Size = new System.Drawing.Size(522, 356); this.dataGridView.TabIndex = 0; // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(449, 529); - this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(101, 36); - this.buttonCancel.TabIndex = 15; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(330, 529); - this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(101, 36); - this.buttonSave.TabIndex = 14; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // // ColumnId // this.ColumnId.HeaderText = "Id"; @@ -180,6 +158,28 @@ this.ColumnCount.ReadOnly = true; this.ColumnCount.Width = 125; // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(449, 529); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(330, 529); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); diff --git a/Confectionery/ConfectioneryView/FormShops.Designer.cs b/Confectionery/ConfectioneryView/FormShops.Designer.cs index 301e6bf..6e4e0bd 100644 --- a/Confectionery/ConfectioneryView/FormShops.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShops.Designer.cs @@ -84,7 +84,7 @@ // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; this.dataGridView.Location = new System.Drawing.Point(0, 0); diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs index ad01fbb..edba0c4 100644 --- a/Confectionery/ConfectioneryView/FormSupply.cs +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -75,7 +75,7 @@ namespace ConfectioneryView } if (comboBoxPastry.SelectedValue == null) { - MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxCount.Text)) @@ -90,7 +90,7 @@ namespace ConfectioneryView { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }); if (pastry == null) { - throw new Exception("Мороженое не найдено."); + throw new Exception("Выпечка не найдена."); } var operationResult = _logicShop.Supply(new ShopSearchModel { -- 2.25.1