diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index 9789315..ff9403e 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,10 +17,14 @@ namespace ComputersShopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + private readonly IComputerStorage _computerStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IComputerStorage computerStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _computerStorage = computerStorage; } public bool CreateOrder(OrderBindingModel model) { @@ -52,7 +56,20 @@ namespace ComputersShopBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) + { + + model.DateImplement = DateTime.Now; + var computer = _computerStorage.GetElement(new() { Id = viewModel.ComputerId }); + if (computer == null) + { + throw new ArgumentNullException(nameof(computer)); + } + if (!_shopLogic.AddComputers(computer, viewModel.Count)) + { + throw new Exception($"AddComputers operation failed - нет места"); + } + } else { model.DateImplement = viewModel.DateImplement; @@ -61,7 +78,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics if (_orderStorage.Update(model) == null) { model.Status--; - _logger.LogWarning("Update operation failed"); + _logger.LogWarning("Change status operation failed"); return false; } return true; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 2d963b1..42f57b9 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -31,6 +32,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics if (quantity <= 0) { + return false; throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity)); } @@ -43,7 +45,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics return false; } - _logger.LogInformation("AddComputerInShop find. Id:{Id}", element.Id); + if (element.Capacity - element.Computers.Select(x => x.Value.Item2).Sum() < quantity) + { + throw new ArgumentNullException("В магазине не хватает места", nameof(quantity)); + } if (element.Computers.TryGetValue(computer.Id, out var pair)) { @@ -62,11 +67,63 @@ namespace ComputersShopBusinessLogic.BusinessLogics ShopAddress = element.ShopAddress, ShopName = element.ShopName, DateOpening = element.DateOpening, - Computers = element.Computers + Computers = element.Computers, + Capacity = element.Capacity, }); return true; } + public bool AddComputers(IComputerModel computer, int quantity) + { + if (computer == null) + { + throw new ArgumentNullException(nameof(computer)); + } + if (quantity <= 0) + { + throw new ArgumentException("Количество документов должно быть больше 0", nameof(quantity)); + } + _logger.LogInformation("AddComputers. ShopName:{ShopName}. Id:{Id}", computer.ComputerName, computer.Id); + var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.Computers.Select(x => x.Value.Item2).Sum()).Sum(); + if (allFreeQuantity < quantity) + { + _logger.LogWarning("AddComputers operation failed."); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + int freeQuantity = shop.Capacity - shop.Computers.Select(x => x.Value.Item2).Sum(); + if (freeQuantity <= 0) + { + continue; + } + if (freeQuantity < quantity) + { + if (!AddComputer(new() { Id = shop.Id }, computer, freeQuantity)) + { + _logger.LogWarning("AddComputers operation failed."); + return false; + } + quantity -= freeQuantity; + } + else + { + if (!AddComputer(new() { Id = shop.Id }, computer, quantity)) + { + _logger.LogWarning("AddComputers operation failed."); + return false; + } + quantity = 0; + } + if (quantity == 0) + { + return true; + } + } + _logger.LogWarning("AddComputers operation failed."); + return false; + } + public bool Create(ShopBindingModel model) { CheckModel(model); @@ -131,6 +188,11 @@ namespace ComputersShopBusinessLogic.BusinessLogics return list; } + public bool SellComputers(IComputerModel computer, int quantity) + { + return _shopStorage.SellComputers(computer, quantity); + } + public bool Update(ShopBindingModel model) { CheckModel(model, false); @@ -177,4 +239,4 @@ namespace ComputersShopBusinessLogic.BusinessLogics } } } -} \ No newline at end of file +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs index 59d6ff3..4a73f59 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs @@ -14,5 +14,6 @@ namespace ComputersShopContracts.BindingModels public string ShopAddress { get; set; } = string.Empty; public DateTime DateOpening { get; set; } = DateTime.Now; public Dictionary Computers { get; set; } = new(); + public int Capacity { get; set; } } -} \ No newline at end of file +} diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IShopLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IShopLogic.cs index a1f8951..b6277fe 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IShopLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IShopLogic.cs @@ -18,5 +18,7 @@ namespace ComputersShopContracts.BusinessLogicContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddComputer(ShopSearchModel model, IComputerModel computer, int quantity); + bool AddComputers(IComputerModel computer, int quantity); + bool SellComputers(IComputerModel computer, int quantity); } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IShopStorage.cs index 74abeaf..5d28ba7 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IShopStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace ComputersShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellComputers(IComputerModel model, int quantity); } -} \ No newline at end of file +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs index 62d4e1a..cf69095 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs @@ -19,5 +19,7 @@ namespace ComputersShopContracts.ViewModels public string ShopAddress { get; set; } = string.Empty; [DisplayName("Дата открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; + [DisplayName("Вместимость магазина")] + public int Capacity { get; set; } } -} \ No newline at end of file +} diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index e2facb0..6362aa1 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -14,9 +14,11 @@ namespace ComputersShopFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string ComputerFileName = "Computer.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Computers { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,11 +30,13 @@ namespace ComputersShopFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2251118 --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,132 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using ComputersShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public bool SellComputers(IComputerModel model, int quantity) + { + int hasCount = 0; + + source.Shops.ForEach(x => + { + if (x.Computers.TryGetValue(model.Id, out var pair)) + { + hasCount += pair.Item2; + } + }); + + if (hasCount < quantity) return false; + + source.Shops.ForEach(x => + { + if (x.Computers.TryGetValue(model.Id, out var pair)) + { + if (quantity >= pair.Item2) + { + quantity -= pair.Item2; + x.Computers[model.Id] = (model, 0); + } + else + { + x.Computers[model.Id] = (model, pair.Item2 - quantity); + quantity = 0; + } + + x.Update(new ShopBindingModel + { + Id = x.Id, + ShopAddress = x.ShopAddress, + Capacity = x.Capacity, + DateOpening = x.DateOpening, + ShopName = x.ShopName, + Computers = x.Computers + }); + } + }); + + source.SaveShops(); + return true; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Models/Shop.cs b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs new file mode 100644 index 0000000..e2eb630 --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs @@ -0,0 +1,108 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ComputersShopFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string ShopAddress { get; private set; } = string.Empty; + public DateTime DateOpening { get; private set; } + public int Capacity { get; private set; } + public Dictionary ComputersCount = new(); + public Dictionary? _computers = null; + public Dictionary Computers + { + get + { + if (_computers == null) + { + var source = DataFileSingleton.GetInstance(); + _computers = ComputersCount.ToDictionary( + x => x.Key, + y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!, + y.Value) + ); + } + return _computers; + } + } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + ShopAddress = model.ShopAddress, + DateOpening = model.DateOpening, + Capacity = model.Capacity, + ComputersCount = model.Computers.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + ShopAddress = element.Element("ShopAddress")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + Capacity = Convert.ToInt32(element.Element("Capacity")!.Value), + ComputersCount = element.Element("Computers")!.Elements("Computer") + .ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + ShopAddress = model.ShopAddress; + DateOpening = model.DateOpening; + Capacity = model.Capacity; + ComputersCount = model.Computers.ToDictionary(x => x.Key, x => x.Value.Item2); + _computers = null; + + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + ShopAddress = ShopAddress, + DateOpening = DateOpening, + Capacity = Capacity, + Computers = Computers + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("ShopAddress", ShopAddress), + new XElement("DateOpening", DateOpening.ToString()), + new XElement("Capacity", Capacity.ToString()), + new XElement("Computers", ComputersCount.Select(x => + new XElement("Computer", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 0becd1a..5ee2b99 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -1,39 +1,40 @@ namespace ComputersShopView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.справочникToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.computerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.replenishmentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.продатьКомпьютеромToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -47,51 +48,59 @@ // menuStrip // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.directoryToolStripMenuItem, - this.replenishmentToolStripMenuItem}); + this.справочникToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem, + this.продатьКомпьютеромToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1047, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; // - // directoryToolStripMenuItem + // справочникToolStripMenuItem // - this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.computerToolStripMenuItem, this.componentsToolStripMenuItem, - this.shopsToolStripMenuItem}); - this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; - this.directoryToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.directoryToolStripMenuItem.Text = "Cправочники"; + this.магазиныToolStripMenuItem}); + this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; + this.справочникToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникToolStripMenuItem.Text = "Справочники"; // // computerToolStripMenuItem // this.computerToolStripMenuItem.Name = "computerToolStripMenuItem"; this.computerToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.computerToolStripMenuItem.Text = "Компьютеры"; - this.computerToolStripMenuItem.Click += new System.EventHandler(this.ComputersToolStripMenuItem_Click); + this.computerToolStripMenuItem.Click += ComputersToolStripMenuItem_Click; // // componentsToolStripMenuItem // this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentsToolStripMenuItem.Text = "Компоненты"; - this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + this.componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // - // shopsToolStripMenuItem + // магазиныToolStripMenuItem // - this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - this.shopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.shopsToolStripMenuItem.Text = "Магазины"; - this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += ShopToolStripMenuItem_Click; // - // replenishmentToolStripMenuItem + // пополнениеМагазинаToolStripMenuItem // - this.replenishmentToolStripMenuItem.Name = "replenishmentToolStripMenuItem"; - this.replenishmentToolStripMenuItem.Size = new System.Drawing.Size(143, 20); - this.replenishmentToolStripMenuItem.Text = "Пополнение магазина"; - this.replenishmentToolStripMenuItem.Click += new System.EventHandler(this.ShopReplenishmentToolStripMenuItem_Click); + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(143, 20); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += shopReplenishmentToolStripMenuItem_Click; + // + // продатьКомпьютеромToolStripMenuItem + // + this.продатьКомпьютеромToolStripMenuItem.Name = "продатьКомпьютеромToolStripMenuItem"; + this.продатьКомпьютеромToolStripMenuItem.Size = new System.Drawing.Size(131, 20); + this.продатьКомпьютеромToolStripMenuItem.Text = "Продать компьютер"; + this.продатьКомпьютеромToolStripMenuItem.Click += ButtonSellComputer_Click; // // dataGridView // @@ -110,7 +119,7 @@ this.buttonCreateOrder.TabIndex = 2; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + this.buttonCreateOrder.Click += ButtonCreateOrder_Click; // // buttonTakeOrderInWork // @@ -120,7 +129,7 @@ this.buttonTakeOrderInWork.TabIndex = 3; this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + this.buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // buttonOrderReady // @@ -130,7 +139,7 @@ this.buttonOrderReady.TabIndex = 4; this.buttonOrderReady.Text = "Заказ готов"; this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + this.buttonOrderReady.Click += ButtonOrderReady_Click; // // buttonIssuedOrder // @@ -140,7 +149,7 @@ this.buttonIssuedOrder.TabIndex = 5; this.buttonIssuedOrder.Text = "Заказ выдан"; this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + this.buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // // buttonRef // @@ -150,7 +159,7 @@ this.buttonRef.TabIndex = 6; this.buttonRef.Text = "Обновить список"; this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + this.buttonRef.Click += ButtonRef_Click; // // FormMain // @@ -167,28 +176,29 @@ this.MainMenuStrip = this.menuStrip; this.Name = "FormMain"; this.Text = "Магазин электроники"; - this.Load += new System.EventHandler(this.FormMain_Load); + Load += FormMain_Load; this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); - } + } - #endregion + #endregion - private MenuStrip menuStrip; - private ToolStripMenuItem dictionaryToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private ToolStripMenuItem computerToolStripMenuItem; - private ToolStripMenuItem componentsToolStripMenuItem; - private ToolStripMenuItem replenishmentToolStripMenuItem; - private ToolStripMenuItem shopsToolStripMenuItem; + private MenuStrip menuStrip; + private ToolStripMenuItem справочникToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private ToolStripMenuItem computerToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private ToolStripMenuItem продатьКомпьютеромToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index 2d588c3..5c9d5ed 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -14,176 +14,189 @@ using System.Windows.Forms; namespace ComputersShopView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ComputerId"].Visible = false; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); - if (service is FormComputers form) - { - form.ShowDialog(); - } - } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ComputerId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); + if (service is FormComputers form) + { + form.ShowDialog(); + } + } private void ShopToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) { form.ShowDialog(); } } private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ShopReplenishmentToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void shopReplenishmentToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); + if (service is FormShopReplenishment form) { form.ShowDialog(); } } + + private void ButtonSellComputer_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellComputers)); + if (service is FormSellComputers form) + { + form.ShowDialog(); + LoadData(); + } + } } } diff --git a/ComputersShop/ComputersShopView/FormSellComputers.Designer.cs b/ComputersShop/ComputersShopView/FormSellComputers.Designer.cs new file mode 100644 index 0000000..9e933c7 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSellComputers.Designer.cs @@ -0,0 +1,124 @@ +namespace ComputersShopView +{ + partial class FormSellComputers + { + /// + /// 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() + { + ButtonCancel = new Button(); + comboBoxDocuments = new ComboBox(); + numericUpDownCount = new NumericUpDown(); + labelDocument = new Label(); + labelCount = new Label(); + ButtonSave = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // ButtonCancel + // + ButtonCancel.Location = new Point(233, 60); + ButtonCancel.Margin = new Padding(3, 2, 3, 2); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(82, 22); + ButtonCancel.TabIndex = 1; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // comboBoxDocuments + // + comboBoxDocuments.FormattingEnabled = true; + comboBoxDocuments.Location = new Point(89, 6); + comboBoxDocuments.Margin = new Padding(3, 2, 3, 2); + comboBoxDocuments.Name = "comboBoxDocuments"; + comboBoxDocuments.Size = new Size(226, 23); + comboBoxDocuments.TabIndex = 2; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(90, 33); + numericUpDownCount.Margin = new Padding(3, 2, 3, 2); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(225, 23); + numericUpDownCount.TabIndex = 3; + // + // labelDocument + // + labelDocument.AutoSize = true; + labelDocument.Location = new Point(12, 9); + labelDocument.Name = "labelDocument"; + labelDocument.Size = new Size(71, 15); + labelDocument.TabIndex = 4; + labelDocument.Text = "Компьютер"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(11, 35); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(72, 15); + labelCount.TabIndex = 5; + labelCount.Text = "Количество"; + // + // ButtonSave + // + ButtonSave.Location = new Point(145, 60); + ButtonSave.Margin = new Padding(3, 2, 3, 2); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(82, 22); + ButtonSave.TabIndex = 6; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // FormSellComputers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(326, 93); + Controls.Add(ButtonSave); + Controls.Add(labelCount); + Controls.Add(labelDocument); + Controls.Add(numericUpDownCount); + Controls.Add(comboBoxDocuments); + Controls.Add(ButtonCancel); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellComputers"; + Text = "Продажа компьютеров"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Button ButtonCancel; + private ComboBox comboBoxDocuments; + private NumericUpDown numericUpDownCount; + private Label labelDocument; + private Label labelCount; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormSellComputers.cs b/ComputersShop/ComputersShopView/FormSellComputers.cs new file mode 100644 index 0000000..e301cec --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSellComputers.cs @@ -0,0 +1,86 @@ +using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.ViewModels; +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 ComputersShopView +{ + public partial class FormSellComputers : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IComputerLogic _computerLogic; + private readonly List? _listComputer; + public FormSellComputers(ILogger logger, IShopLogic shopLogic, IComputerLogic computerLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _computerLogic = computerLogic; + _listComputer = computerLogic.ReadList(null); + if (_listComputer != null) + { + comboBoxDocuments.DisplayMember = "ComputerName"; + comboBoxDocuments.ValueMember = "Id"; + comboBoxDocuments.DataSource = _listComputer; + comboBoxDocuments.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxDocuments.SelectedValue == null) + { + MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(numericUpDownCount.Text)) + { + MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа поездок"); + try + { + var comp = _computerLogic.ReadElement(new() + { + Id = (int)comboBoxDocuments.SelectedValue + }); + if (comp == null) + { + throw new Exception("Компьютер не найден. Дополнительная информация в логах."); + } + var operationResult = _shopLogic.SellComputers( + computer: comp, + quantity: (int)numericUpDownCount.Value + ); + 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/ComputersShop/ComputersShopView/FormSellComputers.resx b/ComputersShop/ComputersShopView/FormSellComputers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSellComputers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShop.Designer.cs b/ComputersShop/ComputersShopView/FormShop.Designer.cs index 3ae9494..94397db 100644 --- a/ComputersShop/ComputersShopView/FormShop.Designer.cs +++ b/ComputersShop/ComputersShopView/FormShop.Designer.cs @@ -28,182 +28,195 @@ /// private void InitializeComponent() { - this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxAddress = new System.Windows.Forms.TextBox(); - this.labelTime = new System.Windows.Forms.Label(); - this.labelAddress = new System.Windows.Forms.Label(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.labelShop = new System.Windows.Forms.Label(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // dateTimePicker - // - this.dateTimePicker.Location = new System.Drawing.Point(384, 27); - this.dateTimePicker.Name = "dateTimePicker"; - this.dateTimePicker.Size = new System.Drawing.Size(207, 23); - this.dateTimePicker.TabIndex = 26; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(10, 27); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(141, 23); - this.textBoxName.TabIndex = 25; - // - // textBoxAddress - // - this.textBoxAddress.Location = new System.Drawing.Point(158, 27); - this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); - this.textBoxAddress.TabIndex = 24; - // - // labelTime - // - this.labelTime.AutoSize = true; - this.labelTime.Location = new System.Drawing.Point(384, 9); - this.labelTime.Name = "labelTime"; - this.labelTime.Size = new System.Drawing.Size(87, 15); - this.labelTime.TabIndex = 23; - this.labelTime.Text = "Дата открытия"; - // - // labelAddress - // - this.labelAddress.AutoSize = true; - this.labelAddress.Location = new System.Drawing.Point(158, 9); - this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(40, 15); - this.labelAddress.TabIndex = 22; - this.labelAddress.Text = "Адрес"; - // - // dataGridView - // - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnID, - this.ColumnManufactureName, - this.Price, - this.ColumnCount}); - this.dataGridView.Location = new System.Drawing.Point(10, 56); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(581, 327); - this.dataGridView.TabIndex = 21; - // - // ColumnID - // - this.ColumnID.HeaderText = "ID"; - this.ColumnID.MinimumWidth = 8; - this.ColumnID.Name = "ColumnID"; - this.ColumnID.Visible = false; - this.ColumnID.Width = 150; - // - // ColumnManufactureName - // - this.ColumnManufactureName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumnManufactureName.HeaderText = "Название компьютера"; - this.ColumnManufactureName.MinimumWidth = 8; - this.ColumnManufactureName.Name = "ColumnManufactureName"; - // - // Price - // - this.Price.HeaderText = "Цена"; - this.Price.MinimumWidth = 6; - this.Price.Name = "Price"; - this.Price.Width = 125; - // - // ColumnCount - // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.MinimumWidth = 8; - this.ColumnCount.Name = "ColumnCount"; - this.ColumnCount.Width = 150; + labelShop = new Label(); + labelAddress = new Label(); + labelDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + dataGridView = new DataGridView(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + numericUpDownCapacity = new NumericUpDown(); + labelCapacity = new Label(); + ID = new DataGridViewTextBoxColumn(); + DocumentName = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + SuspendLayout(); // // labelShop // - this.labelShop.AutoSize = true; - this.labelShop.Location = new System.Drawing.Point(10, 9); - this.labelShop.Name = "labelShop"; - this.labelShop.Size = new System.Drawing.Size(54, 15); - this.labelShop.TabIndex = 20; - this.labelShop.Text = "Магазин"; + labelShop.AutoSize = true; + labelShop.Location = new Point(10, 16); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(54, 15); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин"; // - // buttonSave + // labelAddress // - this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSave.Location = new System.Drawing.Point(363, 392); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(120, 22); - this.buttonSave.TabIndex = 28; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += ButtonSave_Click; + labelAddress.AutoSize = true; + labelAddress.Location = new Point(156, 16); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(40, 15); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес"; // - // buttonCancel + // labelDate // - this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCancel.Location = new System.Drawing.Point(488, 392); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(103, 22); - this.buttonCancel.TabIndex = 27; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += ButtonCancel_Click; + labelDate.AutoSize = true; + labelDate.Location = new Point(375, 16); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(87, 15); + labelDate.TabIndex = 2; + labelDate.Text = "Дата открытия"; + // + // textBoxName + // + textBoxName.Location = new Point(10, 33); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(140, 23); + textBoxName.TabIndex = 3; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(156, 33); + textBoxAddress.Margin = new Padding(3, 2, 3, 2); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(216, 23); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(375, 33); + dateTimePicker.Margin = new Padding(3, 2, 3, 2); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(123, 23); + dateTimePicker.TabIndex = 5; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, DocumentName, Price, Count }); + dataGridView.Location = new Point(10, 58); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(623, 248); + dataGridView.TabIndex = 6; + // + // ButtonSave + // + ButtonSave.Location = new Point(429, 310); + ButtonSave.Margin = new Padding(3, 2, 3, 2); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(97, 22); + ButtonSave.TabIndex = 7; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(551, 310); + ButtonCancel.Margin = new Padding(3, 2, 3, 2); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(82, 22); + ButtonCancel.TabIndex = 8; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(513, 33); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(120, 23); + numericUpDownCapacity.TabIndex = 9; + // + // labelCapacity + // + labelCapacity.AutoSize = true; + labelCapacity.Location = new Point(513, 16); + labelCapacity.Name = "labelCapacity"; + labelCapacity.Size = new Size(80, 15); + labelCapacity.TabIndex = 10; + labelCapacity.Text = "Вместимость"; + // + // ID + // + ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ID.HeaderText = "ID"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.Visible = false; + // + // DocumentName + // + DocumentName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DocumentName.HeaderText = "Название компьютера"; + DocumentName.MinimumWidth = 6; + DocumentName.Name = "DocumentName"; + // + // Price + // + Price.HeaderText = "Стоимость"; + Price.Name = "Price"; + // + // Count + // + Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; // // FormShop // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(616, 425); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.dateTimePicker); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.textBoxAddress); - this.Controls.Add(this.labelTime); - this.Controls.Add(this.labelAddress); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.labelShop); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.Name = "FormShop"; - this.Text = "Магазин"; + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(648, 338); + Controls.Add(labelCapacity); + Controls.Add(numericUpDownCapacity); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelDate); + Controls.Add(labelAddress); + Controls.Add(labelShop); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShop"; + Text = "Магазин"; Load += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - private void ButtonCancel_Click1(object sender, EventArgs e) - { - throw new NotImplementedException(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion - private DateTimePicker dateTimePicker; + private Label labelShop; + private Label labelAddress; + private Label labelDate; private TextBox textBoxName; private TextBox textBoxAddress; - private Label labelTime; - private Label labelAddress; + private DateTimePicker dateTimePicker; private DataGridView dataGridView; - private Label labelShop; - private Button buttonSave; - private Button buttonCancel; - private DataGridViewTextBoxColumn ColumnID; - private DataGridViewTextBoxColumn ColumnManufactureName; + private Button ButtonSave; + private Button ButtonCancel; + private NumericUpDown numericUpDownCapacity; + private Label labelCapacity; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn DocumentName; private DataGridViewTextBoxColumn Price; - private DataGridViewTextBoxColumn ColumnCount; + private DataGridViewTextBoxColumn Count; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShop.cs b/ComputersShop/ComputersShopView/FormShop.cs index 305f2ac..91ff44f 100644 --- a/ComputersShop/ComputersShopView/FormShop.cs +++ b/ComputersShop/ComputersShopView/FormShop.cs @@ -46,6 +46,7 @@ namespace ComputersShopView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.ShopAddress.ToString(); dateTimePicker.Text = view.DateOpening.ToString(); + numericUpDownCapacity.Value = view.Capacity; _shopComputers = view.Computers ?? new Dictionary(); LoadData(); } @@ -88,7 +89,7 @@ namespace ComputersShopView } if (string.IsNullOrEmpty(textBoxAddress.Text)) { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение магазина"); @@ -100,6 +101,7 @@ namespace ComputersShopView ShopName = textBoxName.Text, ShopAddress = textBoxAddress.Text, DateOpening = dateTimePicker.Value.Date, + Capacity = (int)numericUpDownCapacity.Value, Computers = _shopComputers }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/ComputersShop/ComputersShopView/FormShop.resx b/ComputersShop/ComputersShopView/FormShop.resx index f298a7b..7920df3 100644 --- a/ComputersShop/ComputersShopView/FormShop.resx +++ b/ComputersShop/ComputersShopView/FormShop.resx @@ -57,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 042fc94..17b74b9 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -55,6 +55,7 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/ComputersShop/СomputersShopDataModels/Models/IShopModel.cs b/ComputersShop/СomputersShopDataModels/Models/IShopModel.cs index 2ce1e52..0db9cbf 100644 --- a/ComputersShop/СomputersShopDataModels/Models/IShopModel.cs +++ b/ComputersShop/СomputersShopDataModels/Models/IShopModel.cs @@ -11,6 +11,7 @@ namespace ComputersShopDataModels.Models public string ShopName { get; } public string ShopAddress { get; } DateTime DateOpening { get; } + public int Capacity { get; } Dictionary Computers { get; } } -} \ No newline at end of file +}