From a934a1618b397a71134aac6a370bf0c11387209e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Fri, 2 Jun 2023 20:28:07 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B11=20=D1=83=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D1=91=D0=BD=D0=BD=D0=B0=D1=8F-=20=D0=B2?= =?UTF-8?q?=D0=BD=D0=B5=D0=B4=D1=80=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 111 ++++++++++++++++++ .../Models/Shop.cs | 54 +++++++++ 2 files changed, 165 insertions(+) create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Implements/ShopStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Models/Shop.cs diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/ShopStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..f0f17b9 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/ShopStorage.cs @@ -0,0 +1,111 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/Shop.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/Shop.cs new file mode 100644 index 0000000..735d1dc --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/Shop.cs @@ -0,0 +1,54 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string ShopAdress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopDishes { get; private set; } = new Dictionary(); + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + ShopAdress = model.ShopAdress, + OpeningDate = model.OpeningDate, + ShopDishes = model.ShopDishes + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + ShopAdress = model.ShopAdress; + OpeningDate = model.OpeningDate; + ShopDishes = model.ShopDishes; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + ShopAdress = ShopAdress, + ShopDishes = ShopDishes, + OpeningDate = OpeningDate + }; + } +} From 92bc862718d47ec280a609a53d1d5bbf5100866e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Fri, 2 Jun 2023 20:28:13 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B11=20=D1=83=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D1=91=D0=BD=D0=BD=D0=B0=D1=8F-=20=D0=B2?= =?UTF-8?q?=D0=BD=D0=B5=D0=B4=D1=80=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 159 ++++++++ .../BindingModels/ShopBindingModel.cs | 22 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 + .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 26 ++ .../Models/IShopModel.cs | 16 + .../DataListSingleton.cs | 4 +- .../FoodOrders/FormDelivery.Designer.cs | 143 +++++++ FoodOrders/FoodOrders/FormDelivery.cs | 106 ++++++ FoodOrders/FoodOrders/FormDelivery.resx | 120 ++++++ FoodOrders/FoodOrders/FormMain.Designer.cs | 352 +++++++++--------- FoodOrders/FoodOrders/FormMain.cs | 308 +++++++-------- FoodOrders/FoodOrders/FormShop.Designer.cs | 196 ++++++++++ FoodOrders/FoodOrders/FormShop.cs | 108 ++++++ FoodOrders/FoodOrders/FormShop.resx | 120 ++++++ FoodOrders/FoodOrders/FormShops.Designer.cs | 119 ++++++ FoodOrders/FoodOrders/FormShops.cs | 111 ++++++ FoodOrders/FoodOrders/FormShops.resx | 120 ++++++ FoodOrders/FoodOrders/Program.cs | 14 +- 20 files changed, 1782 insertions(+), 319 deletions(-) create mode 100644 FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BindingModels/ShopBindingModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/SearchModels/ShopSearchModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IShopStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersContracts/ViewModels/ShopViewModel.cs create mode 100644 FoodOrders/AbstractFoodOrdersDataModels/Models/IShopModel.cs create mode 100644 FoodOrders/FoodOrders/FormDelivery.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormDelivery.cs create mode 100644 FoodOrders/FoodOrders/FormDelivery.resx create mode 100644 FoodOrders/FoodOrders/FormShop.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormShop.cs create mode 100644 FoodOrders/FoodOrders/FormShop.resx create mode 100644 FoodOrders/FoodOrders/FormShops.Designer.cs create mode 100644 FoodOrders/FoodOrders/FormShops.cs create mode 100644 FoodOrders/FoodOrders/FormShops.resx diff --git a/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ShopLogic.cs b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..131893e --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,159 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersBusinessLogic.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)); + } + if (string.IsNullOrEmpty(model.ShopAdress)) + { + throw new ArgumentNullException("Нет адресса магазина", nameof(model.ShopAdress)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool DeliverDishToShop(ShopBindingModel shopModel, IDishModel dishModel, int count) + { + CheckModel(shopModel, false); + if (dishModel == null) + { + throw new ArgumentNullException(nameof(dishModel)); + } + if (count <= 0) + { + throw new ArgumentNullException("Количество изделий в поставке должно быть больше нуля!"); + } + var element = _shopStorage.GetElement(new ShopSearchModel + { + Id = shopModel.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + _logger.LogInformation("Delivery. ShopName:{ShopName}. Id:{Id}. DishName:{DishName}. Count:{count}", element.ShopName, element.Id, dishModel.DishName, count); + if (element.ShopDishes.TryGetValue(dishModel.Id, out var shopDish)) + { + element.ShopDishes[dishModel.Id] = (dishModel, shopDish.Item2 + count); + } + else + { + element.ShopDishes.Add(dishModel.Id, (dishModel, count)); + } + _shopStorage.Update(new ShopBindingModel + { + Id = element.Id, + ShopName = element.ShopName, + ShopAdress = element.ShopAdress, + OpeningDate = element.OpeningDate, + ShopDishes = element.ShopDishes + }); + return true; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ShopBindingModel.cs b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..c4c788c --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,22 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string ShopAdress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } + public Dictionary ShopDishes + { + get; + set; + } = new(); + } +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IShopLogic.cs b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..21ad11e --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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 DeliverDishToShop(ShopBindingModel shopModel, IDishModel dishModel, int count); + } +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ShopSearchModel.cs b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..9a48a69 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IShopStorage.cs b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..d4e2626 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.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/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ShopViewModel.cs b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..5875ad4 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,26 @@ +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = String.Empty; + [DisplayName("Адресс магазина")] + public string ShopAdress { get; set; } = String.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopDishes + { + get; + set; + } = new(); + } +} diff --git a/FoodOrders/AbstractFoodOrdersDataModels/Models/IShopModel.cs b/FoodOrders/AbstractFoodOrdersDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..dd95dfc --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string ShopAdress { get; } + DateTime OpeningDate { get; } + Dictionary ShopDishes { get; } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs index b4e1a01..3a7284a 100644 --- a/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs +++ b/FoodOrders/AbstractFoodOrdersListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AbstractFoodOrdersListImplement public List Components { get; set; } public List Orders { get; set; } public List Dishes { get; set; } - private DataListSingleton() + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Dishes = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/FoodOrders/FoodOrders/FormDelivery.Designer.cs b/FoodOrders/FoodOrders/FormDelivery.Designer.cs new file mode 100644 index 0000000..21dbc34 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDelivery.Designer.cs @@ -0,0 +1,143 @@ +namespace FoodOrders +{ + partial class FormDelivery + { + /// + /// 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() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxDish = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(254, 130); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(142, 130); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(94, 29); + this.buttonCreate.TabIndex = 14; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(129, 84); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(219, 27); + this.textBoxSum.TabIndex = 13; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(129, 6); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(219, 28); + this.comboBoxShop.TabIndex = 11; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 87); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(93, 20); + this.label3.TabIndex = 10; + this.label3.Text = "Количество:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 47); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(71, 20); + this.label2.TabIndex = 9; + this.label2.Text = "Изделие:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(72, 20); + this.label1.TabIndex = 8; + this.label1.Text = "Магазин:"; + // + // comboBoxDish + // + this.comboBoxDish.FormattingEnabled = true; + this.comboBoxDish.Location = new System.Drawing.Point(129, 44); + this.comboBoxDish.Name = "comboBoxDish"; + this.comboBoxDish.Size = new System.Drawing.Size(219, 28); + this.comboBoxDish.TabIndex = 16; + // + // FormDelivery + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(359, 173); + this.Controls.Add(this.comboBoxDish); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormDelivery"; + this.Text = "FormDelivery"; + this.Load += new System.EventHandler(this.FormDelivery_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonCreate; + private TextBox textBoxSum; + private ComboBox comboBoxShop; + private Label label3; + private Label label2; + private Label label1; + private ComboBox comboBoxDish; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormDelivery.cs b/FoodOrders/FoodOrders/FormDelivery.cs new file mode 100644 index 0000000..84bbab7 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDelivery.cs @@ -0,0 +1,106 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.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 FoodOrders +{ + public partial class FormDelivery : Form + { + private readonly ILogger _logger; + private readonly IDishLogic _logicD; + private readonly IShopLogic _logicS; + private List? _listDish; + private List? _listShop; + public FormDelivery(ILogger logger, IDishLogic logicD, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicS = logicS; + } + + private void FormDelivery_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка магазинов для поставки"); + _listShop = _logicS.ReadList(null); + if (_listShop != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShop; + comboBoxShop.SelectedItem = null; + } + _logger.LogInformation("Загрузка изделий для поставки"); + _listDish = _logicD.ReadList(null); + if (_listDish != null) + { + comboBoxDish.DisplayMember = "DishName"; + comboBoxDish.ValueMember = "Id"; + comboBoxDish.DataSource = _listDish; + comboBoxDish.SelectedItem = null; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDish.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (String.IsNullOrEmpty(textBoxSum.Text)) + { + MessageBox.Show("Заполните поле количество!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + ShopBindingModel shop = new ShopBindingModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }; + DishBindingModel dish = new DishBindingModel + { + Id = Convert.ToInt32(comboBoxDish.SelectedValue), + DishName = comboBoxDish.Text + }; + int count = Convert.ToInt32(textBoxSum.Text); + bool operationResult = _logicS.DeliverDishToShop(shop, dish, count); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки!"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/FoodOrders/FoodOrders/FormDelivery.resx b/FoodOrders/FoodOrders/FormDelivery.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FoodOrders/FoodOrders/FormDelivery.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/FoodOrders/FoodOrders/FormMain.Designer.cs b/FoodOrders/FoodOrders/FormMain.Designer.cs index bf50541..5b056b6 100644 --- a/FoodOrders/FoodOrders/FormMain.Designer.cs +++ b/FoodOrders/FoodOrders/FormMain.Designer.cs @@ -1,177 +1,191 @@ namespace FoodOrders { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.БлюдаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip - // - this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(1104, 28); - this.menuStrip.TabIndex = 0; - this.menuStrip.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.КомпонентыToolStripMenuItem, - this.БлюдаToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // КомпонентыToolStripMenuItem - // - this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); - this.КомпонентыToolStripMenuItem.Text = "Компоненты"; - this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); - // - // БлюдаToolStripMenuItem - // - this.БлюдаToolStripMenuItem.Name = "БлюдаToolStripMenuItem"; - this.БлюдаToolStripMenuItem.Size = new System.Drawing.Size(182, 26); - this.БлюдаToolStripMenuItem.Text = "Блюда"; - this.БлюдаToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 40); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(798, 408); - this.dataGridView.TabIndex = 1; - // - // ButtonCreateOrder - // - this.ButtonCreateOrder.Location = new System.Drawing.Point(831, 82); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(241, 29); - this.ButtonCreateOrder.TabIndex = 2; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // ButtonTakeOrderInWork - // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(831, 141); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(241, 29); - this.ButtonTakeOrderInWork.TabIndex = 3; - this.ButtonTakeOrderInWork.Text = "Отдать заказ на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // ButtonOrderReady - // - this.ButtonOrderReady.Location = new System.Drawing.Point(831, 202); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(241, 29); - this.ButtonOrderReady.TabIndex = 4; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // ButtonIssuedOrder - // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(831, 264); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(241, 29); - this.ButtonIssuedOrder.TabIndex = 5; - this.ButtonIssuedOrder.Text = "Заказ выдан"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // ButtonRef - // - this.ButtonRef.Location = new System.Drawing.Point(831, 331); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(241, 29); - this.ButtonRef.TabIndex = 6; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1104, 470); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "Доставка еды"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip.ResumeLayout(false); - this.menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + БлюдаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ButtonCreateOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + ButtonOrderReady = new Button(); + ButtonIssuedOrder = new Button(); + ButtonRef = new Button(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1104, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, БлюдаToolStripMenuItem, магазиныToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(224, 26); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // БлюдаToolStripMenuItem + // + БлюдаToolStripMenuItem.Name = "БлюдаToolStripMenuItem"; + БлюдаToolStripMenuItem.Size = new Size(224, 26); + БлюдаToolStripMenuItem.Text = "Блюда"; + БлюдаToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 40); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(798, 408); + dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + ButtonCreateOrder.Location = new Point(831, 82); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(241, 29); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; + // + // ButtonTakeOrderInWork + // + ButtonTakeOrderInWork.Location = new Point(831, 141); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(241, 29); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать заказ на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // ButtonOrderReady + // + ButtonOrderReady.Location = new Point(831, 202); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(241, 29); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Location = new Point(831, 264); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(241, 29); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // ButtonRef + // + ButtonRef.Location = new Point(831, 331); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(241, 29); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1104, 470); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Доставка еды"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - } + #endregion - #endregion - - private MenuStrip menuStrip; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem КомпонентыToolStripMenuItem; - private ToolStripMenuItem БлюдаToolStripMenuItem; - private DataGridView dataGridView; - private Button ButtonCreateOrder; - private Button ButtonTakeOrderInWork; - private Button ButtonOrderReady; - private Button ButtonIssuedOrder; - private Button ButtonRef; - } + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem БлюдаToolStripMenuItem; + private DataGridView dataGridView; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + } } \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormMain.cs b/FoodOrders/FoodOrders/FormMain.cs index b13b4df..8208a68 100644 --- a/FoodOrders/FoodOrders/FormMain.cs +++ b/FoodOrders/FoodOrders/FormMain.cs @@ -14,149 +14,167 @@ using System.Windows.Forms; namespace FoodOrders { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["DishId"].Visible = false; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormDishes)); - if (service is FormDishes form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new - OrderBindingModel - { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(new - OrderBindingModel - { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new - OrderBindingModel - { Id = id }); - 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(); - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["DishId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormDishes)); + if (service is FormDishes form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDelivery)); + if (service is FormDelivery form) + { + form.ShowDialog(); + } + } + } } diff --git a/FoodOrders/FoodOrders/FormShop.Designer.cs b/FoodOrders/FoodOrders/FormShop.Designer.cs new file mode 100644 index 0000000..73d4d36 --- /dev/null +++ b/FoodOrders/FoodOrders/FormShop.Designer.cs @@ -0,0 +1,196 @@ +namespace FoodOrders +{ + 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() + { + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.openingDateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.label2 = new System.Windows.Forms.Label(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.DishId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DishName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(120, 38); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(350, 27); + this.textBoxAdress.TabIndex = 11; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(120, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(350, 27); + this.textBoxName.TabIndex = 10; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(60, 41); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(54, 20); + this.label1.TabIndex = 9; + this.label1.Text = "Адрес:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(34, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 8; + this.labelName.Text = "Название:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(376, 276); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(276, 276); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // openingDateTimePicker + // + this.openingDateTimePicker.Location = new System.Drawing.Point(120, 72); + this.openingDateTimePicker.Name = "openingDateTimePicker"; + this.openingDateTimePicker.Size = new System.Drawing.Size(350, 27); + this.openingDateTimePicker.TabIndex = 12; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(1, 72); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(113, 20); + this.label2.TabIndex = 13; + this.label2.Text = "Дата открытия:"; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.DishId, + this.DishName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(120, 105); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 165); + this.dataGridView.TabIndex = 14; + // + // DishId + // + this.DishId.HeaderText = "Id"; + this.DishId.MinimumWidth = 6; + this.DishId.Name = "DishId"; + this.DishId.ReadOnly = true; + this.DishId.Visible = false; + this.DishId.Width = 125; + // + // DishName + // + this.DishName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.DishName.HeaderText = "Название изделия"; + this.DishName.MinimumWidth = 6; + this.DishName.Name = "DishName"; + this.DishName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + this.Count.Width = 125; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(478, 317); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.label2); + this.Controls.Add(this.openingDateTimePicker); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label1); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxAdress; + private TextBox textBoxName; + private Label label1; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + private DateTimePicker openingDateTimePicker; + private Label label2; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn DishId; + private DataGridViewTextBoxColumn DishName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormShop.cs b/FoodOrders/FoodOrders/FormShop.cs new file mode 100644 index 0000000..988d9c3 --- /dev/null +++ b/FoodOrders/FoodOrders/FormShop.cs @@ -0,0 +1,108 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.BusinessLogicsContracts; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersDataModels.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 FoodOrders +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private Dictionary _shopDishes = new Dictionary(); + + private int? _id; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logic = logic; + _logger = logger; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + ShopAdress = textBoxAdress.Text, + OpeningDate = openingDateTimePicker.Value.Date, + ShopDishes = _shopDishes + }; + 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 FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение магазина"); + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.ShopAdress; + openingDateTimePicker.Value = view.OpeningDate; + _shopDishes = view.ShopDishes; + foreach (var pc in view.ShopDishes) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.DishName, pc.Value.Item2 }); + } + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка заказов"); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FoodOrders/FoodOrders/FormShop.resx b/FoodOrders/FoodOrders/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FoodOrders/FoodOrders/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormShops.Designer.cs b/FoodOrders/FoodOrders/FormShops.Designer.cs new file mode 100644 index 0000000..557d3a7 --- /dev/null +++ b/FoodOrders/FoodOrders/FormShops.Designer.cs @@ -0,0 +1,119 @@ +namespace FoodOrders +{ + 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() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(524, 185); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(524, 127); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(524, 70); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(524, 13); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(2, 1); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.TabIndex = 5; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(626, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FoodOrders/FoodOrders/FormShops.cs b/FoodOrders/FoodOrders/FormShops.cs new file mode 100644 index 0000000..bead1c0 --- /dev/null +++ b/FoodOrders/FoodOrders/FormShops.cs @@ -0,0 +1,111 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.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 FoodOrders +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopDishes"].Visible = false; + } + _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/FoodOrders/FoodOrders/FormShops.resx b/FoodOrders/FoodOrders/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FoodOrders/FoodOrders/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/FoodOrders/FoodOrders/Program.cs b/FoodOrders/FoodOrders/Program.cs index 6a119c7..51fefcc 100644 --- a/FoodOrders/FoodOrders/Program.cs +++ b/FoodOrders/FoodOrders/Program.cs @@ -38,17 +38,23 @@ namespace FoodOrders services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file