From fef056226a64c79cef3ee6a5a877d2ae1e3603f5 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Sun, 16 Jun 2024 23:15:45 +0400 Subject: [PATCH] laba2_hard --- .../BusinessLogics/OrderLogic.cs | 27 +- .../BusinessLogics/ShopLogic.cs | 62 +++ .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 2 + .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 2 + .../Models/IShopModel.cs | 2 + .../DataFileSingleton.cs | 12 +- .../Implements/ShopStorage.cs | 107 +++++ .../FishFactoryFileImplement/Models/Order.cs | 3 +- .../FishFactoryFileImplement/Models/Shop.cs | 108 +++++ .../Implements/ShopStorage.cs | 5 + .../FishFactoryListImplement/Models/Shop.cs | 1 + .../FormSellCanned.Designer.cs | 119 ++++++ FishFactory/FishFactoryView/FormSellCanned.cs | 90 +++++ .../FishFactoryView/FormSellCanned.resx | 120 ++++++ .../FishFactoryView/FormShop.Designer.cs | 377 ++++++++++-------- FishFactory/FishFactoryView/FormShop.cs | 214 +++++----- .../FishFactoryView/MainForm.Designer.cs | 19 +- FishFactory/FishFactoryView/MainForm.cs | 9 + FishFactory/FishFactoryView/Program.cs | 1 + 21 files changed, 990 insertions(+), 293 deletions(-) create mode 100644 FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs create mode 100644 FishFactory/FishFactoryFileImplement/Models/Shop.cs create mode 100644 FishFactory/FishFactoryView/FormSellCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormSellCanned.cs create mode 100644 FishFactory/FishFactoryView/FormSellCanned.resx diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index 840b83e..964f7e6 100644 --- a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,11 +17,15 @@ namespace FishFactoryBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + private readonly ICannedStorage _cannedStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICannedStorage cannedStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _cannedStorage = cannedStorage; } public List? ReadList(OrderSearchModel? model) @@ -66,8 +70,25 @@ namespace FishFactoryBusinessLogic.BusinessLogics throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } model.Status = status; - if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - _orderStorage.Update(model); + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + var canned = _cannedStorage.GetElement(new() { Id = element.CannedId }); + if (canned == null) + { + throw new ArgumentNullException(nameof(canned)); + } + if (!_shopLogic.AddCanned(canned, element.Count)) + { + throw new Exception($"AddCanned operation failed. Shop is full."); + } + } + else + { + model.DateImplement = element.DateImplement; + } + CheckModel(model, false); + _orderStorage.Update(model); return true; } diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs index bb71a62..4d7b21b 100644 --- a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -98,6 +98,12 @@ namespace FishFactoryBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); } + if (model.MaxCountCanned < 0) + { + throw new ArgumentException( + "Максимальное количество консервы в магазине не может быть меньше нуля", + nameof(model.MaxCountCanned)); + } _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -128,6 +134,10 @@ namespace FishFactoryBusinessLogic.BusinessLogics _logger.LogWarning("AddCannedInShop element not found"); return false; } + if (element.MaxCountCanned - element.ListCanned.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Магазин переполнен", nameof(count)); + } _logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id); if (element.ListCanned.TryGetValue(Canned.Id, out var pair)) @@ -150,9 +160,61 @@ namespace FishFactoryBusinessLogic.BusinessLogics Address = element.Address, ShopName = element.ShopName, DateOpening = element.DateOpening, + MaxCountCanned = element.MaxCountCanned, ListCanned = element.ListCanned }); return true; } + public bool AddCanned(ICannedModel model, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count)); + } + var freeCount = _shopStorage.GetFullList() + .Select(x => x.MaxCountCanned - x.ListCanned + .Select(p => p.Value.Item2).Sum()).Sum() - count; + if (freeCount < 0) + { + _logger.LogInformation("AddCanned. Не удалось добавить изделия в магазины, они переполнены."); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + int countFree = shop.MaxCountCanned - shop.ListCanned.Select(x => x.Value.Item2).Sum(); + if (countFree < count) + { + if (!AddCannedInShop(new() { Id = shop.Id }, model, countFree)) + { + _logger.LogWarning("AddCannedInShop operation failed."); + return false; + } + count -= countFree; + } + else + { + if (!AddCannedInShop(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddCannedInShop operation failed."); + return false; + } + count = 0; + } + if (count == 0) + { + return true; + } + } + return false; + } + + public bool SellCanned(ICannedModel model, int count) + { + return _shopStorage.SellCanned(model, count); + } } } diff --git a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs index 5ffad0a..f726951 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs @@ -15,6 +15,7 @@ namespace FishFactoryContracts.BindingModels public string Address { get; set; } = string.Empty; public DateTime DateOpening { get; set; } = DateTime.Now; + public int MaxCountCanned { get; set; } public Dictionary ListCanned { diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs index b333579..aa1d9a6 100644 --- a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count); + bool AddCanned(ICannedModel canned, int count); + bool SellCanned(ICannedModel canned, int count); } } diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs index fd2f8a5..f705a30 100644 --- a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.SearchModels; using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace FishFactoryContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellCanned(ICannedModel model, int count); } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs index 8e69af8..9daa236 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs @@ -19,6 +19,8 @@ namespace FishFactoryContracts.ViewModels [DisplayName("Дата открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; + [DisplayName("Максимальное количество консерв")] + public int MaxCountCanned { get; set; } public Dictionary ListCanned { diff --git a/FishFactory/FishFactoryDataModels/Models/IShopModel.cs b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs index 64c7cb4..f19b54b 100644 --- a/FishFactory/FishFactoryDataModels/Models/IShopModel.cs +++ b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,6 +12,7 @@ namespace FishFactoryDataModels.Models string ShopName { get; } string Address { get; } DateTime DateOpening { get; } + int MaxCountCanned { get; } Dictionary ListCanned { get; } } } diff --git a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs index 4f3e9cc..3a4bb89 100644 --- a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs +++ b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs @@ -14,10 +14,12 @@ namespace FishFactoryFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string CannedFileName = "Canned.xml"; - public List Components { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Canneds { get; private set; } - public static DataFileSingleton GetInstance() + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -44,11 +46,13 @@ namespace FishFactoryFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveCannedes() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } } } diff --git a/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..58294e6 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,107 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using FishFactoryFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + 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 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 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 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; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public bool SellCanned(ICannedModel model, int count) + { + if (source.Shops.Select(x => x.ListCanned.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < count) + { + return false; + } + foreach (var shop in source.Shops.Where(x => x.ListCanned.ContainsKey(model.Id))) + { + int countInCurrentShop = shop.ListCanned[model.Id].Item2; + if (countInCurrentShop <= count) + { + shop.ListCanned.Remove(model.Id); + count -= countInCurrentShop; + } + else + { + shop.ListCanned[model.Id] = (shop.ListCanned[model.Id].Item1, countInCurrentShop - count); + count = 0; + } + if (count == 0) + { + return true; + } + } + return false; + } + } +} diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index dec97fe..93dfc04 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -35,7 +35,8 @@ namespace FishFactoryFileImplement.Models Count = model.Count, Sum = model.Sum, Status = model.Status, - DateCreate = model.DateCreate + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, }; } public static Order? Create(XElement element) diff --git a/FishFactory/FishFactoryFileImplement/Models/Shop.cs b/FishFactory/FishFactoryFileImplement/Models/Shop.cs new file mode 100644 index 0000000..3caadc7 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Models/Shop.cs @@ -0,0 +1,108 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FishFactoryFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpening { get; private set; } + public int MaxCountCanned { get; private set; } + public Dictionary CountCanned + { + get; + private set; + } = new(); + + private Dictionary? _shopCanned = null; + public Dictionary ListCanned + { + get + { + if (_shopCanned == null) + { + var source = DataFileSingleton.GetInstance(); + _shopCanned = + CountCanned.ToDictionary(x => x.Key, + y => ((source.Canneds.FirstOrDefault(z => z.Id == y.Key) as ICannedModel)!, y.Value)); + } + return _shopCanned; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + MaxCountCanned = model.MaxCountCanned, + DateOpening = model.DateOpening, + CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + MaxCountCanned = Convert.ToInt32(element.Element("MaxCountCanned")!.Value), + CountCanned = element.Element("ListCanned")!.Elements("Canned").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; + Address = model.Address; + DateOpening = model.DateOpening; + MaxCountCanned = model.MaxCountCanned; + CountCanned = model.ListCanned.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopCanned = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + ListCanned = ListCanned, + DateOpening = DateOpening, + MaxCountCanned = MaxCountCanned, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("MaxCountCanned", MaxCountCanned), + new XElement("ListCanned", CountCanned.Select(x => new XElement("Canned", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs index c8bb272..7b1699e 100644 --- a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs +++ b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using FishFactoryContracts.SearchModels; using FishFactoryContracts.StoragesContracts; using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; using FishFactoryListImplement.Models; using System; using System.Collections.Generic; @@ -103,5 +104,9 @@ namespace FishFactoryListImplement.Implements } return null; } + public bool SellCanned(ICannedModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/FishFactory/FishFactoryListImplement/Models/Shop.cs b/FishFactory/FishFactoryListImplement/Models/Shop.cs index 2d7700c..a568dc0 100644 --- a/FishFactory/FishFactoryListImplement/Models/Shop.cs +++ b/FishFactory/FishFactoryListImplement/Models/Shop.cs @@ -54,5 +54,6 @@ namespace FishFactoryListImplement.Models ListCanned = ListCanned, DateOpening = DateOpening, }; + public int MaxCountCanned => throw new NotImplementedException(); } } diff --git a/FishFactory/FishFactoryView/FormSellCanned.Designer.cs b/FishFactory/FishFactoryView/FormSellCanned.Designer.cs new file mode 100644 index 0000000..cf2d74a --- /dev/null +++ b/FishFactory/FishFactoryView/FormSellCanned.Designer.cs @@ -0,0 +1,119 @@ +namespace FishFactoryView +{ + partial class FormSellCanned + { + /// + /// 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() + { + comboBoxCanned = new ComboBox(); + textBoxCount = new TextBox(); + labelCanned = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxCanned + // + comboBoxCanned.FormattingEnabled = true; + comboBoxCanned.Location = new Point(162, 27); + comboBoxCanned.Name = "comboBoxCanned"; + comboBoxCanned.Size = new Size(244, 28); + comboBoxCanned.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(162, 81); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(244, 27); + textBoxCount.TabIndex = 1; + // + // labelCanned + // + labelCanned.AutoSize = true; + labelCanned.Location = new Point(25, 30); + labelCanned.Name = "labelCanned"; + labelCanned.Size = new Size(76, 20); + labelCanned.TabIndex = 2; + labelCanned.Text = "Консерва"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(25, 84); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 3; + labelCount.Text = "Количество"; + // + // buttonSave + // + buttonSave.Location = new Point(162, 150); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(300, 150); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellCanned + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(418, 191); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelCanned); + Controls.Add(textBoxCount); + Controls.Add(comboBoxCanned); + Name = "FormSellCanned"; + Text = "Продажа консервы"; + Load += FormSellCanned_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxCanned; + private TextBox textBoxCount; + private Label labelCanned; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormSellCanned.cs b/FishFactory/FishFactoryView/FormSellCanned.cs new file mode 100644 index 0000000..8d8392c --- /dev/null +++ b/FishFactory/FishFactoryView/FormSellCanned.cs @@ -0,0 +1,90 @@ +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.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 FishFactoryView +{ + public partial class FormSellCanned : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logicCanned; + private readonly IShopLogic _logicShop; + + public FormSellCanned(ILogger logger, ICannedLogic logicCanned, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicCanned = logicCanned; + _logicShop = logicShop; + } + + private void FormSellCanned_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка консервы для продажи"); + try + { + var list = _logicCanned.ReadList(null); + if (list != null) + { + comboBoxCanned.DisplayMember = "CannedName"; + comboBoxCanned.ValueMember = "Id"; + comboBoxCanned.DataSource = list; + comboBoxCanned.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 (comboBoxCanned.SelectedValue == null) + { + MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа консерв"); + try + { + var operationResult = _logicShop.SellCanned(_logicCanned.ReadElement(new CannedSearchModel() + { + Id = Convert.ToInt32(comboBoxCanned.SelectedValue) + })!, Convert.ToInt32(textBoxCount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при продаже консервы. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка продажи консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormSellCanned.resx b/FishFactory/FishFactoryView/FormSellCanned.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/FishFactory/FishFactoryView/FormSellCanned.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/FishFactory/FishFactoryView/FormShop.Designer.cs b/FishFactory/FishFactoryView/FormShop.Designer.cs index 3124185..0716754 100644 --- a/FishFactory/FishFactoryView/FormShop.Designer.cs +++ b/FishFactory/FishFactoryView/FormShop.Designer.cs @@ -1,184 +1,209 @@ namespace FishFactoryView { - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + 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); - } + /// + /// 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() - { - textBoxShop = new TextBox(); - textBoxAddress = new TextBox(); - dateTimePicker = new DateTimePicker(); - dataGridView = new DataGridView(); - labelName = new Label(); - labelAddress = new Label(); - labelDate = new Label(); - buttonSave = new Button(); - buttonCancel = new Button(); - ColumnId = new DataGridViewTextBoxColumn(); - ColumnCannedName = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // textBoxShop - // - textBoxShop.Location = new Point(394, 12); - textBoxShop.Name = "textBoxShop"; - textBoxShop.Size = new Size(277, 27); - textBoxShop.TabIndex = 0; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(394, 57); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(277, 27); - textBoxAddress.TabIndex = 1; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(394, 100); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(277, 27); - dateTimePicker.TabIndex = 2; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnCannedName, ColumnCount }); - dataGridView.Location = new Point(12, 147); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(659, 309); - dataGridView.TabIndex = 3; - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(225, 15); - labelName.Name = "labelName"; - labelName.Size = new Size(147, 20); - labelName.TabIndex = 4; - labelName.Text = "Название магазина"; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(225, 60); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(51, 20); - labelAddress.TabIndex = 5; - labelAddress.Text = "Адрес"; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(225, 105); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(110, 20); - labelDate.TabIndex = 6; - labelDate.Text = "Дата открытия"; - // - // buttonSave - // - buttonSave.Location = new Point(411, 467); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 7; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(549, 467); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 8; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // ColumnId - // - ColumnId.HeaderText = "Id"; - ColumnId.MinimumWidth = 6; - ColumnId.Name = "ColumnId"; - ColumnId.Visible = false; - ColumnId.Width = 125; - // - // ColumnCannedName - // - ColumnCannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnCannedName.HeaderText = "Консерва"; - ColumnCannedName.MinimumWidth = 6; - ColumnCannedName.Name = "ColumnCannedName"; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.MinimumWidth = 6; - ColumnCount.Name = "ColumnCount"; - ColumnCount.Width = 125; - // - // FormShop - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(683, 508); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(labelDate); - Controls.Add(labelAddress); - Controls.Add(labelName); - Controls.Add(dataGridView); - Controls.Add(dateTimePicker); - Controls.Add(textBoxAddress); - Controls.Add(textBoxShop); - Name = "FormShop"; - Text = "Создание магазина"; - Load += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxShop = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnCannedName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + labelName = new Label(); + labelAddress = new Label(); + labelDate = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + numericUpDownCount = new NumericUpDown(); + labelCount = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // textBoxShop + // + textBoxShop.Location = new Point(394, 12); + textBoxShop.Name = "textBoxShop"; + textBoxShop.Size = new Size(277, 27); + textBoxShop.TabIndex = 0; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(394, 57); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(277, 27); + textBoxAddress.TabIndex = 1; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(394, 100); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(277, 27); + dateTimePicker.TabIndex = 2; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnCannedName, ColumnCount }); + dataGridView.Location = new Point(12, 191); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(659, 309); + dataGridView.TabIndex = 3; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnCannedName + // + ColumnCannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnCannedName.HeaderText = "Консерва"; + ColumnCannedName.MinimumWidth = 6; + ColumnCannedName.Name = "ColumnCannedName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(202, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(147, 20); + labelName.TabIndex = 4; + labelName.Text = "Название магазина"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(202, 60); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(51, 20); + labelAddress.TabIndex = 5; + labelAddress.Text = "Адрес"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(202, 105); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(110, 20); + labelDate.TabIndex = 6; + labelDate.Text = "Дата открытия"; + // + // buttonSave + // + buttonSave.Location = new Point(415, 506); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(554, 506); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(394, 148); + numericUpDownCount.Maximum = new decimal(new int[] { 500, 0, 0, 0 }); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(277, 27); + numericUpDownCount.TabIndex = 9; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(202, 150); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(170, 20); + labelCount.TabIndex = 10; + labelCount.Text = "Вместимость магазина"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(683, 547); + Controls.Add(labelCount); + Controls.Add(numericUpDownCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelDate); + Controls.Add(labelAddress); + Controls.Add(labelName); + Controls.Add(dataGridView); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxShop); + Name = "FormShop"; + Text = "Создание магазина"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private TextBox textBoxShop; - private TextBox textBoxAddress; - private DateTimePicker dateTimePicker; - private DataGridView dataGridView; - private Label labelName; - private Label labelAddress; - private Label labelDate; - private Button buttonSave; - private Button buttonCancel; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnCannedName; - private DataGridViewTextBoxColumn ColumnCount; - } + private TextBox textBoxShop; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private DataGridView dataGridView; + private Label labelName; + private Label labelAddress; + private Label labelDate; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnCannedName; + private DataGridViewTextBoxColumn ColumnCount; + private NumericUpDown numericUpDownCount; + private Label labelCount; + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShop.cs b/FishFactory/FishFactoryView/FormShop.cs index 294b0dc..f08a9f7 100644 --- a/FishFactory/FishFactoryView/FormShop.cs +++ b/FishFactory/FishFactoryView/FormShop.cs @@ -15,116 +15,118 @@ using System.Windows.Forms; namespace FishFactoryView { - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - private int? _id; - private Dictionary _shopListCanned; - public int Id { set { _id = value; } } + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopListCanned; + public int Id { set { _id = value; } } - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _shopListCanned = new(); - } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopListCanned = new(); + } - private void FormShop_Load(object sender, EventArgs e) - { + 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) - { - textBoxShop.Text = view.ShopName; - textBoxAddress.Text = view.Address; - dateTimePicker.Text = view.DateOpening.ToString(); - _shopListCanned = view.ListCanned ?? new Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + numericUpDownCount.Value = view.MaxCountCanned; + _shopListCanned = view.ListCanned ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } - private void LoadData() - { - _logger.LogInformation("Загрузка консервы магазина"); - try - { - if (_shopListCanned != null) - { - dataGridView.Rows.Clear(); - foreach (var elem in _shopListCanned) - { - dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.CannedName, elem.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки консерв магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void LoadData() + { + _logger.LogInformation("Загрузка консервы магазина"); + try + { + if (_shopListCanned != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopListCanned) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.CannedName, elem.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(textBoxShop.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 = textBoxShop.Text, - Address = textBoxAddress.Text, - DateOpening = dateTimePicker.Value.Date, - ListCanned = _shopListCanned - }; - 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 buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShop.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 = textBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + MaxCountCanned = (int)numericUpDownCount.Value, + ListCanned = _shopListCanned + }; + 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(); - } - } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/FishFactory/FishFactoryView/MainForm.Designer.cs b/FishFactory/FishFactoryView/MainForm.Designer.cs index 32e5b51..31c520f 100644 --- a/FishFactory/FishFactoryView/MainForm.Designer.cs +++ b/FishFactory/FishFactoryView/MainForm.Designer.cs @@ -40,6 +40,7 @@ консервыToolStripMenuItem = new ToolStripMenuItem(); ShopsToolStripMenuItem = new ToolStripMenuItem(); ButtonAddCannedInShop = new Button(); + buttonSellCanned = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -124,21 +125,21 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(182, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; // // консервыToolStripMenuItem // консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; - консервыToolStripMenuItem.Size = new Size(224, 26); + консервыToolStripMenuItem.Size = new Size(182, 26); консервыToolStripMenuItem.Text = "Консервы"; консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click; // // ShopsToolStripMenuItem // ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(224, 26); + ShopsToolStripMenuItem.Size = new Size(182, 26); ShopsToolStripMenuItem.Text = "Магазины"; ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; // @@ -152,11 +153,22 @@ ButtonAddCannedInShop.UseVisualStyleBackColor = true; ButtonAddCannedInShop.Click += ButtonAddCannedInShop_Click; // + // buttonSellCanned + // + buttonSellCanned.Location = new Point(885, 434); + buttonSellCanned.Name = "buttonSellCanned"; + buttonSellCanned.Size = new Size(179, 29); + buttonSellCanned.TabIndex = 9; + buttonSellCanned.Text = "Продать консервы"; + buttonSellCanned.UseVisualStyleBackColor = true; + buttonSellCanned.Click += buttonSellCanned_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1076, 487); + Controls.Add(buttonSellCanned); Controls.Add(ButtonAddCannedInShop); Controls.Add(button5); Controls.Add(button4); @@ -189,5 +201,6 @@ private ToolStripMenuItem консервыToolStripMenuItem; private ToolStripMenuItem ShopsToolStripMenuItem; private Button ButtonAddCannedInShop; + private Button buttonSellCanned; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/MainForm.cs b/FishFactory/FishFactoryView/MainForm.cs index 440592c..16666e7 100644 --- a/FishFactory/FishFactoryView/MainForm.cs +++ b/FishFactory/FishFactoryView/MainForm.cs @@ -174,5 +174,14 @@ MessageBoxIcon.Error); form.ShowDialog(); } } + private void buttonSellCanned_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellCanned)); + if (service is FormSellCanned form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 30932f0..321348f 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -52,6 +52,7 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file