From 1b3b7f760497d4a41498e51a636ea0ff9a222092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D0=B1=D0=B5=D0=B5=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Sun, 19 May 2024 15:29:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=201=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 145 ++++++++ .../BindingModels/ShopBindingModel.cs | 18 + .../BusinessLogicsContracts/IShopLogic.cs | 23 ++ .../SearchModels/ShopSearchModel.cs | 14 + .../StoragesContracts/IShopStorage.cs | 22 ++ .../ViewModels/ShopViewModel.cs | 27 ++ .../Models/IShopModel.cs | 19 ++ .../DataListSingleton.cs | 6 +- .../Implements/ShopStorage.cs | 106 ++++++ .../Models/Shop.cs | 50 +++ .../FormMain.Designer.cs | 316 +++++++++--------- .../CarpentryWorkshopView/FormMain.cs | 306 +++++++++-------- .../CarpentryWorkshopView/FormMain.resx | 62 +++- .../FormShop.Designer.cs | 191 +++++++++++ .../CarpentryWorkshopView/FormShop.cs | 129 +++++++ .../CarpentryWorkshopView/FormShop.resx | 129 +++++++ .../FormShops.Designer.cs | 120 +++++++ .../CarpentryWorkshopView/FormShops.cs | 112 +++++++ .../CarpentryWorkshopView/FormShops.resx | 120 +++++++ .../FormWoodShop.Designer.cs | 147 ++++++++ .../CarpentryWorkshopView/FormWoodShop.cs | 127 +++++++ .../CarpentryWorkshopView/FormWoodShop.resx | 120 +++++++ .../CarpentryWorkshopView/Program.cs | 13 +- 23 files changed, 2020 insertions(+), 302 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ShopViewModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IShopModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShop.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormShops.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.resx diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..93101eb --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,145 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopBusinessLogic.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. Id:{Id}", 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. Id:{Id}", 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("Create 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); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool AddWood(ShopSearchModel model, IWoodModel wood, int count) + { + if (model == null) throw new ArgumentNullException(nameof(model)); + if (count <= 0) throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + + _logger.LogInformation("AddWood. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var shop = _shopStorage.GetElement(model); + + if (shop == null) return false; + + if (!shop.ShopWoods.ContainsKey(wood.Id)) + { + shop.ShopWoods[wood.Id] = (wood, count); + } + else + { + shop.ShopWoods[wood.Id] = (wood, shop.ShopWoods[wood.Id].Item2 + count); + } + + _shopStorage.Update(new ShopBindingModel() + { + ShopName = shop.ShopName, + ShopAddress = shop.ShopAddress, + DateOpen = shop.DateOpen, + ShopWoods = shop.ShopWoods + }); + 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.ShopAddress)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.ShopAddress)); + } + _logger.LogInformation("Wood. ShopName:{ShopName}. ShopAddress:{ShopAddress}. Id:{Id}", model.ShopName, model.ShopAddress, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..45972f8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string ShopAddress { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } = DateTime.Now; + public Dictionary ShopWoods { get; set; } = new(); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..5e58859 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,23 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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 AddWood(ShopSearchModel model, IWoodModel wood, int count); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..1f1a451 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string ShopName { get; set; } = string.Empty; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..5ca544f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,22 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ShopViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..00d52f8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,27 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string ShopAddress { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary ShopWoods { get; set; } = new(); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IShopModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..ae2ca4e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IShopModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string ShopAddress { get; } + + DateTime DateOpen { get; } + + Dictionary ShopWoods { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs index 0a14a86..e796496 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs @@ -13,12 +13,14 @@ namespace CarpentryWorkshopListImplement public List Components { get; set; } public List Orders { get; set; } public List Woods { get; set; } - private DataListSingleton() + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Woods = new List(); - } + Shops = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..b6e741d --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,106 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.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 ((model.ShopName == shop.ShopName) || (model.Id == shop.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/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs new file mode 100644 index 0000000..e0eda71 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs @@ -0,0 +1,50 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string ShopAddress { get; private set; } = string.Empty; + public DateTime DateOpen { get; private set; } = DateTime.Now; + public Dictionary ShopWoods { 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, + ShopAddress = model.ShopAddress, + DateOpen = model.DateOpen, + ShopWoods = model.ShopWoods + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) return; + ShopName = model.ShopName; + ShopAddress = model.ShopAddress; + DateOpen = model.DateOpen; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + ShopAddress = ShopAddress, + DateOpen = DateOpen, + ShopWoods = ShopWoods + }; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs index 7d8ce28..a23371e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -20,160 +20,170 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1389, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); - // - // изделияToolStripMenuItem - // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); - this.изделияToolStripMenuItem.Text = "Изделия"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 27); - this.dataGridView.MultiSelect = false; - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowHeadersVisible = false; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(1158, 423); - this.dataGridView.TabIndex = 1; - // - // ButtonCreateOrder - // - this.ButtonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonCreateOrder.Location = new System.Drawing.Point(1177, 44); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(199, 40); - this.ButtonCreateOrder.TabIndex = 2; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // ButtonTakeOrderInWork - // - this.ButtonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(1177, 121); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(199, 40); - this.ButtonTakeOrderInWork.TabIndex = 3; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // ButtonOrderReady - // - this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonOrderReady.Location = new System.Drawing.Point(1177, 206); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(199, 40); - this.ButtonOrderReady.TabIndex = 4; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // ButtonIssuedOrder - // - this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonIssuedOrder.Location = new System.Drawing.Point(1177, 292); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(199, 40); - this.ButtonIssuedOrder.TabIndex = 5; - this.ButtonIssuedOrder.Text = "Заказ выдан"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // ButtonRef - // - this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonRef.Location = new System.Drawing.Point(1177, 379); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(199, 40); - this.ButtonRef.TabIndex = 6; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1389, 450); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "Столярная мастерская"; - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ButtonCreateOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + ButtonOrderReady = new Button(); + ButtonIssuedOrder = new Button(); + ButtonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1389, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(180, 22); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(180, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(143, 20); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 27); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(1158, 423); + dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonCreateOrder.Location = new Point(1177, 44); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(199, 40); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; + // + // ButtonTakeOrderInWork + // + ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonTakeOrderInWork.Location = new Point(1177, 121); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(199, 40); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // ButtonOrderReady + // + ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonOrderReady.Location = new Point(1177, 206); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(199, 40); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonIssuedOrder.Location = new Point(1177, 292); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(199, 40); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // ButtonRef + // + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(1177, 379); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(199, 40); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1389, 450); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Столярная мастерская"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - } + #endregion - #endregion - - private MenuStrip menuStrip1; + private MenuStrip menuStrip1; private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; @@ -183,5 +193,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/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs index 71ddb64..ce06799 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -14,162 +14,180 @@ using System.Windows.Forms; namespace CarpentryWorkshopView { - public partial class FormMain : Form - { - private readonly ILogger _logger; + public partial class FormMain : Form + { + private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); + try + { + var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["WoodId"].Visible = false; - } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["WoodId"].Visible = false; + } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } - private void изделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormWoods)); + private void изделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWoods)); - if (service is FormWoods form) - { - form.ShowDialog(); - } - } + if (service is FormWoods form) + { + form.ShowDialog(); + } + } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + 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(FormWoodShop)); + if (service is FormWoodShop form) + { + form.ShowDialog(); + } + } + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx index 938108a..a0623c8 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShop.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.Designer.cs new file mode 100644 index 0000000..cbab6b0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.Designer.cs @@ -0,0 +1,191 @@ +namespace CarpentryWorkshopView +{ + 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() + { + textBoxShopName = new TextBox(); + labelShopName = new Label(); + labelShopAddress = new Label(); + textBoxShopAddress = new TextBox(); + labelOpenShop = new Label(); + dateTimePickerOpenShop = new DateTimePicker(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxShopName + // + textBoxShopName.Location = new Point(187, 27); + textBoxShopName.Name = "textBoxShopName"; + textBoxShopName.Size = new Size(251, 23); + textBoxShopName.TabIndex = 0; + // + // labelShopName + // + labelShopName.AutoSize = true; + labelShopName.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelShopName.Location = new Point(12, 27); + labelShopName.Name = "labelShopName"; + labelShopName.Size = new Size(169, 23); + labelShopName.TabIndex = 1; + labelShopName.Text = "Название магазина:"; + // + // labelShopAddress + // + labelShopAddress.AutoSize = true; + labelShopAddress.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelShopAddress.Location = new Point(12, 67); + labelShopAddress.Name = "labelShopAddress"; + labelShopAddress.Size = new Size(140, 23); + labelShopAddress.TabIndex = 2; + labelShopAddress.Text = "Адрес магазина:"; + // + // textBoxShopAddress + // + textBoxShopAddress.Location = new Point(187, 67); + textBoxShopAddress.Name = "textBoxShopAddress"; + textBoxShopAddress.Size = new Size(251, 23); + textBoxShopAddress.TabIndex = 3; + // + // labelOpenShop + // + labelOpenShop.AutoSize = true; + labelOpenShop.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelOpenShop.Location = new Point(12, 105); + labelOpenShop.Name = "labelOpenShop"; + labelOpenShop.Size = new Size(129, 23); + labelOpenShop.TabIndex = 4; + labelOpenShop.Text = "Дата открытия:"; + // + // dateTimePickerOpenShop + // + dateTimePickerOpenShop.Location = new Point(187, 105); + dateTimePickerOpenShop.Name = "dateTimePickerOpenShop"; + dateTimePickerOpenShop.Size = new Size(251, 23); + dateTimePickerOpenShop.TabIndex = 5; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = SystemColors.ControlLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(0, 148); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(800, 304); + dataGridView.TabIndex = 6; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.HeaderText = "Изделие"; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // buttonSave + // + buttonSave.Location = new Point(591, 22); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(146, 37); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(591, 91); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(146, 37); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePickerOpenShop); + Controls.Add(labelOpenShop); + Controls.Add(textBoxShopAddress); + Controls.Add(labelShopAddress); + Controls.Add(labelShopName); + Controls.Add(textBoxShopName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxShopName; + private Label labelShopName; + private Label labelShopAddress; + private TextBox textBoxShopAddress; + private Label labelOpenShop; + private DateTimePicker dateTimePickerOpenShop; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs new file mode 100644 index 0000000..89f9c65 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs @@ -0,0 +1,129 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopDataModels.Models; +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 CarpentryWorkshopView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopWoods; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopWoods = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxShopName.Text = view.ShopName; + textBoxShopAddress.Text = view.ShopAddress; + dateTimePickerOpenShop.Value = view.DateOpen; + _shopWoods = view.ShopWoods ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка ремонтов магазина"); + try + { + if (_shopWoods != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _shopWoods) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.WoodName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ремонтов магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShopName.Text)) + { + MessageBox.Show("Заполните название магазина", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxShopAddress.Text)) + { + MessageBox.Show("Заполните адрес магазина", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxShopName.Text, + ShopAddress = textBoxShopAddress.Text, + DateOpen = dateTimePickerOpenShop.Value.Date, + ShopWoods = _shopWoods + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах"); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx new file mode 100644 index 0000000..fcacbcb --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs new file mode 100644 index 0000000..5ef68a4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace CarpentryWorkshopView +{ + 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 1); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(598, 449); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(648, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(134, 54); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(648, 117); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(134, 54); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(648, 205); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(134, 54); + buttonUpd.TabIndex = 3; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonRef + // + buttonRef.Location = new Point(648, 294); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(134, 54); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(824, 450); + Controls.Add(buttonRef); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonDel; + private Button buttonUpd; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs new file mode 100644 index 0000000..8ee0e20 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs @@ -0,0 +1,112 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +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 CarpentryWorkshopView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logic = logic; + _logger = logger; + } + + 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["ShopWoods"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ремонта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShops.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/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/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.Designer.cs new file mode 100644 index 0000000..a6e5489 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.Designer.cs @@ -0,0 +1,147 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoodShop + { + /// + /// 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() + { + comboBoxShopName = new ComboBox(); + comboBoxWoodName = new ComboBox(); + textBoxCount = new TextBox(); + labelShopName = new Label(); + labelWoodName = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxShopName + // + comboBoxShopName.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShopName.FormattingEnabled = true; + comboBoxShopName.Location = new Point(132, 27); + comboBoxShopName.Name = "comboBoxShopName"; + comboBoxShopName.Size = new Size(313, 23); + comboBoxShopName.TabIndex = 0; + // + // comboBoxWoodName + // + comboBoxWoodName.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWoodName.FormattingEnabled = true; + comboBoxWoodName.Location = new Point(132, 69); + comboBoxWoodName.Name = "comboBoxWoodName"; + comboBoxWoodName.Size = new Size(313, 23); + comboBoxWoodName.TabIndex = 1; + // + // textBoxCount + // + textBoxCount.Location = new Point(132, 108); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(313, 23); + textBoxCount.TabIndex = 2; + // + // labelShopName + // + labelShopName.AutoSize = true; + labelShopName.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelShopName.Location = new Point(20, 27); + labelShopName.Name = "labelShopName"; + labelShopName.Size = new Size(82, 23); + labelShopName.TabIndex = 3; + labelShopName.Text = "Магазин:"; + // + // labelWoodName + // + labelWoodName.AutoSize = true; + labelWoodName.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelWoodName.Location = new Point(20, 69); + labelWoodName.Name = "labelWoodName"; + labelWoodName.Size = new Size(81, 23); + labelWoodName.TabIndex = 4; + labelWoodName.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Font = new Font("Segoe UI", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + labelCount.Location = new Point(20, 108); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(106, 23); + labelCount.TabIndex = 5; + labelCount.Text = "Количество:"; + // + // buttonSave + // + buttonSave.Location = new Point(98, 165); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(134, 51); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(263, 165); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(134, 51); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormWoodShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(523, 259); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelWoodName); + Controls.Add(labelShopName); + Controls.Add(textBoxCount); + Controls.Add(comboBoxWoodName); + Controls.Add(comboBoxShopName); + Name = "FormWoodShop"; + Text = "Магазин изделия"; + Load += FormWoodShop_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShopName; + private ComboBox comboBoxWoodName; + private TextBox textBoxCount; + private Label labelShopName; + private Label labelWoodName; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.cs new file mode 100644 index 0000000..1a3c8d0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.cs @@ -0,0 +1,127 @@ +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormWoodShop : Form + { + private readonly ILogger _logger; + + private readonly IWoodLogic _logicW; + + private readonly IShopLogic _logicS; + + public FormWoodShop(ILogger logger, IWoodLogic logicW, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicW = logicW; + _logicS = logicS; + } + + private void FormWoodShop_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка магазинов"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxShopName.DisplayMember = "ShopName"; + comboBoxShopName.ValueMember = "Id"; + comboBoxShopName.DataSource = list; + comboBoxShopName.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка изделий"); + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWoodName.DisplayMember = "WoodName"; + comboBoxWoodName.ValueMember = "Id"; + comboBoxWoodName.DataSource = list; + comboBoxWoodName.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(comboBoxShopName.Text)) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(comboBoxWoodName.Text)) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Пополнение магазина"); + + try + { + var operationResult = _logicS.AddWood(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShopName.SelectedValue) + }, + + _logicW.ReadElement(new WoodSearchModel() + { + Id = Convert.ToInt32(comboBoxWoodName.SelectedValue) + })!, + + Convert.ToInt32(textBoxCount.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка пополнения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodShop.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/CarpentryWorkshop/CarpentryWorkshopView/Program.cs b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs index 435a020..cd68ec4 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs @@ -37,16 +37,23 @@ namespace CarpentryWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file -- 2.25.1