diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..9685675 --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,162 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.BusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + if (count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddPlaneInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddPlaneInShop element not found"); + return false; + } + _logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id); + + if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) + { + element.ShopDocuments[document.Id] = (document, count + pair.Item2); + _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + } + else + { + element.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + } + + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + OpeningDate = element.OpeningDate, + ShopDocuments = element.ShopDocuments + }); + 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)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..b3fb02d --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary ShopDocuments + { + get; + set; + } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..da2f762 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.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 SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..ad93303 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,15 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..61e307f --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.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/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..e4de58c --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,29 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopDocuments + { + get; + set; + } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..cdca195 --- /dev/null +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataModels.Models +{ + public interface IShopModel : IId + { + String ShopName { get; } + String Address { get; } + DateTime OpeningDate { get; } + Dictionary ShopDocuments { get; } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs index ca1efab..5da0aec 100644 --- a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs +++ b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AbstractLawFirmListImplement public List Components { get; set; } public List Orders { get; set; } public List Documents { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Documents = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..aa88ff1 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs @@ -0,0 +1,118 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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 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 List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + 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/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs new file mode 100644 index 0000000..144fea1 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs @@ -0,0 +1,60 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopDocuments + { + get; + private set; + } = new Dictionary(); + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + ShopDocuments = model.ShopDocuments + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + ShopDocuments = model.ShopDocuments; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopDocuments = ShopDocuments + }; + } +} diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 134665b..0391af9 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -176,5 +176,22 @@ namespace LawFirmView DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }; } + private void buttonSupplyShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirmView/FormMain.designer.cs b/LawFirm/LawFirmView/FormMain.designer.cs index 6d9d80f..129e0d5 100644 --- a/LawFirm/LawFirmView/FormMain.designer.cs +++ b/LawFirm/LawFirmView/FormMain.designer.cs @@ -28,134 +28,148 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.toolStripMenuItemCatalogs = 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(); + toolStripMenuItemCatalogs = 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(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // menuStrip1 // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItemCatalogs}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(910, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "Справочники"; + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(7, 3, 0, 3); + menuStrip1.Size = new Size(1040, 30); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "Справочники"; // // toolStripMenuItemCatalogs // - this.toolStripMenuItemCatalogs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.компонентыToolStripMenuItem, - this.пакетыДокументовToolStripMenuItem}); - this.toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; - this.toolStripMenuItemCatalogs.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItemCatalogs.Text = "Справочники"; + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, пакетыДокументовToolStripMenuItem, магазиныToolStripMenuItem }); + toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + toolStripMenuItemCatalogs.Size = new Size(117, 24); + toolStripMenuItemCatalogs.Text = "Справочники"; // // компонентыToolStripMenuItem // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(229, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // пакетыДокументовToolStripMenuItem // - this.пакетыДокументовToolStripMenuItem.Name = "пакетыДокументовToolStripMenuItem"; - this.пакетыДокументовToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; - this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click); + пакетыДокументовToolStripMenuItem.Name = "пакетыДокументовToolStripMenuItem"; + пакетыДокументовToolStripMenuItem.Size = new Size(229, 26); + пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; + пакетыДокументовToolStripMenuItem.Click += пакетыДокументовToolStripMenuItem_Click; // // dataGridView // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(736, 411); - this.dataGridView.TabIndex = 1; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 36); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(841, 548); + dataGridView.TabIndex = 1; // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(742, 39); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(156, 26); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); + buttonCreateOrder.Location = new Point(848, 52); + buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(178, 35); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; // // buttonTakeOrderInWork // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(742, 71); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(156, 23); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.buttonTakeOrderInWork_Click); + buttonTakeOrderInWork.Location = new Point(848, 95); + buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(178, 31); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; // // buttonOrderReady // - this.buttonOrderReady.Location = new System.Drawing.Point(742, 100); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(156, 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(848, 133); + buttonOrderReady.Margin = new Padding(3, 4, 3, 4); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(178, 31); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(742, 129); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(156, 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(848, 172); + buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(178, 31); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(742, 158); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(156, 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(848, 211); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(178, 31); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(229, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(910, 477); - 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 = "FormMain"; - 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(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1040, 636); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -170,5 +184,6 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.resx b/LawFirm/LawFirmView/FormMain.resx index 05252e7..a39c409 100644 --- a/LawFirm/LawFirmView/FormMain.resx +++ b/LawFirm/LawFirmView/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/LawFirm/LawFirmView/FormShop.Designer.cs b/LawFirm/LawFirmView/FormShop.Designer.cs new file mode 100644 index 0000000..9dc7170 --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -0,0 +1,189 @@ +namespace LawFirmView +{ + 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() + { + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + dataGridView = new DataGridView(); + Column1 = new DataGridViewTextBoxColumn(); + Column2 = new DataGridViewTextBoxColumn(); + Column3 = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(149, 20); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(228, 27); + textBoxName.TabIndex = 0; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(149, 56); + textBoxAddress.Margin = new Padding(3, 4, 3, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(228, 27); + textBoxAddress.TabIndex = 1; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(149, 94); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(228, 27); + dateTimePicker.TabIndex = 2; + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3 }); + dataGridView.Location = new Point(14, 132); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(613, 327); + dataGridView.TabIndex = 3; + // + // Column1 + // + Column1.HeaderText = "id"; + Column1.MinimumWidth = 6; + Column1.Name = "Column1"; + Column1.Visible = false; + // + // Column2 + // + Column2.HeaderText = "Название пакета документов"; + Column2.MinimumWidth = 6; + Column2.Name = "Column2"; + // + // Column3 + // + Column3.HeaderText = "Количество"; + Column3.MinimumWidth = 6; + Column3.Name = "Column3"; + // + // buttonSave + // + buttonSave.Location = new Point(397, 495); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(106, 31); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(509, 495); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(48, 20); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 6; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(59, 59); + label2.Name = "label2"; + label2.Size = new Size(54, 20); + label2.TabIndex = 7; + label2.Text = "Адрес:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(30, 101); + label3.Name = "label3"; + label3.Size = new Size(113, 20); + label3.TabIndex = 8; + label3.Text = "Дата открытия:"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(640, 557); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs new file mode 100644 index 0000000..cf7d42b --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.cs @@ -0,0 +1,134 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmDataModels.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 LawFirmView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopDocuments; + private int? _id; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopDocuments = new(); + } + + 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) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.OpeningDate; + _shopDocuments = view.ShopDocuments ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка документов магазина"); + try + { + if (_shopDocuments != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _shopDocuments) + { + dataGridView.Rows.Add(new object[] + { + pc.Key, + pc.Value.Item1.DocumentName, + pc.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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date, + ShopDocuments = _shopDocuments + }; + 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/LawFirm/LawFirmView/FormShop.resx b/LawFirm/LawFirmView/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/LawFirm/LawFirmView/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/LawFirm/LawFirmView/FormShopSupply.Designer.cs b/LawFirm/LawFirmView/FormShopSupply.Designer.cs new file mode 100644 index 0000000..95685f2 --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.Designer.cs @@ -0,0 +1,148 @@ +namespace LawFirmView +{ + partial class FormShopSupply + { + /// + /// 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() + { + comboBoxShop = new ComboBox(); + comboBoxDocument = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(112, 16); + comboBoxShop.Margin = new Padding(3, 4, 3, 4); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(243, 28); + comboBoxShop.TabIndex = 0; + // + // comboBoxDocument + // + comboBoxDocument.FormattingEnabled = true; + comboBoxDocument.Location = new Point(112, 55); + comboBoxDocument.Margin = new Padding(3, 4, 3, 4); + comboBoxDocument.Name = "comboBoxDocument"; + comboBoxDocument.Size = new Size(243, 28); + comboBoxDocument.TabIndex = 1; + // + // textBoxCount + // + textBoxCount.Location = new Point(112, 93); + textBoxCount.Margin = new Padding(3, 4, 3, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(243, 27); + textBoxCount.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(112, 163); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(86, 31); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(253, 163); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 12); + label1.Name = "label1"; + label1.Size = new Size(83, 20); + label1.TabIndex = 5; + label1.Text = "Магазины:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(16, 59); + label2.Name = "label2"; + label2.Size = new Size(90, 20); + label2.TabIndex = 6; + label2.Text = "Документы:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(16, 97); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 7; + label3.Text = "Количество:"; + // + // FormShopSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(409, 212); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxDocument); + Controls.Add(comboBoxShop); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShopSupply"; + Text = "Выбор"; + Load += FormShopSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShopSupply.cs b/LawFirm/LawFirmView/FormShopSupply.cs new file mode 100644 index 0000000..2ca73de --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.cs @@ -0,0 +1,125 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.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 LawFirmView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IShopLogic _logicS; + public FormShopSupply(ILogger logger, IDocumentLogic logicD, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicS = logicS; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для пополнения"); + try + { + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.SupplyDocuments( + new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue), + ShopName = comboBoxShop.Text + }, + new DocumentBindingModel + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue), + DocumentName = comboBoxDocument.Text + }, + 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/LawFirm/LawFirmView/FormShopSupply.resx b/LawFirm/LawFirmView/FormShopSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.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/LawFirm/LawFirmView/FormShops.Designer.cs b/LawFirm/LawFirmView/FormShops.Designer.cs new file mode 100644 index 0000000..0a496c3 --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace LawFirmView +{ + 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() + { + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonAdd + // + buttonAdd.Location = new Point(514, 28); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(86, 31); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(514, 83); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(86, 31); + buttonUpd.TabIndex = 1; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(514, 139); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(86, 31); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(514, 191); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(86, 31); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(489, 491); + dataGridView.TabIndex = 4; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(638, 507); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShops.cs b/LawFirm/LawFirmView/FormShops.cs new file mode 100644 index 0000000..04fc851 --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.cs @@ -0,0 +1,122 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.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 LawFirmView +{ + 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 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 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 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 buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopDocuments"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } +} diff --git a/LawFirm/LawFirmView/FormShops.resx b/LawFirm/LawFirmView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/LawFirm/LawFirmView/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/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index ab37d8c..79b603a 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -37,9 +37,12 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +50,9 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } }