From fb0b7ccd1de5257a977945e2d9ebcd3d840d4cf8 Mon Sep 17 00:00:00 2001 From: leoevgeniy <98206383+leoevgeniy@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:38:22 +0400 Subject: [PATCH 1/2] need to work --- .../BusinessLogics/ShopLogic.cs | 155 +++++++++++++ .../BindingModels/ShopBindingModel.cs | 13 ++ .../BindingModels/SupplyBindingModel .cs | 11 + .../BusinessLogicsContracts/IShopLogic.cs | 17 ++ .../SearchModels/ShopSearchModel.cs | 8 + .../StoragesContracts/IShopStorage.cs | 22 ++ .../ViewModels/ShopViewModel.cs | 17 ++ .../Models/IShopModel.cs | 10 + .../Models/ISupplyModel.cs | 9 + .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 104 +++++++++ .../Models/Shop.cs | 53 +++++ .../FormMain.Designer.cs | 210 ++++++++++-------- .../CarpentryWorkshopView/FormMain.cs | 18 ++ .../CarpentryWorkshopView/FormMain.resx | 62 +++++- .../FormShop.Designer.cs | 187 ++++++++++++++++ .../CarpentryWorkshopView/FormShop.cs | 114 ++++++++++ .../CarpentryWorkshopView/FormShop.resx | 120 ++++++++++ .../FormShops.Designer.cs | 117 ++++++++++ .../CarpentryWorkshopView/FormShops.cs | 107 +++++++++ .../CarpentryWorkshopView/FormShops.resx | 120 ++++++++++ .../FormSupply.Designer.cs | 109 +++++++++ .../CarpentryWorkshopView/FormSupply.cs | 153 +++++++++++++ .../CarpentryWorkshopView/FormSupply.resx | 120 ++++++++++ .../CarpentryWorkshopView/Program.cs | 8 + 25 files changed, 1767 insertions(+), 99 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/SupplyBindingModel .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/CarpentryWorkshopDataModels/Models/ISupplyModel.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/FormSupply.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormSupply.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormSupply.resx diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..dbd73e0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,155 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IWoodStorage _woodStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, IWoodStorage woodStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _woodStorage = woodStorage; + } + + 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 bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopWoods.ContainsKey(model.WoodId)) + { + var oldValue = shop.ShopWoods[model.WoodId]; + oldValue.Item2 += model.Count; + shop.ShopWoods[model.WoodId] = oldValue; + } + else + { + var wood = _woodStorage.GetElement(new WoodSearchModel + { + Id = model.WoodId + }); + if (wood == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.WoodId} не найденн"); + } + shop.ShopWoods.Add(model.WoodId, (wood, model.Count)); + } + return true; + } + + 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; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Address)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Address, model.DateOpen, 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..feed4c9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,13 @@ +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Address { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopWoods { get; set; } = new(); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/SupplyBindingModel .cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/SupplyBindingModel .cs new file mode 100644 index 0000000..d824da7 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/SupplyBindingModel .cs @@ -0,0 +1,11 @@ +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int WoodId { get; set; } + public int Count { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..5840f0f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; + +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 MakeSupply(SupplyBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..71d0ee2 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace CarpentryWorkshopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..465cef8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,22 @@ +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.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..d469d57 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,17 @@ +using CarpentryWorkshopDataModels.Models; +using System.ComponentModel; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } + [DisplayName("Адрес магазина")] + public string Address { get; set; } + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } + 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..19e6d4c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IShopModel.cs @@ -0,0 +1,10 @@ +namespace CarpentryWorkshopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopWoods { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/ISupplyModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..8d0e414 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/ISupplyModel.cs @@ -0,0 +1,9 @@ +namespace CarpentryWorkshopDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int WoodId { get; } + int Count { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs index 9813b2a..1d3857e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace CarpentryWorkshopListImplement public List Components { get; set; } public List Orders { get; set; } public List Woods { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Woods = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..fc8c47b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,104 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopListImplement.Models; + +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 ((!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/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs new file mode 100644 index 0000000..1b9426b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Shop.cs @@ -0,0 +1,53 @@ +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; } + public string Address { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopWoods { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopWoods = ShopWoods + }; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs index efe7222..94eddf1 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -28,137 +28,149 @@ /// 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 = new MenuStrip(); + справочники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(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + 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(896, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(896, 24); + menuStrip1.TabIndex = 0; + 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.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочники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.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += Компоненты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); + ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + ИзделияToolStripMenuItem.Size = new Size(180, 22); + ИзделияToolStripMenuItem.Text = "Изделия"; + ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // // dataGridView // - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.EnableHeadersVisualStyles = false; - this.dataGridView.Location = new System.Drawing.Point(1, 32); - this.dataGridView.MultiSelect = false; - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(755, 243); - this.dataGridView.TabIndex = 1; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.EnableHeadersVisualStyles = false; + dataGridView.Location = new Point(1, 32); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(755, 243); + dataGridView.TabIndex = 1; // // ButtonCreateOrder // - this.ButtonCreateOrder.Location = new System.Drawing.Point(762, 44); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(122, 23); - this.ButtonCreateOrder.TabIndex = 2; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + ButtonCreateOrder.Location = new Point(762, 44); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(122, 23); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; // // ButtonTakeOrderInWork // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(762, 73); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(122, 42); - this.ButtonTakeOrderInWork.TabIndex = 3; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + ButtonTakeOrderInWork.Location = new Point(762, 73); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(122, 42); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // ButtonOrderReady // - this.ButtonOrderReady.Location = new System.Drawing.Point(762, 121); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(122, 23); - this.ButtonOrderReady.TabIndex = 4; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + ButtonOrderReady.Location = new Point(762, 121); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(122, 23); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; // // ButtonIssuedOrder // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(762, 150); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(122, 23); - this.ButtonIssuedOrder.TabIndex = 5; - this.ButtonIssuedOrder.Text = "Заказ выдан"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + ButtonIssuedOrder.Location = new Point(762, 150); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(122, 23); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; // // ButtonRef // - this.ButtonRef.Location = new System.Drawing.Point(762, 179); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(122, 23); - this.ButtonRef.TabIndex = 6; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + ButtonRef.Location = new Point(762, 179); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(122, 23); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_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.DoubleClick += поставкиToolStripMenuItem_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(896, 280); - 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.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(896, 280); + 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 = "Сборка Набора"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -172,5 +184,7 @@ private System.Windows.Forms.Button ButtonRef; private System.Windows.Forms.ToolStripMenuItem КомпонентыToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ИзделияToolStripMenuItem; + 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 89a244e..211ce67 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -1,6 +1,7 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using CarpentryWorkshopDataModels.Enums; using System; using System.Collections.Generic; using System.ComponentModel; @@ -144,5 +145,22 @@ namespace CarpentryWorkshopView { 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(FormSupply)); + if (service is FormSupply 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..05f98fc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.Designer.cs @@ -0,0 +1,187 @@ +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() + { + DateTimePicker = new DateTimePicker(); + NameTextBox = new TextBox(); + AddressTextBox = new TextBox(); + NameLabel = new Label(); + AdressLabel = new Label(); + DateLabel = new Label(); + SaveButton = new Button(); + CancelButton = new Button(); + DataGridView = new DataGridView(); + Column1 = new DataGridViewTextBoxColumn(); + Название = new DataGridViewTextBoxColumn(); + Цена = new DataGridViewTextBoxColumn(); + Количество = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DateTimePicker + // + DateTimePicker.Location = new Point(85, 70); + DateTimePicker.Name = "DateTimePicker"; + DateTimePicker.Size = new Size(318, 23); + DateTimePicker.TabIndex = 0; + // + // NameTextBox + // + NameTextBox.Location = new Point(85, 12); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(318, 23); + NameTextBox.TabIndex = 1; + // + // AddressTextBox + // + AddressTextBox.Location = new Point(85, 41); + AddressTextBox.Name = "AddressTextBox"; + AddressTextBox.Size = new Size(318, 23); + AddressTextBox.TabIndex = 2; + // + // NameLabel + // + NameLabel.AutoSize = true; + NameLabel.Location = new Point(12, 15); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(59, 15); + NameLabel.TabIndex = 3; + NameLabel.Text = "Название"; + // + // AdressLabel + // + AdressLabel.AutoSize = true; + AdressLabel.Location = new Point(12, 44); + AdressLabel.Name = "AdressLabel"; + AdressLabel.Size = new Size(40, 15); + AdressLabel.TabIndex = 4; + AdressLabel.Text = "Адрес"; + // + // DateLabel + // + DateLabel.AutoSize = true; + DateLabel.Location = new Point(12, 76); + DateLabel.Name = "DateLabel"; + DateLabel.Size = new Size(32, 15); + DateLabel.TabIndex = 5; + DateLabel.Text = "Дата"; + // + // SaveButton + // + SaveButton.Location = new Point(247, 255); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(75, 23); + SaveButton.TabIndex = 6; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(328, 255); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(75, 23); + CancelButton.TabIndex = 7; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Название, Цена, Количество }); + DataGridView.Location = new Point(12, 99); + DataGridView.Name = "DataGridView"; + DataGridView.Size = new Size(391, 150); + DataGridView.TabIndex = 8; + // + // Column1 + // + Column1.HeaderText = "Column1"; + Column1.Name = "Column1"; + Column1.Visible = false; + // + // Название + // + Название.HeaderText = "Название"; + Название.Name = "Название"; + Название.ReadOnly = true; + Название.Width = 150; + // + // Цена + // + Цена.HeaderText = "Цена"; + Цена.Name = "Цена"; + Цена.ReadOnly = true; + // + // Количество + // + Количество.HeaderText = "Количество"; + Количество.Name = "Количество"; + Количество.ReadOnly = true; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(411, 285); + Controls.Add(DataGridView); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(DateLabel); + Controls.Add(AdressLabel); + Controls.Add(NameLabel); + Controls.Add(AddressTextBox); + Controls.Add(NameTextBox); + Controls.Add(DateTimePicker); + Name = "FormShop"; + Text = "Редактор магазина"; + Load += ShopForm_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker DateTimePicker; + private TextBox NameTextBox; + private TextBox AddressTextBox; + private Label NameLabel; + private Label AdressLabel; + private Label DateLabel; + private Button SaveButton; + private Button CancelButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Название; + private DataGridViewTextBoxColumn Цена; + private DataGridViewTextBoxColumn Количество; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs new file mode 100644 index 0000000..0076e41 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.cs @@ -0,0 +1,114 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _woods; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ShopForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + NameTextBox.Text = shop.ShopName; + AddressTextBox.Text = shop.Address; + DateTimePicker.Text = shop.DateOpen.ToString(); + _woods = shop.ShopWoods; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_woods != null) + { + foreach (var wood in _woods) + { + DataGridView.Rows.Add(new object[] { wood.Key, wood.Value.Item1.WoodName, wood.Value.Item1.Price, wood.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(AddressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = NameTextBox.Text, + Address = AddressTextBox.Text, + DateOpen = DateTimePicker.Value.Date, + ShopWoods = _woods + }; + 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); + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/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/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs new file mode 100644 index 0000000..95737d2 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.Designer.cs @@ -0,0 +1,117 @@ +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(); + AddButton = new Button(); + UpdateButton = new Button(); + RefreshButton = new Button(); + DeleteButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.Size = new Size(393, 374); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(411, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(114, 23); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(411, 41); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(114, 23); + UpdateButton.TabIndex = 2; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(411, 70); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(114, 23); + RefreshButton.TabIndex = 3; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(411, 99); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(114, 23); + DeleteButton.TabIndex = 4; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(539, 403); + Controls.Add(DeleteButton); + Controls.Add(RefreshButton); + Controls.Add(UpdateButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += ShopsForm_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button UpdateButton; + private Button RefreshButton; + private Button DeleteButton; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + private DataGridViewTextBoxColumn Column4; + private DataGridViewTextBoxColumn Column5; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs new file mode 100644 index 0000000..d0def38 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormShops.cs @@ -0,0 +1,107 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["ShopWoods"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ShopsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void AddButton_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 UpdateButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void DeleteButton_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); + } + } + } + } + } +} 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/FormSupply.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs new file mode 100644 index 0000000..5f858ea --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs @@ -0,0 +1,109 @@ +namespace CarpentryWorkshopView +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ShopComboBox = new ComboBox(); + WoodComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(331, 23); + ShopComboBox.TabIndex = 0; + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + // + // WoodComboBox + // + WoodComboBox.FormattingEnabled = true; + WoodComboBox.Location = new Point(12, 41); + WoodComboBox.Name = "WoodComboBox"; + WoodComboBox.Size = new Size(331, 23); + WoodComboBox.TabIndex = 1; + WoodComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + WoodComboBox.FormattingEnabled = true; + // + // CountTextBox + // + CountTextBox.Location = new Point(12, 70); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(331, 23); + CountTextBox.TabIndex = 2; + // + // SaveButton + // + SaveButton.Location = new Point(187, 99); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(75, 23); + SaveButton.TabIndex = 3; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(268, 99); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(75, 23); + CancelButton.TabIndex = 4; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(355, 136); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(CountTextBox); + Controls.Add(WoodComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + Text = "SupplyForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox WoodComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.cs new file mode 100644 index 0000000..ba71e4b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.cs @@ -0,0 +1,153 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +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 FormSupply : Form + { + private readonly List? _woodList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IWoodLogic _woodLogic; + public int ShopId + { + get + { + return + Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int WoodId + { + get + { + return + Convert.ToInt32(WoodComboBox.SelectedValue); + } + set + { + WoodComboBox.SelectedValue = value; + } + } + + public IWoodModel? WoodModel + { + get + { + if (_woodList == null) + { + return null; + } + foreach (var elem in _woodList) + { + if (elem.Id == WoodId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IWoodLogic woodLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _woodLogic = woodLogic; + _woodList = woodLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_woodList != null) + { + WoodComboBox.DisplayMember = "WoodName"; + WoodComboBox.ValueMember = "Id"; + WoodComboBox.DataSource = _woodList; + WoodComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (WoodComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(CountTextBox.Text); + + bool res = _shopLogic.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(ShopComboBox.SelectedValue), + WoodId = Convert.ToInt32(WoodComboBox.SelectedValue), + Count = Convert.ToInt32(CountTextBox.Text) + }); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.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 efb4377..1b79a94 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs @@ -5,6 +5,7 @@ using CarpentryWorkshopListImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using CarpentryWorkshopView; namespace CarpentryWorkshopView { @@ -36,9 +37,13 @@ namespace CarpentryWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -46,6 +51,9 @@ namespace CarpentryWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From 42fc0bd9025c4a9233826dcf23cea4fdfcd290eb Mon Sep 17 00:00:00 2001 From: leoevgeniy <98206383+leoevgeniy@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:02:23 +0400 Subject: [PATCH 2/2] thats works --- .../FormMain.Designer.cs | 32 +++++++++---------- .../FormSupply.Designer.cs | 8 ++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs index 94eddf1..ebc4608 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -32,14 +32,14 @@ справочники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(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); - поставкиToolStripMenuItem = new ToolStripMenuItem(); + поставкаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -55,7 +55,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, магазиныToolStripMenuItem, поставкаToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; @@ -74,6 +74,13 @@ ИзделияToolStripMenuItem.Text = "Изделия"; ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(180, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = SystemColors.ButtonHighlight; @@ -136,19 +143,12 @@ ButtonRef.UseVisualStyleBackColor = true; ButtonRef.Click += ButtonRef_Click; // - // магазиныToolStripMenuItem + // поставка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.DoubleClick += поставкиToolStripMenuItem_Click; + поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem"; + поставкаToolStripMenuItem.Size = new Size(180, 22); + поставкаToolStripMenuItem.Text = "Поставка"; + поставкаToolStripMenuItem.Click += поставкиToolStripMenuItem_Click; // // FormMain // @@ -185,6 +185,6 @@ private System.Windows.Forms.ToolStripMenuItem КомпонентыToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ИзделияToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; - private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem поставкаToolStripMenuItem; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs index 5f858ea..491fd83 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormSupply.Designer.cs @@ -37,23 +37,21 @@ // // ShopComboBox // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; ShopComboBox.FormattingEnabled = true; ShopComboBox.Location = new Point(12, 12); ShopComboBox.Name = "ShopComboBox"; ShopComboBox.Size = new Size(331, 23); ShopComboBox.TabIndex = 0; - ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ShopComboBox.FormattingEnabled = true; // // WoodComboBox // + WoodComboBox.DropDownStyle = ComboBoxStyle.DropDownList; WoodComboBox.FormattingEnabled = true; WoodComboBox.Location = new Point(12, 41); WoodComboBox.Name = "WoodComboBox"; WoodComboBox.Size = new Size(331, 23); WoodComboBox.TabIndex = 1; - WoodComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - WoodComboBox.FormattingEnabled = true; // // CountTextBox // @@ -93,7 +91,7 @@ Controls.Add(WoodComboBox); Controls.Add(ShopComboBox); Name = "FormSupply"; - Text = "SupplyForm"; + Text = "Поставки"; ResumeLayout(false); PerformLayout(); }