From 7a8a3451f396fb626d2258509fdf9cb9d3a49457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Tue, 27 Feb 2024 21:03:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TypographyBusinessLogic/ShopLogic.cs | 171 ++++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 23 +++ .../BusinessLogicsContracts/IShopLogic.cs | 27 +++ .../SearchModels/ShopSearchModel.cs | 15 ++ .../StoragesContracts/IShopStorage.cs | 26 +++ .../ViewModels/ShopViewModel.cs | 30 +++ TypographyDataModels/IShopModel.cs | 19 ++ TypographyListImplement/DataListSingleton.cs | 2 + .../{ => Implements}/ComponentStorage.cs | 0 .../{ => Implements}/OrderStorage.cs | 0 .../{ => Implements}/PrintedStorage.cs | 0 .../Implements/ShopStorage.cs | 114 ++++++++++++ .../{ => Models}/Component.cs | 0 TypographyListImplement/{ => Models}/Order.cs | 0 .../{ => Models}/Printed.cs | 0 TypographyListImplement/Models/Shop.cs | 65 +++++++ TypographyView/FormMain.Designer.cs | 22 ++- TypographyView/FormMain.cs | 17 ++ TypographyView/FormMakeShipment.Designer.cs | 142 +++++++++++++++ TypographyView/FormMakeShipment.cs | 123 +++++++++++++ TypographyView/FormMakeShipment.resx | 120 ++++++++++++ TypographyView/FormShop.Designer.cs | 39 ++++ TypographyView/FormShop.cs | 132 ++++++++++++++ TypographyView/FormShop.resx | 120 ++++++++++++ TypographyView/FormShops.Designer.cs | 45 +++++ TypographyView/FormShops.cs | 20 ++ TypographyView/FormShops.resx | 120 ++++++++++++ TypographyView/Program.cs | 4 + 28 files changed, 1394 insertions(+), 2 deletions(-) create mode 100644 TypographyBusinessLogic/ShopLogic.cs create mode 100644 TypographyContracts/BindingModels/ShopBindingModel.cs create mode 100644 TypographyContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 TypographyContracts/SearchModels/ShopSearchModel.cs create mode 100644 TypographyContracts/StoragesContracts/IShopStorage.cs create mode 100644 TypographyContracts/ViewModels/ShopViewModel.cs create mode 100644 TypographyDataModels/IShopModel.cs rename TypographyListImplement/{ => Implements}/ComponentStorage.cs (100%) rename TypographyListImplement/{ => Implements}/OrderStorage.cs (100%) rename TypographyListImplement/{ => Implements}/PrintedStorage.cs (100%) create mode 100644 TypographyListImplement/Implements/ShopStorage.cs rename TypographyListImplement/{ => Models}/Component.cs (100%) rename TypographyListImplement/{ => Models}/Order.cs (100%) rename TypographyListImplement/{ => Models}/Printed.cs (100%) create mode 100644 TypographyListImplement/Models/Shop.cs create mode 100644 TypographyView/FormMakeShipment.Designer.cs create mode 100644 TypographyView/FormMakeShipment.cs create mode 100644 TypographyView/FormMakeShipment.resx create mode 100644 TypographyView/FormShop.Designer.cs create mode 100644 TypographyView/FormShop.cs create mode 100644 TypographyView/FormShop.resx create mode 100644 TypographyView/FormShops.Designer.cs create mode 100644 TypographyView/FormShops.cs create mode 100644 TypographyView/FormShops.resx diff --git a/TypographyBusinessLogic/ShopLogic.cs b/TypographyBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..a9eea1d --- /dev/null +++ b/TypographyBusinessLogic/ShopLogic.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace TypographyBusinessLogic +{ + 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, IPrintedModel iceCream, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (iceCream == null) + { + throw new ArgumentNullException(nameof(iceCream)); + } + 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.ShopPrinteds.ContainsKey(iceCream.Id)) + { + var shopIC = shop.ShopPrinteds[iceCream.Id]; + shopIC.Item2 += count; + shop.ShopPrinteds[iceCream.Id] = shopIC; + _logger.LogInformation("MakeShipment. Added {count} '{iceCream}' to '{ShopName}' shop", count, iceCream.PrintedName, + shop.ShopName); + } + else + { + shop.ShopPrinteds.Add(iceCream.Id, (iceCream, count)); + _logger.LogInformation("MakeShipment. Added {count} new '{iceCream}' to '{ShopName}' shop", count, iceCream.PrintedName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopPrinteds = shop.ShopPrinteds, + }) == 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/TypographyContracts/BindingModels/ShopBindingModel.cs b/TypographyContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..78ede24 --- /dev/null +++ b/TypographyContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; +using TypographyDataModels.Enums; + +namespace TypographyContracts.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 ShopPrinteds { get; set; } = new(); + } +} diff --git a/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs b/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..ee813e5 --- /dev/null +++ b/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyContracts.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, IPrintedModel iceCream, int count); + } +} diff --git a/TypographyContracts/SearchModels/ShopSearchModel.cs b/TypographyContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..8b9e425 --- /dev/null +++ b/TypographyContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/TypographyContracts/StoragesContracts/IShopStorage.cs b/TypographyContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..dd0970a --- /dev/null +++ b/TypographyContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.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/TypographyContracts/ViewModels/ShopViewModel.cs b/TypographyContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..819cb46 --- /dev/null +++ b/TypographyContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; +using System.ComponentModel; + +namespace TypographyContracts.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 ShopPrinteds + { + get; + set; + } = new(); + } +} diff --git a/TypographyDataModels/IShopModel.cs b/TypographyDataModels/IShopModel.cs new file mode 100644 index 0000000..2f84af5 --- /dev/null +++ b/TypographyDataModels/IShopModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopPrinteds { get; } + } +} diff --git a/TypographyListImplement/DataListSingleton.cs b/TypographyListImplement/DataListSingleton.cs index dd973c4..af24912 100644 --- a/TypographyListImplement/DataListSingleton.cs +++ b/TypographyListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace TypographyListImplement public List Components { get; set; } public List Orders { get; set; } public List Printeds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Printeds = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/TypographyListImplement/ComponentStorage.cs b/TypographyListImplement/Implements/ComponentStorage.cs similarity index 100% rename from TypographyListImplement/ComponentStorage.cs rename to TypographyListImplement/Implements/ComponentStorage.cs diff --git a/TypographyListImplement/OrderStorage.cs b/TypographyListImplement/Implements/OrderStorage.cs similarity index 100% rename from TypographyListImplement/OrderStorage.cs rename to TypographyListImplement/Implements/OrderStorage.cs diff --git a/TypographyListImplement/PrintedStorage.cs b/TypographyListImplement/Implements/PrintedStorage.cs similarity index 100% rename from TypographyListImplement/PrintedStorage.cs rename to TypographyListImplement/Implements/PrintedStorage.cs diff --git a/TypographyListImplement/Implements/ShopStorage.cs b/TypographyListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..4890152 --- /dev/null +++ b/TypographyListImplement/Implements/ShopStorage.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyListImplement.Models; + +namespace TypographyListImplement.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/TypographyListImplement/Component.cs b/TypographyListImplement/Models/Component.cs similarity index 100% rename from TypographyListImplement/Component.cs rename to TypographyListImplement/Models/Component.cs diff --git a/TypographyListImplement/Order.cs b/TypographyListImplement/Models/Order.cs similarity index 100% rename from TypographyListImplement/Order.cs rename to TypographyListImplement/Models/Order.cs diff --git a/TypographyListImplement/Printed.cs b/TypographyListImplement/Models/Printed.cs similarity index 100% rename from TypographyListImplement/Printed.cs rename to TypographyListImplement/Models/Printed.cs diff --git a/TypographyListImplement/Models/Shop.cs b/TypographyListImplement/Models/Shop.cs new file mode 100644 index 0000000..c815360 --- /dev/null +++ b/TypographyListImplement/Models/Shop.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyListImplement.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 ShopPrinteds + { + 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, + ShopPrinteds = model.ShopPrinteds + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopPrinteds = model.ShopPrinteds; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopPrinteds = ShopPrinteds + }; + } +} diff --git a/TypographyView/FormMain.Designer.cs b/TypographyView/FormMain.Designer.cs index dbc094d..065af82 100644 --- a/TypographyView/FormMain.Designer.cs +++ b/TypographyView/FormMain.Designer.cs @@ -32,6 +32,8 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); изделиеToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -45,7 +47,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1146, 28); @@ -54,7 +56,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, магазиныToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -73,6 +75,20 @@ изделиеToolStripMenuItem.Text = "Изделие"; изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазиныToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = SystemColors.ControlLightLight; @@ -170,5 +186,7 @@ private Button buttonUpd; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделиеToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/TypographyView/FormMain.cs b/TypographyView/FormMain.cs index f60a245..c9283d4 100644 --- a/TypographyView/FormMain.cs +++ b/TypographyView/FormMain.cs @@ -69,6 +69,23 @@ namespace TypographyView form.ShowDialog(); } } + 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(FormMakeShipment)); + if (service is FormMakeShipment form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { diff --git a/TypographyView/FormMakeShipment.Designer.cs b/TypographyView/FormMakeShipment.Designer.cs new file mode 100644 index 0000000..93a1b23 --- /dev/null +++ b/TypographyView/FormMakeShipment.Designer.cs @@ -0,0 +1,142 @@ +namespace PrintedBarView +{ + partial class FormMakeShipment + { + /// + /// 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() + { + labelShop = new Label(); + labelPrinted = new Label(); + label1 = new Label(); + comboBoxShop = new ComboBox(); + comboBoxPrinted = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelPrinted + // + labelPrinted.AutoSize = true; + labelPrinted.Location = new Point(12, 45); + labelPrinted.Name = "labelPrinted"; + labelPrinted.Size = new Size(65, 20); + labelPrinted.TabIndex = 1; + labelPrinted.Text = "Закуски:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 84); + label1.Name = "label1"; + label1.Size = new Size(93, 20); + label1.TabIndex = 2; + label1.Text = "Количество:"; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(111, 6); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(252, 28); + comboBoxShop.TabIndex = 3; + // + // comboBoxPrinted + // + comboBoxPrinted.FormattingEnabled = true; + comboBoxPrinted.Location = new Point(111, 45); + comboBoxPrinted.Name = "comboBoxPrinted"; + comboBoxPrinted.Size = new Size(252, 28); + comboBoxPrinted.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(111, 84); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(252, 27); + textBoxCount.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(111, 133); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(104, 37); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(221, 133); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(110, 37); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FromMakeShipment + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(386, 182); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPrinted); + Controls.Add(comboBoxShop); + Controls.Add(label1); + Controls.Add(labelPrinted); + Controls.Add(labelShop); + Name = "FromMakeShipment"; + Text = "Пополнение магазина"; + Load += FormMakeShipment_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelPrinted; + private Label label1; + private ComboBox comboBoxShop; + private ComboBox comboBoxPrinted; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TypographyView/FormMakeShipment.cs b/TypographyView/FormMakeShipment.cs new file mode 100644 index 0000000..c8ab22b --- /dev/null +++ b/TypographyView/FormMakeShipment.cs @@ -0,0 +1,123 @@ +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 TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormMakeShipment : Form + { + private readonly ILogger _logger; + + private readonly IPrintedLogic _logicPrinted; + + private readonly IShopLogic _logicShop; + public FormMakeShipment(ILogger logger, IPrintedLogic logicPrinted, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPrinted = logicPrinted; + _logicShop = logicShop; + } + private void FormMakeShipment_Load(object sender, EventArgs e) + { + _logger.LogInformation("Printeds loading"); + try + { + var list = _logicPrinted.ReadList(null); + if (list != null) + { + comboBoxPrinted.DisplayMember = "PrintedName"; + comboBoxPrinted.ValueMember = "Id"; + comboBoxPrinted.DataSource = list; + comboBoxPrinted.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Printeds 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 (comboBoxPrinted.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 iceCream = _logicPrinted.ReadElement(new PrintedSearchModel + { Id = Convert.ToInt32(comboBoxPrinted.SelectedValue) }); + if (iceCream == null) + { + throw new Exception("Закуска не найдено."); + } + var operationResult = _logicShop.MakeShipment(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + iceCream, + 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/TypographyView/FormMakeShipment.resx b/TypographyView/FormMakeShipment.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TypographyView/FormMakeShipment.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TypographyView/FormShop.Designer.cs b/TypographyView/FormShop.Designer.cs new file mode 100644 index 0000000..36e0088 --- /dev/null +++ b/TypographyView/FormShop.Designer.cs @@ -0,0 +1,39 @@ +namespace TypographyView +{ + 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.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormShop"; + } + + #endregion + } +} \ No newline at end of file diff --git a/TypographyView/FormShop.cs b/TypographyView/FormShop.cs new file mode 100644 index 0000000..b3f9680 --- /dev/null +++ b/TypographyView/FormShop.cs @@ -0,0 +1,132 @@ +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; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; + +namespace TypographyView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopPrinteds; + + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopPrinteds = 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; + _shopPrinteds = view.ShopPrinteds ?? 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 printeds loading"); + try + { + if (_shopPrinteds != null) + { + dataGridView.Rows.Clear(); + foreach (var printed in _shopPrinteds) + { + dataGridView.Rows.Add(new object[] { printed.Key, printed.Value.Item1.PrintedName, printed.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop printeds 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, + ShopPrinteds = _shopPrinteds + }; + 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/TypographyView/FormShop.resx b/TypographyView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TypographyView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TypographyView/FormShops.Designer.cs b/TypographyView/FormShops.Designer.cs new file mode 100644 index 0000000..9ccd9b7 --- /dev/null +++ b/TypographyView/FormShops.Designer.cs @@ -0,0 +1,45 @@ +namespace TypographyView +{ + 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() + { + SuspendLayout(); + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "FormShops"; + Text = "Магазины"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/TypographyView/FormShops.cs b/TypographyView/FormShops.cs new file mode 100644 index 0000000..c0389b2 --- /dev/null +++ b/TypographyView/FormShops.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 TypographyView +{ + public partial class FormShops : Form + { + public FormShops() + { + InitializeComponent(); + } + } +} diff --git a/TypographyView/FormShops.resx b/TypographyView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TypographyView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TypographyView/Program.cs b/TypographyView/Program.cs index c3b8cca..6079741 100644 --- a/TypographyView/Program.cs +++ b/TypographyView/Program.cs @@ -5,6 +5,7 @@ using TypographyListImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using TypographyBusinessLogic; namespace TypographyView { @@ -40,6 +41,8 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +51,7 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file