From b196286763490911835d0a2b45ebbfce8e1b151c Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Fri, 17 May 2024 00:10:05 +0400 Subject: [PATCH 1/2] laba1_hard --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ca1c7a3..99640b8 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,5 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/FishFactory/ImplementationExtensions +/.gitignore -- 2.25.1 From 8bf0019980b1202cfaa0550f28418856a58129b7 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Fri, 17 May 2024 00:10:19 +0400 Subject: [PATCH 2/2] laba1 --- .../BusinessLogics/ShopLogic.cs | 158 +++++++ .../BindingModels/ShopBindingModel.cs | 25 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 + .../SearchModels/ShopSearchModel.cs | 14 + .../StoragesContracts/IShopStorage.cs | 21 + .../ViewModels/ShopViewModel.cs | 29 ++ .../Models/IShopModel.cs | 16 + .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 107 +++++ .../FishFactoryListImplement/Models/Shop.cs | 58 +++ .../FishFactoryView/FormCanned.Designer.cs | 424 +++++++++--------- FishFactory/FishFactoryView/FormCanned.cs | 404 ++++++++--------- FishFactory/FishFactoryView/FormCanned.resx | 6 + .../FishFactoryView/FormCanneds.Designer.cs | 211 ++++----- FishFactory/FishFactoryView/FormCanneds.cs | 186 ++++---- .../FishFactoryView/FormShop.Designer.cs | 184 ++++++++ FishFactory/FishFactoryView/FormShop.cs | 130 ++++++ FishFactory/FishFactoryView/FormShop.resx | 129 ++++++ .../FormShopCanned.Designer.cs | 143 ++++++ FishFactory/FishFactoryView/FormShopCanned.cs | 99 ++++ .../FishFactoryView/FormShopCanned.resx | 120 +++++ .../FishFactoryView/FormShops.Designer.cs | 114 +++++ FishFactory/FishFactoryView/FormShops.cs | 111 +++++ FishFactory/FishFactoryView/FormShops.resx | 120 +++++ .../FishFactoryView/MainForm.Designer.cs | 350 ++++++++------- FishFactory/FishFactoryView/MainForm.cs | 320 ++++++------- FishFactory/FishFactoryView/Program.cs | 7 +- 27 files changed, 2581 insertions(+), 929 deletions(-) create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IShopModel.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Shop.cs create mode 100644 FishFactory/FishFactoryView/FormShop.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShop.cs create mode 100644 FishFactory/FishFactoryView/FormShop.resx create mode 100644 FishFactory/FishFactoryView/FormShopCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShopCanned.cs create mode 100644 FishFactory/FishFactoryView/FormShopCanned.resx create mode 100644 FishFactory/FishFactoryView/FormShops.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShops.cs create mode 100644 FishFactory/FishFactoryView/FormShops.resx diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..bb71a62 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,158 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", + model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : + _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", + model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddCannedInShop(ShopSearchModel model, ICannedModel Canned, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddCannedInShop. ShopName:{ShopName}.Id:{ Id}", + model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddCannedInShop element not found"); + return false; + } + _logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id); + + if (element.ListCanned.TryGetValue(Canned.Id, out var pair)) + { + element.ListCanned[Canned.Id] = (Canned, count + pair.Item2); + _logger.LogInformation( + "AddCannedInShop. Added {count} {Canned} to '{ShopName}' shop", + count, Canned.CannedName, element.ShopName); + } + else + { + element.ListCanned[Canned.Id] = (Canned, count); + _logger.LogInformation( + "AddCannedInShop. Added {count} new Canned {Canned} to '{ShopName}' shop", + count, Canned.CannedName, element.ShopName); + } + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + DateOpening = element.DateOpening, + ListCanned = element.ListCanned + }); + return true; + } + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..5ffad0a --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,25 @@ +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ListCanned + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..b333579 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count); + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..f9453d3 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..fd2f8a5 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..8e69af8 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,29 @@ +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ListCanned + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/IShopModel.cs b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..64c7cb4 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary ListCanned { get; } + } +} diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs index 751fc45..958d0c5 100644 --- a/FishFactory/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace FishFactoryListImplement public List Components { get; set; } public List Orders { get; set; } public List Canneds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Canneds = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..c8bb272 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,107 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Shop.cs b/FishFactory/FishFactoryListImplement/Models/Shop.cs new file mode 100644 index 0000000..2d7700c --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Shop.cs @@ -0,0 +1,58 @@ +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; + +namespace FishFactoryListImplement.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 Dictionary ListCanned + { + get; + private set; + } = new(); + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ListCanned = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ListCanned = model.ListCanned; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + ListCanned = ListCanned, + DateOpening = DateOpening, + }; + } +} diff --git a/FishFactory/FishFactoryView/FormCanned.Designer.cs b/FishFactory/FishFactoryView/FormCanned.Designer.cs index 51a4f54..ff7c72a 100644 --- a/FishFactory/FishFactoryView/FormCanned.Designer.cs +++ b/FishFactory/FishFactoryView/FormCanned.Designer.cs @@ -1,220 +1,220 @@ namespace FishFactoryView { - partial class FormCanned - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormCanned + { + /// + /// 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() - { - label1 = new Label(); - label2 = new Label(); - textBoxName = new TextBox(); - textBoxPrice = new TextBox(); - ButtonCancel = new Button(); - ButtonSave = new Button(); - groupBox1 = new GroupBox(); - ButtonRef = new Button(); - ButtonDel = new Button(); - ButtonUpd = new Button(); - ButtonAdd = new Button(); - dataGridView = new DataGridView(); - Component = new DataGridViewTextBoxColumn(); - Cost = new DataGridViewTextBoxColumn(); - groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(29, 18); - label1.Name = "label1"; - label1.Size = new Size(80, 20); - label1.TabIndex = 0; - label1.Text = "Название:"; - // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(29, 54); - label2.Name = "label2"; - label2.Size = new Size(86, 20); - label2.TabIndex = 1; - label2.Text = "Стоимость:"; - // - // textBoxName - // - textBoxName.Location = new Point(128, 15); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(403, 27); - textBoxName.TabIndex = 2; - // - // textBoxPrice - // - textBoxPrice.Location = new Point(128, 51); - textBoxPrice.Name = "textBoxPrice"; - textBoxPrice.Size = new Size(201, 27); - textBoxPrice.TabIndex = 3; - // - // ButtonCancel - // - ButtonCancel.Location = new Point(726, 545); - ButtonCancel.Name = "ButtonCancel"; - ButtonCancel.Size = new Size(94, 29); - ButtonCancel.TabIndex = 4; - ButtonCancel.Text = "Отмена"; - ButtonCancel.UseVisualStyleBackColor = true; - ButtonCancel.Click += ButtonCancel_Click; - // - // ButtonSave - // - ButtonSave.Location = new Point(609, 545); - ButtonSave.Name = "ButtonSave"; - ButtonSave.Size = new Size(94, 29); - ButtonSave.TabIndex = 5; - ButtonSave.Text = "Сохранить"; - ButtonSave.UseVisualStyleBackColor = true; - ButtonSave.Click += ButtonSave_Click; - // - // groupBox1 - // - groupBox1.Controls.Add(ButtonRef); - groupBox1.Controls.Add(ButtonDel); - groupBox1.Controls.Add(ButtonUpd); - groupBox1.Controls.Add(ButtonAdd); - groupBox1.Controls.Add(dataGridView); - groupBox1.Location = new Point(12, 94); - groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(833, 445); - groupBox1.TabIndex = 6; - groupBox1.TabStop = false; - groupBox1.Text = "Компоненты"; - // - // ButtonRef - // - ButtonRef.Location = new Point(714, 230); - ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(94, 29); - ButtonRef.TabIndex = 4; - ButtonRef.Text = "Обновить"; - ButtonRef.UseVisualStyleBackColor = true; - ButtonRef.Click += ButtonRef_Click; - // - // ButtonDel - // - ButtonDel.Location = new Point(714, 171); - ButtonDel.Name = "ButtonDel"; - ButtonDel.Size = new Size(94, 29); - ButtonDel.TabIndex = 3; - ButtonDel.Text = "Удалить"; - ButtonDel.UseVisualStyleBackColor = true; - ButtonDel.Click += ButtonDel_Click; - // - // ButtonUpd - // - ButtonUpd.Location = new Point(714, 114); - ButtonUpd.Name = "ButtonUpd"; - ButtonUpd.Size = new Size(94, 29); - ButtonUpd.TabIndex = 2; - ButtonUpd.Text = "Изменить"; - ButtonUpd.UseVisualStyleBackColor = true; - ButtonUpd.Click += ButtonUpd_Click; - // - // ButtonAdd - // - ButtonAdd.Location = new Point(714, 57); - ButtonAdd.Name = "ButtonAdd"; - ButtonAdd.Size = new Size(94, 29); - ButtonAdd.TabIndex = 1; - ButtonAdd.Text = "Добавить"; - ButtonAdd.UseVisualStyleBackColor = true; - ButtonAdd.Click += ButtonAdd_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, Cost }); - dataGridView.Location = new Point(10, 24); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(662, 415); - dataGridView.TabIndex = 0; - // - // Component - // - Component.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; - Component.Frozen = true; - Component.HeaderText = "Компонент"; - Component.MinimumWidth = 6; - Component.Name = "Component"; - Component.Width = 484; - // - // Cost - // - Cost.HeaderText = "Количество"; - Cost.MinimumWidth = 6; - Cost.Name = "Cost"; - Cost.Width = 125; - // - // FormCanned - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(857, 586); - Controls.Add(groupBox1); - Controls.Add(ButtonSave); - Controls.Add(ButtonCancel); - Controls.Add(textBoxPrice); - Controls.Add(textBoxName); - Controls.Add(label2); - Controls.Add(label1); - Name = "FormCanned"; - Text = "Консерва"; - Load += FormCanned_Load; - groupBox1.ResumeLayout(false); - ((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() + { + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + ButtonCancel = new Button(); + ButtonSave = new Button(); + groupBox1 = new GroupBox(); + ButtonRef = new Button(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridView = new DataGridView(); + Component = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(29, 18); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(29, 54); + label2.Name = "label2"; + label2.Size = new Size(86, 20); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(128, 15); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(403, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(128, 51); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(201, 27); + textBoxPrice.TabIndex = 3; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(726, 545); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(94, 29); + ButtonCancel.TabIndex = 4; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(609, 545); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(94, 29); + ButtonSave.TabIndex = 5; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // groupBox1 + // + groupBox1.Controls.Add(ButtonRef); + groupBox1.Controls.Add(ButtonDel); + groupBox1.Controls.Add(ButtonUpd); + groupBox1.Controls.Add(ButtonAdd); + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(12, 94); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(833, 445); + groupBox1.TabIndex = 6; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // ButtonRef + // + ButtonRef.Location = new Point(714, 230); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(94, 29); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(714, 171); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(94, 29); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(714, 114); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(94, 29); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(714, 57); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(94, 29); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, Cost }); + dataGridView.Location = new Point(10, 24); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(662, 415); + dataGridView.TabIndex = 0; + // + // Component + // + Component.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; + Component.Frozen = true; + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + Component.Width = 484; + // + // Cost + // + Cost.HeaderText = "Количество"; + Cost.MinimumWidth = 6; + Cost.Name = "Cost"; + Cost.Width = 125; + // + // FormCanned + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(857, 586); + Controls.Add(groupBox1); + Controls.Add(ButtonSave); + Controls.Add(ButtonCancel); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormCanned"; + Text = "Консерва"; + Load += FormCanned_Load; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Label label1; - private Label label2; - private TextBox textBoxName; - private TextBox textBoxPrice; - private Button ButtonCancel; - private Button ButtonSave; - private GroupBox groupBox1; - private DataGridView dataGridView; - private Button ButtonRef; - private Button ButtonDel; - private Button ButtonUpd; - private Button ButtonAdd; - private DataGridViewTextBoxColumn Component; - private DataGridViewTextBoxColumn Cost; - } + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button ButtonCancel; + private Button ButtonSave; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Cost; + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanned.cs b/FishFactory/FishFactoryView/FormCanned.cs index f2b79e5..f5851cc 100644 --- a/FishFactory/FishFactoryView/FormCanned.cs +++ b/FishFactory/FishFactoryView/FormCanned.cs @@ -15,206 +15,206 @@ using System.Windows.Forms; namespace FishFactoryView { - public partial class FormCanned : Form - { - private readonly ILogger _logger; - private readonly ICannedLogic _logic; - private int? _id; - private Dictionary _CannedComponents; - public int Id { set { _id = value; } } - public FormCanned(ILogger logger, ICannedLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _CannedComponents = new Dictionary(); - } - private void FormCanned_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка изделия"); - try - { - var view = _logic.ReadElement(new CannedSearchModel { Id = _id.Value }); - if (view != null) - { - textBoxName.Text = view.CannedName; - textBoxPrice.Text = view.Price.ToString(); - _CannedComponents = view.CannedComponents ?? new - Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка компонент изделия"); - try - { - if (_CannedComponents != null) - { - dataGridView.Rows.Clear(); - foreach (var pc in _CannedComponents) - { - dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); - } - textBoxPrice.Text = CalcPrice().ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); - if (service is FormCannedComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - if (_CannedComponents.ContainsKey(form.Id)) - { - _CannedComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _CannedComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } - } - } - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); - if (service is FormCannedComponent form) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _CannedComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _CannedComponents[form.Id] = (form.ComponentModel, - form.Count); - LoadData(); - } - } - } - } - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - try - { - _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _CannedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - LoadData(); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxPrice.Text)) - { - MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } - if (_CannedComponents == null || _CannedComponents.Count == 0) - { - MessageBox.Show("Заполните компоненты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение изделия"); - try - { - var model = new CannedBindingModel - { - Id = _id ?? 0, - CannedName = textBoxName.Text, - Price = Convert.ToDouble(textBoxPrice.Text), - CannedComponents = _CannedComponents - }; - 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 double CalcPrice() - { - double price = 0; - foreach (var elem in _CannedComponents) - { - price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); - } - return Math.Round(price, 2); - } - } + public partial class FormCanned : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + private int? _id; + private Dictionary _CannedComponents; + public int Id { set { _id = value; } } + public FormCanned(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _CannedComponents = new Dictionary(); + } + private void FormCanned_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new CannedSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.CannedName; + textBoxPrice.Text = view.Price.ToString(); + _CannedComponents = view.CannedComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_CannedComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _CannedComponents) + { + dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); + if (service is FormCannedComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_CannedComponents.ContainsKey(form.Id)) + { + _CannedComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _CannedComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); + if (service is FormCannedComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _CannedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _CannedComponents[form.Id] = (form.ComponentModel, + form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _CannedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_CannedComponents == null || _CannedComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new CannedBindingModel + { + Id = _id ?? 0, + CannedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + CannedComponents = _CannedComponents + }; + 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 double CalcPrice() + { + double price = 0; + foreach (var elem in _CannedComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price, 2); + } + } } diff --git a/FishFactory/FishFactoryView/FormCanned.resx b/FishFactory/FishFactoryView/FormCanned.resx index ac743bd..5db4ced 100644 --- a/FishFactory/FishFactoryView/FormCanned.resx +++ b/FishFactory/FishFactoryView/FormCanned.resx @@ -123,4 +123,10 @@ True + + True + + + True + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanneds.Designer.cs b/FishFactory/FishFactoryView/FormCanneds.Designer.cs index e9e52b1..457ebf9 100644 --- a/FishFactory/FishFactoryView/FormCanneds.Designer.cs +++ b/FishFactory/FishFactoryView/FormCanneds.Designer.cs @@ -1,113 +1,114 @@ namespace FishFactoryView { - partial class FormCanneds - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormCanneds + { + /// + /// 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() - { - dataGridView = new DataGridView(); - AddButton = new Button(); - UpdateButton = new Button(); - DeleteButton = new Button(); - RefreshButton = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 0); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(634, 456); - dataGridView.TabIndex = 0; - // - // AddButton - // - AddButton.Location = new Point(675, 29); - AddButton.Name = "AddButton"; - AddButton.Size = new Size(94, 29); - AddButton.TabIndex = 1; - AddButton.Text = "Добавить"; - AddButton.UseVisualStyleBackColor = true; - AddButton.Click += AddButton_Click; - // - // UpdateButton - // - UpdateButton.Location = new Point(675, 89); - UpdateButton.Name = "UpdateButton"; - UpdateButton.Size = new Size(94, 29); - UpdateButton.TabIndex = 2; - UpdateButton.Text = "Изменить"; - UpdateButton.UseVisualStyleBackColor = true; - UpdateButton.Click += UpdateButton_Click; - // - // DeleteButton - // - DeleteButton.Location = new Point(675, 146); - DeleteButton.Name = "DeleteButton"; - DeleteButton.Size = new Size(94, 29); - DeleteButton.TabIndex = 3; - DeleteButton.Text = "Удалить"; - DeleteButton.UseVisualStyleBackColor = true; - DeleteButton.Click += DeleteButton_Click; - // - // RefreshButton - // - RefreshButton.Location = new Point(675, 208); - RefreshButton.Name = "RefreshButton"; - RefreshButton.Size = new Size(94, 29); - RefreshButton.TabIndex = 4; - RefreshButton.Text = "Обновить"; - RefreshButton.UseVisualStyleBackColor = true; - RefreshButton.Click += RefreshButton_Click; - // - // FormCanneds - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(805, 457); - Controls.Add(RefreshButton); - Controls.Add(DeleteButton); - Controls.Add(UpdateButton); - Controls.Add(AddButton); - Controls.Add(dataGridView); - Name = "FormCanneds"; - Text = "Консервы"; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + AddButton = new Button(); + UpdateButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(634, 456); + dataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(675, 29); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(94, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(675, 89); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(94, 29); + UpdateButton.TabIndex = 2; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(675, 146); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(94, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(675, 208); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(94, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // FormCanneds + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(805, 457); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(UpdateButton); + Controls.Add(AddButton); + Controls.Add(dataGridView); + Name = "FormCanneds"; + Text = "Консервы"; + Load += FormCanneds_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } - #endregion + #endregion - private DataGridView dataGridView; - private Button AddButton; - private Button UpdateButton; - private Button DeleteButton; - private Button RefreshButton; - } + private DataGridView dataGridView; + private Button AddButton; + private Button UpdateButton; + private Button DeleteButton; + private Button RefreshButton; + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanneds.cs b/FishFactory/FishFactoryView/FormCanneds.cs index b9f762b..964b4aa 100644 --- a/FishFactory/FishFactoryView/FormCanneds.cs +++ b/FishFactory/FishFactoryView/FormCanneds.cs @@ -13,101 +13,101 @@ using System.Windows.Forms; namespace FishFactoryView { - public partial class FormCanneds : Form - { - private readonly ILogger _logger; - private readonly ICannedLogic _logic; - public FormCanneds(ILogger logger, ICannedLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - private void FormCanneds_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["CannedComponents"].Visible = false; - } - _logger.LogInformation("Загрузка консервы"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки консервы"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void AddButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); - if (service is FormCanned form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + public partial class FormCanneds : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + public FormCanneds(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormCanneds_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["CannedComponents"].Visible = false; + } + _logger.LogInformation("Загрузка консервы"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); + if (service is FormCanned form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } - private void UpdateButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); - if (service is FormCanned form) - { - var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } + private void UpdateButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); + if (service is FormCanned form) + { + var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } - private void DeleteButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление консервы"); - try - { - if (!_logic.Delete(new CannedBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления консервы"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление консервы"); + try + { + if (!_logic.Delete(new CannedBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); - } - } + } + } } diff --git a/FishFactory/FishFactoryView/FormShop.Designer.cs b/FishFactory/FishFactoryView/FormShop.Designer.cs new file mode 100644 index 0000000..3124185 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.Designer.cs @@ -0,0 +1,184 @@ +namespace FishFactoryView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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(); + } + + #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; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShop.cs b/FishFactory/FishFactoryView/FormShop.cs new file mode 100644 index 0000000..294b0dc --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.cs @@ -0,0 +1,130 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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 FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopListCanned = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + 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); + } + } + } + + 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 buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormShop.resx b/FishFactory/FishFactoryView/FormShop.resx new file mode 100644 index 0000000..4d97cd9 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShopCanned.Designer.cs b/FishFactory/FishFactoryView/FormShopCanned.Designer.cs new file mode 100644 index 0000000..9c2a911 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.Designer.cs @@ -0,0 +1,143 @@ +namespace FishFactoryView +{ + partial class FormShopCanned + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxShop = new ComboBox(); + comboBoxCanned = new ComboBox(); + numericUpDownCount = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelShop = new Label(); + labelCanned = new Label(); + labelCount = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(205, 21); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(290, 28); + comboBoxShop.TabIndex = 0; + // + // comboBoxCanned + // + comboBoxCanned.FormattingEnabled = true; + comboBoxCanned.Location = new Point(205, 76); + comboBoxCanned.Name = "comboBoxCanned"; + comboBoxCanned.Size = new Size(290, 28); + comboBoxCanned.TabIndex = 1; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(205, 133); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(290, 27); + numericUpDownCount.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(266, 191); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(401, 191); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(29, 24); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(69, 20); + labelShop.TabIndex = 5; + labelShop.Text = "Магазин"; + // + // labelCanned + // + labelCanned.AutoSize = true; + labelCanned.Location = new Point(29, 79); + labelCanned.Name = "labelCanned"; + labelCanned.Size = new Size(76, 20); + labelCanned.TabIndex = 6; + labelCanned.Text = "Консерва"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(29, 135); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 7; + labelCount.Text = "Количество"; + // + // FormShopCanned + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(507, 232); + Controls.Add(labelCount); + Controls.Add(labelCanned); + Controls.Add(labelShop); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownCount); + Controls.Add(comboBoxCanned); + Controls.Add(comboBoxShop); + Name = "FormShopCanned"; + Text = "Поступление консервы на рыбный завод"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxCanned; + private NumericUpDown numericUpDownCount; + private Button buttonSave; + private Button buttonCancel; + private Label labelShop; + private Label labelCanned; + private Label labelCount; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShopCanned.cs b/FishFactory/FishFactoryView/FormShopCanned.cs new file mode 100644 index 0000000..5c108da --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.cs @@ -0,0 +1,99 @@ +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.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 FishFactoryView +{ + public partial class FormShopCanned : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly ICannedLogic _CannedLogic; + private readonly List? _listShops; + private readonly List? _listCanned; + + public FormShopCanned(ILogger logger, IShopLogic shopLogic, ICannedLogic CannedLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _CannedLogic = CannedLogic; + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + + _listCanned = CannedLogic.ReadList(null); + if (_listCanned != null) + { + comboBoxCanned.DisplayMember = "CannedName"; + comboBoxCanned.ValueMember = "Id"; + comboBoxCanned.DataSource = _listCanned; + comboBoxCanned.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCanned.SelectedValue == null) + { + MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление консервы в магазин"); + try + { + var сanned = _CannedLogic.ReadElement(new() + { + Id = (int)comboBoxCanned.SelectedValue + }); + if (сanned == null) + { + throw new Exception("Не найдено консерва. Дополнительная информация в логах."); + } + var resultOperation = _shopLogic.AddCannedInShop( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + canned: сanned, + count: (int)numericUpDownCount.Value + ); + if (!resultOperation) + { + 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/FormShopCanned.resx b/FishFactory/FishFactoryView/FormShopCanned.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.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/FormShops.Designer.cs b/FishFactory/FishFactoryView/FormShops.Designer.cs new file mode 100644 index 0000000..183892c --- /dev/null +++ b/FishFactory/FishFactoryView/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace FishFactoryView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(648, 426); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(698, 40); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(698, 101); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(120, 29); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(698, 160); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(120, 29); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(698, 219); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(120, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(846, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShops.cs b/FishFactory/FishFactoryView/FormShops.cs new file mode 100644 index 0000000..ead75a4 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShops.cs @@ -0,0 +1,111 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FishFactoryView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ListCanned"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormShops.resx b/FishFactory/FishFactoryView/FormShops.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/FishFactory/FishFactoryView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/MainForm.Designer.cs b/FishFactory/FishFactoryView/MainForm.Designer.cs index 09e9e2b..32e5b51 100644 --- a/FishFactory/FishFactoryView/MainForm.Designer.cs +++ b/FishFactory/FishFactoryView/MainForm.Designer.cs @@ -1,171 +1,193 @@ namespace FishFactoryView { - partial class MainForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class MainForm + { + /// + /// 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() - { - dataGridView = new DataGridView(); - button1 = new Button(); - button2 = new Button(); - button3 = new Button(); - button4 = new Button(); - button5 = new Button(); - menuStrip1 = new MenuStrip(); - toolStripMenuItem1 = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - консервыToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - menuStrip1.SuspendLayout(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(-1, 30); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(871, 457); - dataGridView.TabIndex = 1; - // - // button1 - // - button1.Location = new Point(885, 55); - button1.Name = "button1"; - button1.Size = new Size(179, 29); - button1.TabIndex = 2; - button1.Text = "Создать заказ"; - button1.UseVisualStyleBackColor = true; - button1.Click += ButtonCreateOrder_Click; - // - // button2 - // - button2.Location = new Point(885, 117); - button2.Name = "button2"; - button2.Size = new Size(179, 29); - button2.TabIndex = 3; - button2.Text = "Отдать на выполнение"; - button2.UseVisualStyleBackColor = true; - button2.Click += ButtonTakeOrderInWork_Click; - // - // button3 - // - button3.Location = new Point(885, 185); - button3.Name = "button3"; - button3.Size = new Size(179, 29); - button3.TabIndex = 4; - button3.Text = "Заказ готов"; - button3.UseVisualStyleBackColor = true; - button3.Click += ButtonOrderReady_Click; - // - // button4 - // - button4.Location = new Point(885, 254); - button4.Name = "button4"; - button4.Size = new Size(179, 29); - button4.TabIndex = 5; - button4.Text = "Заказ выдан"; - button4.UseVisualStyleBackColor = true; - button4.Click += ButtonIssuedOrder_Click; - // - // button5 - // - button5.Location = new Point(885, 321); - button5.Name = "button5"; - button5.Size = new Size(179, 29); - button5.TabIndex = 6; - button5.Text = "Обновить список"; - button5.UseVisualStyleBackColor = true; - button5.Click += ButtonRef_Click; - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1 }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1076, 28); - menuStrip1.TabIndex = 7; - menuStrip1.Text = "menuStrip1"; - // - // toolStripMenuItem1 - // - toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem }); - toolStripMenuItem1.Name = "toolStripMenuItem1"; - toolStripMenuItem1.Size = new Size(117, 24); - toolStripMenuItem1.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; - // - // консервыToolStripMenuItem - // - консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; - консервыToolStripMenuItem.Size = new Size(224, 26); - консервыToolStripMenuItem.Text = "Консервы"; - консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click; - // - // MainForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1076, 487); - Controls.Add(button5); - Controls.Add(button4); - Controls.Add(button3); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Name = "MainForm"; - Text = "Рыбный завод"; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + button5 = new Button(); + menuStrip1 = new MenuStrip(); + toolStripMenuItem1 = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + консервыToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + ButtonAddCannedInShop = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-1, 30); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(871, 457); + dataGridView.TabIndex = 1; + // + // button1 + // + button1.Location = new Point(885, 55); + button1.Name = "button1"; + button1.Size = new Size(179, 29); + button1.TabIndex = 2; + button1.Text = "Создать заказ"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonCreateOrder_Click; + // + // button2 + // + button2.Location = new Point(885, 117); + button2.Name = "button2"; + button2.Size = new Size(179, 29); + button2.TabIndex = 3; + button2.Text = "Отдать на выполнение"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonTakeOrderInWork_Click; + // + // button3 + // + button3.Location = new Point(885, 185); + button3.Name = "button3"; + button3.Size = new Size(179, 29); + button3.TabIndex = 4; + button3.Text = "Заказ готов"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonOrderReady_Click; + // + // button4 + // + button4.Location = new Point(885, 254); + button4.Name = "button4"; + button4.Size = new Size(179, 29); + button4.TabIndex = 5; + button4.Text = "Заказ выдан"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonIssuedOrder_Click; + // + // button5 + // + button5.Location = new Point(885, 321); + button5.Name = "button5"; + button5.Size = new Size(179, 29); + button5.TabIndex = 6; + button5.Text = "Обновить список"; + button5.UseVisualStyleBackColor = true; + button5.Click += ButtonRef_Click; + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1 }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1076, 28); + menuStrip1.TabIndex = 7; + menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItem1 + // + toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, ShopsToolStripMenuItem }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(117, 24); + toolStripMenuItem1.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; + // + // консервыToolStripMenuItem + // + консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; + консервыToolStripMenuItem.Size = new Size(224, 26); + консервыToolStripMenuItem.Text = "Консервы"; + консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click; + // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(224, 26); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // ButtonAddCannedInShop + // + ButtonAddCannedInShop.Location = new Point(885, 383); + ButtonAddCannedInShop.Name = "ButtonAddCannedInShop"; + ButtonAddCannedInShop.Size = new Size(179, 29); + ButtonAddCannedInShop.TabIndex = 8; + ButtonAddCannedInShop.Text = "Пополнить магазин"; + ButtonAddCannedInShop.UseVisualStyleBackColor = true; + ButtonAddCannedInShop.Click += ButtonAddCannedInShop_Click; + // + // MainForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1076, 487); + Controls.Add(ButtonAddCannedInShop); + Controls.Add(button5); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "MainForm"; + Text = "Рыбный завод"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } - #endregion - private DataGridView dataGridView; - private Button button1; - private Button button2; - private Button button3; - private Button button4; - private Button button5; - private MenuStrip menuStrip1; - private ToolStripMenuItem toolStripMenuItem1; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem консервыToolStripMenuItem; - } + #endregion + private DataGridView dataGridView; + private Button button1; + private Button button2; + private Button button3; + private Button button4; + private Button button5; + private MenuStrip menuStrip1; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem консервыToolStripMenuItem; + private ToolStripMenuItem ShopsToolStripMenuItem; + private Button ButtonAddCannedInShop; + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/MainForm.cs b/FishFactory/FishFactoryView/MainForm.cs index aeee666..440592c 100644 --- a/FishFactory/FishFactoryView/MainForm.cs +++ b/FishFactory/FishFactoryView/MainForm.cs @@ -6,157 +6,173 @@ using System.Windows.Forms; namespace FishFactoryView { - public partial class MainForm : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public MainForm(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["CannedId"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation(" "); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentToolStripMenuItem_Click(object sender, EventArgs - e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void CannedToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCanneds)); - if (service is FormCanneds 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(CreateBindingModel(id)); - 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(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + public partial class MainForm : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public MainForm(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["CannedId"].Visible = false; + dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentToolStripMenuItem_Click(object sender, EventArgs + e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void CannedToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCanneds)); + if (service is FormCanneds 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(CreateBindingModel(id)); + 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(CreateBindingModel(id)); + 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(CreateBindingModel(id)); - 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 OrderBindingModel CreateBindingModel(int id, bool isDone = false) - { - return new OrderBindingModel - { - Id = id, - CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].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()), - }; - } - } + } + } + } + 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(CreateBindingModel(id)); + 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 OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].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()), + }; + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ButtonAddCannedInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopCanned)); + if (service is FormShopCanned form) + { + form.ShowDialog(); + } + } + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 7cca7c6..9ef6319 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -37,9 +37,11 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +49,9 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file -- 2.25.1