From db19d63b3772f06b3f2fd399455ed4a2008378ad Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 13 Feb 2023 20:45:17 +0400 Subject: [PATCH 1/7] ShopLogic --- .../BusinessLogics/ShopLogic.cs | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..f60e210 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,149 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBusinessLogic +{ + 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?.Name, 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.Name, 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); + //model.ListSushi = new(); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model, false); + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); + } + //model.ListSushi = new(); + 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.Name)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + model.Name, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id && element.Name == model.Name) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого суши должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", + model.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddSushiInShop element not found"); + return false; + } + _logger.LogInformation("AddSushiInShop find. Id:{Id}", element.Id); + + if (element.ListSushi.TryGetValue(sushi.Id, out var pair)) + { + pair.Item2 += count; + _logger.LogInformation("AddSushiInShop. Has been added {count} {sushi} in {ShopName}", + count, sushi.SushiName, element.Name); + } + else + { + element.ListSushi[sushi.Id] = (sushi, count); + _logger.LogInformation( + "AddSushiInShop. Has been added {count} new Sushi {sushi} in {ShopName}", + count, sushi.SushiName, element.Name); + } + return true; + } + } +} -- 2.25.1 From 9353ee3b063d364ff2acfa85037d037f54cd472f Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 13 Feb 2023 23:13:13 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBar/FormAddSushiInShop.Designer.cs | 151 ++++++++++++++ SushiBar/SushiBar/FormAddSushiInShop.cs | 90 +++++++++ SushiBar/SushiBar/FormAddSushiInShop.resx | 60 ++++++ SushiBar/SushiBar/FormIngredients.cs | 1 - SushiBar/SushiBar/FormListSushi.cs | 1 - SushiBar/SushiBar/FormMain.Designer.cs | 36 +++- SushiBar/SushiBar/FormMain.cs | 18 +- SushiBar/SushiBar/FormShop.Designer.cs | 188 ++++++++++++++++++ SushiBar/SushiBar/FormShop.cs | 141 +++++++++++++ SushiBar/SushiBar/FormShop.resx | 69 +++++++ SushiBar/SushiBar/FormShops.Designer.cs | 122 ++++++++++++ SushiBar/SushiBar/FormShops.cs | 102 ++++++++++ SushiBar/SushiBar/FormShops.resx | 60 ++++++ SushiBar/SushiBar/FormSushi.cs | 1 - SushiBar/SushiBar/Program.cs | 6 + .../BusinessLogics/ShopLogic.cs | 57 +++--- .../BindingModels/ShopBindingModel.cs | 20 ++ .../BusinessLogicsContracts/IShopLogic.cs | 17 ++ .../SearchModels/ShopSearchModel.cs | 8 + .../StoragesContracts/IShopStorage.cs | 16 ++ .../ViewModels/ShopViewModel.cs | 24 +++ .../SushiBarDataModels/Models/IShopModel.cs | 10 + .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 108 ++++++++++ SushiBar/SushiBarListImplement/Models/Shop.cs | 58 ++++++ 25 files changed, 1329 insertions(+), 37 deletions(-) create mode 100644 SushiBar/SushiBar/FormAddSushiInShop.Designer.cs create mode 100644 SushiBar/SushiBar/FormAddSushiInShop.cs create mode 100644 SushiBar/SushiBar/FormAddSushiInShop.resx create mode 100644 SushiBar/SushiBar/FormShop.Designer.cs create mode 100644 SushiBar/SushiBar/FormShop.cs create mode 100644 SushiBar/SushiBar/FormShop.resx create mode 100644 SushiBar/SushiBar/FormShops.Designer.cs create mode 100644 SushiBar/SushiBar/FormShops.cs create mode 100644 SushiBar/SushiBar/FormShops.resx create mode 100644 SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IShopModel.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/ShopStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Shop.cs diff --git a/SushiBar/SushiBar/FormAddSushiInShop.Designer.cs b/SushiBar/SushiBar/FormAddSushiInShop.Designer.cs new file mode 100644 index 0000000..89627cc --- /dev/null +++ b/SushiBar/SushiBar/FormAddSushiInShop.Designer.cs @@ -0,0 +1,151 @@ +namespace SushiBarView +{ + partial class FormAddSushiInShop + { + /// + /// 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.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSushi = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(87, 62); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(344, 23); + this.numericUpDownCount.TabIndex = 13; + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(86, 35); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(345, 23); + this.comboBoxSushi.TabIndex = 12; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(9, 64); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 11; + this.labelCount.Text = "Количество"; + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(41, 38); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(39, 15); + this.labelSushi.TabIndex = 10; + this.labelSushi.Text = "Суши"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(86, 8); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(345, 23); + this.comboBoxShop.TabIndex = 9; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(26, 11); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 8; + this.labelShop.Text = "Магазин"; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(356, 94); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(275, 94); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormAddSushiInShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(443, 129); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelSushi); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormAddSushiInShop"; + this.Text = "Поступление суши в суши-бар"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private NumericUpDown numericUpDownCount; + private ComboBox comboBoxSushi; + private Label labelCount; + private Label labelSushi; + private ComboBox comboBoxShop; + private Label labelShop; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormAddSushiInShop.cs b/SushiBar/SushiBar/FormAddSushiInShop.cs new file mode 100644 index 0000000..32ce4c7 --- /dev/null +++ b/SushiBar/SushiBar/FormAddSushiInShop.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarView +{ + public partial class FormAddSushiInShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly ISushiLogic _sushiLogic; + private readonly List? _listShops; + private readonly List? _listSushi; + + public FormAddSushiInShop(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _sushiLogic = sushiLogic; + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + + _listSushi = sushiLogic.ReadList(null); + if (_listSushi != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _listSushi; + comboBoxSushi.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление суши в магазин"); + try + { + var sushi = _sushiLogic.ReadElement(new() + { + Id = (int)comboBoxSushi.SelectedValue + }); + if (sushi == null) + { + throw new Exception("Не найдено суши. Дополнительная информация в логах."); + } + var resultOperation = _shopLogic.AddSushiInShop( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + sushi: sushi, + 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/SushiBar/SushiBar/FormAddSushiInShop.resx b/SushiBar/SushiBar/FormAddSushiInShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormAddSushiInShop.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 73d7cfa..781205f 100644 --- a/SushiBar/SushiBar/FormIngredients.cs +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index 333b51c..d20376b 100644 --- a/SushiBar/SushiBar/FormListSushi.cs +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index cad392a..c1af807 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -32,12 +32,14 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAddSushiInShop = new System.Windows.Forms.Button(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +58,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ингредиентыToolStripMenuItem, - this.сушиToolStripMenuItem}); + this.сушиToolStripMenuItem, + this.shopsToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -75,9 +78,16 @@ this.сушиToolStripMenuItem.Text = "Суши"; this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(780, 314); + this.buttonUpdate.Location = new System.Drawing.Point(781, 299); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(170, 58); @@ -88,7 +98,7 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(780, 252); + this.buttonSetToFinish.Location = new System.Drawing.Point(781, 237); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); @@ -99,7 +109,7 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(780, 190); + this.buttonSetToDone.Location = new System.Drawing.Point(781, 175); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); @@ -110,7 +120,7 @@ // // buttonSetToWork // - this.buttonSetToWork.Location = new System.Drawing.Point(780, 128); + this.buttonSetToWork.Location = new System.Drawing.Point(781, 113); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); @@ -121,7 +131,7 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(780, 66); + this.buttonCreateOrder.Location = new System.Drawing.Point(781, 51); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); @@ -142,11 +152,23 @@ this.dataGridView.Size = new System.Drawing.Size(755, 426); this.dataGridView.TabIndex = 7; // + // buttonAddSushiInShop + // + this.buttonAddSushiInShop.Location = new System.Drawing.Point(781, 361); + this.buttonAddSushiInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAddSushiInShop.Name = "buttonAddSushiInShop"; + this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 58); + this.buttonAddSushiInShop.TabIndex = 13; + this.buttonAddSushiInShop.Text = "Добавить суши в магазин"; + this.buttonAddSushiInShop.UseVisualStyleBackColor = true; + this.buttonAddSushiInShop.Click += new System.EventHandler(this.ButtonAddSushiInShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(975, 450); + this.Controls.Add(this.buttonAddSushiInShop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); this.Controls.Add(this.buttonSetToDone); @@ -178,5 +200,7 @@ private Button buttonSetToWork; private Button buttonCreateOrder; private DataGridView dataGridView; + private ToolStripMenuItem shopsToolStripMenuItem; + private Button buttonAddSushiInShop; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 4ea5668..d79cbd6 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarDataModels.Enums; @@ -159,5 +158,22 @@ namespace SushiBarView { LoadData(); } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void ButtonAddSushiInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddSushiInShop)); + if (service is FormAddSushiInShop form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShop.Designer.cs b/SushiBar/SushiBar/FormShop.Designer.cs new file mode 100644 index 0000000..ff78362 --- /dev/null +++ b/SushiBar/SushiBar/FormShop.Designer.cs @@ -0,0 +1,188 @@ +namespace SushiBarView +{ + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxDateOpening = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelTime = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(364, 303); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.TabIndex = 17; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(490, 302); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.TabIndex = 16; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // textBoxDateOpening + // + this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Name = "textBoxDateOpening"; + this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); + this.textBoxDateOpening.TabIndex = 15; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.TabIndex = 14; + // + // labelTime + // + this.labelTime.AutoSize = true; + this.labelTime.Location = new System.Drawing.Point(386, 9); + this.labelTime.Name = "labelTime"; + this.labelTime.Size = new System.Drawing.Size(97, 15); + this.labelTime.TabIndex = 13; + this.labelTime.Text = "Дата открытия"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(159, 9); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 12; + this.labelAddress.Text = "Адрес"; + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.SushiName, + this.Price, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 56); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(581, 240); + this.dataGridView.TabIndex = 11; + // + // SushiName + // + this.SushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.SushiName.HeaderText = "Суши"; + this.SushiName.Name = "SushiName"; + // + // Price + // + this.Price.HeaderText = "Цена"; + this.Price.Name = "Price"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(12, 27); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(141, 23); + this.comboBoxShop.TabIndex = 10; + this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 9); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 9; + this.labelShop.Text = "Магазин"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(605, 337); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxDateOpening); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelTime); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Click += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxDateOpening; + private TextBox textBoxAddress; + private Label labelTime; + private Label labelAddress; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn SushiName; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Count; + private ComboBox comboBoxShop; + private Label labelShop; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShop.cs b/SushiBar/SushiBar/FormShop.cs new file mode 100644 index 0000000..bfb81bf --- /dev/null +++ b/SushiBar/SushiBar/FormShop.cs @@ -0,0 +1,141 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarView +{ + public partial class FormShop : Form + { + private readonly List? _listShops; + private readonly IShopLogic _logic; + private readonly ILogger _logger; + public int Id { get; set; } + + private IShopModel? GetShop(int id) + { + if (_listShops == null) + { + return null; + } + foreach (var elem in _listShops) + { + if (elem.Id == id) + { + return elem; + } + } + return null; + } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _listShops = logic.ReadList(null); + _logic = logic; + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + } + + private void LoadData(bool extendDate = true) + { + try + { + var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); + if (model != null) + { + comboBoxShop.Text = model.ShopName; + textBoxAddress.Text = model.Address; + textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + dataGridView.Rows.Clear(); + foreach (var el in model.ListSushi.Values) + { + dataGridView.Rows.Add(new object[] { el.Item1.SushiName, el.Item1.Price, el.Item2 }); + } + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) + { + LoadData(false); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(comboBoxShop.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение суши"); + try + { + DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); + ShopBindingModel model = new() + { + ShopName = comboBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTime + }; + var vmodel = GetShop(Id); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _logic.Create(model); + } + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/FormShop.resx b/SushiBar/SushiBar/FormShop.resx new file mode 100644 index 0000000..a34aa69 --- /dev/null +++ b/SushiBar/SushiBar/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SushiBar/SushiBar/FormShops.Designer.cs b/SushiBar/SushiBar/FormShops.Designer.cs new file mode 100644 index 0000000..d755d2d --- /dev/null +++ b/SushiBar/SushiBar/FormShops.Designer.cs @@ -0,0 +1,122 @@ +namespace SushiBarView +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 333); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 175); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 149); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 123); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 97); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(566, 333); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShops.cs b/SushiBar/SushiBar/FormShops.cs new file mode 100644 index 0000000..e4dbc52 --- /dev/null +++ b/SushiBar/SushiBar/FormShops.cs @@ -0,0 +1,102 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + 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["ListSushi"].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/SushiBar/SushiBar/FormShops.resx b/SushiBar/SushiBar/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 67496b1..515011f 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index f38dd3a..8615648 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -5,6 +5,7 @@ using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarListImplement.Implements; +using SushiBusinessLogic; namespace SushiBarView { @@ -39,9 +40,11 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -49,6 +52,9 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index f60e210..bb6147e 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -19,15 +19,16 @@ namespace SushiBusinessLogic } public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. ShopName: {ShopName}. Id:{ Id} ", - model?.Name, model?.Id); - var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(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); + _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } public ShopViewModel? ReadElement(ShopSearchModel model) @@ -36,21 +37,20 @@ namespace SushiBusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", - model.Name, model.Id); + _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); + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); return element; } public bool Create(ShopBindingModel model) { CheckModel(model); - //model.ListSushi = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -60,12 +60,7 @@ namespace SushiBusinessLogic } public bool Update(ShopBindingModel model) { - CheckModel(model, false); - if (string.IsNullOrEmpty(model.Name)) - { - throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); - } - //model.ListSushi = new(); + CheckModel(model); if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -76,7 +71,7 @@ namespace SushiBusinessLogic public bool Delete(ShopBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); + _logger.LogInformation("Delete. Id: {Id}", model.Id); if (_shopStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); @@ -94,17 +89,17 @@ namespace SushiBusinessLogic { return; } - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { - throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); } _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", - model.Name, model.Address, model.Id); + model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - Name = model.Name + ShopName = model.ShopName }); - if (element != null && element.Id != model.Id && element.Name == model.Name) + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } @@ -118,10 +113,10 @@ namespace SushiBusinessLogic } if (count <= 0) { - throw new ArgumentException("Количество добавляемого суши должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество суши должно быть больше 0", nameof(count)); } _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", - model.Name, model.Id); + model.ShopName, model.Id); var element = _shopStorage.GetElement(model); if (element == null) { @@ -132,17 +127,25 @@ namespace SushiBusinessLogic if (element.ListSushi.TryGetValue(sushi.Id, out var pair)) { - pair.Item2 += count; - _logger.LogInformation("AddSushiInShop. Has been added {count} {sushi} in {ShopName}", - count, sushi.SushiName, element.Name); + element.ListSushi[sushi.Id] = (sushi, count + pair.Item2); + _logger.LogInformation( + "AddSushiInShop. Added {count} {sushi} to '{ShopName}' shop", + count, sushi.SushiName, element.ShopName); } else { element.ListSushi[sushi.Id] = (sushi, count); _logger.LogInformation( - "AddSushiInShop. Has been added {count} new Sushi {sushi} in {ShopName}", - count, sushi.SushiName, element.Name); + "AddSushiInShop. Added {count} new sushi {sushi} to '{ShopName}' shop", + count, sushi.SushiName, element.ShopName); } + _shopStorage.Update(new() { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + DateOpening = element.DateOpening, + ListSushi = element.ListSushi + }); return true; } } diff --git a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..006a3eb --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,20 @@ +using SushiBarDataModels.Models; + +namespace SushiBarContracts.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 ListSushi + { + get; + set; + } = new(); + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..f1f455b --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.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 AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count); + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..5438e15 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..8ebaaf5 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..f53c548 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,24 @@ +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.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 ListSushi + { + get; + set; + } = new(); + } +} diff --git a/SushiBar/SushiBarDataModels/Models/IShopModel.cs b/SushiBar/SushiBarDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..2c7c569 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IShopModel.cs @@ -0,0 +1,10 @@ +namespace SushiBarDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary ListSushi { get; } + } +} diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index f344d8f..04beee0 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace SushiBarListImplement public List Ingredients { get; set; } public List Orders { get; set; } public List ListSushi { get; set; } + public List Shops { get; set; } private DataListSingleton() { Ingredients = new List(); Orders = new List(); ListSushi = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..50017b7 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs @@ -0,0 +1,108 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Shop.cs b/SushiBar/SushiBarListImplement/Models/Shop.cs new file mode 100644 index 0000000..aeaf3de --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Shop.cs @@ -0,0 +1,58 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class Shop : IShopModel + { + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ListSushi + { + get; + private set; + } = new(); + + public int Id { get; private set; } + + 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, + ListSushi = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ListSushi = model.ListSushi; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + ListSushi = ListSushi, + DateOpening = DateOpening, + }; + } +} -- 2.25.1 From 65d38414ee053bd739faed8e3b3aff270356fdbb Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 13 Feb 2023 23:38:41 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20FormShop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormShop.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/SushiBar/SushiBar/FormShop.cs b/SushiBar/SushiBar/FormShop.cs index bfb81bf..671f7b8 100644 --- a/SushiBar/SushiBar/FormShop.cs +++ b/SushiBar/SushiBar/FormShop.cs @@ -43,7 +43,10 @@ namespace SushiBarView comboBoxShop.SelectedItem = null; } } - + private void FormShop_Load(object sender, EventArgs e) + { + LoadData(); + } private void LoadData(bool extendDate = true) { try @@ -66,7 +69,7 @@ namespace SushiBarView { _logger.LogError(ex, "Ошибка загрузки магазинов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBoxIcon.Error); } } @@ -79,14 +82,14 @@ namespace SushiBarView { if (string.IsNullOrEmpty(comboBoxShop.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxAddress.Text)) { MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение суши"); @@ -116,7 +119,7 @@ namespace SushiBarView throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } @@ -132,10 +135,5 @@ namespace SushiBarView DialogResult = DialogResult.Cancel; Close(); } - - private void FormShop_Load(object sender, EventArgs e) - { - LoadData(); - } } } -- 2.25.1 From a4a2c34044e19c305c5b202fdcbf013891995a0f Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 00:26:18 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20FormShop.?= =?UTF-8?q?=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BD=D0=B5=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormShop.Designer.cs | 96 ++++++------- SushiBar/SushiBar/FormShop.cs | 130 ++++++++---------- SushiBar/SushiBar/FormShop.resx | 6 +- .../Implements/ShopStorage.cs | 70 +++++----- SushiBar/SushiBarListImplement/Models/Shop.cs | 7 +- 5 files changed, 139 insertions(+), 170 deletions(-) diff --git a/SushiBar/SushiBar/FormShop.Designer.cs b/SushiBar/SushiBar/FormShop.Designer.cs index ff78362..71971de 100644 --- a/SushiBar/SushiBar/FormShop.Designer.cs +++ b/SushiBar/SushiBar/FormShop.Designer.cs @@ -30,16 +30,16 @@ { this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); - this.textBoxDateOpening = new System.Windows.Forms.TextBox(); this.textBoxAddress = new System.Windows.Forms.TextBox(); this.labelTime = new System.Windows.Forms.Label(); this.labelAddress = new System.Windows.Forms.Label(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.comboBoxShop = new System.Windows.Forms.ComboBox(); this.labelShop = new System.Windows.Forms.Label(); + this.textBoxShop = new System.Windows.Forms.TextBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnSushiName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -65,13 +65,6 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // - // textBoxDateOpening - // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); - this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); - this.textBoxDateOpening.TabIndex = 15; - // // textBoxAddress // this.textBoxAddress.Location = new System.Drawing.Point(159, 27); @@ -84,7 +77,7 @@ this.labelTime.AutoSize = true; this.labelTime.Location = new System.Drawing.Point(386, 9); this.labelTime.Name = "labelTime"; - this.labelTime.Size = new System.Drawing.Size(97, 15); + this.labelTime.Size = new System.Drawing.Size(87, 15); this.labelTime.TabIndex = 13; this.labelTime.Text = "Дата открытия"; // @@ -104,40 +97,15 @@ | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.SushiName, - this.Price, - this.Count}); + this.ColumnID, + this.ColumnSushiName, + this.ColumnCount}); this.dataGridView.Location = new System.Drawing.Point(12, 56); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; this.dataGridView.Size = new System.Drawing.Size(581, 240); this.dataGridView.TabIndex = 11; // - // SushiName - // - this.SushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.SushiName.HeaderText = "Суши"; - this.SushiName.Name = "SushiName"; - // - // Price - // - this.Price.HeaderText = "Цена"; - this.Price.Name = "Price"; - // - // Count - // - this.Count.HeaderText = "Количество"; - this.Count.Name = "Count"; - // - // comboBoxShop - // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(12, 27); - this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(141, 23); - this.comboBoxShop.TabIndex = 10; - this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); - // // labelShop // this.labelShop.AutoSize = true; @@ -147,22 +115,54 @@ this.labelShop.TabIndex = 9; this.labelShop.Text = "Магазин"; // + // textBoxShop + // + this.textBoxShop.Location = new System.Drawing.Point(12, 27); + this.textBoxShop.Name = "textBoxShop"; + this.textBoxShop.Size = new System.Drawing.Size(141, 23); + this.textBoxShop.TabIndex = 18; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(386, 27); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(207, 23); + this.dateTimePicker.TabIndex = 19; + // + // ColumnID + // + this.ColumnID.HeaderText = "ID"; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + // + // ColumnSushiName + // + this.ColumnSushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnSushiName.HeaderText = "Суши"; + this.ColumnSushiName.Name = "ColumnSushiName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(605, 337); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxShop); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxDateOpening); this.Controls.Add(this.textBoxAddress); this.Controls.Add(this.labelTime); this.Controls.Add(this.labelAddress); this.Controls.Add(this.dataGridView); - this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.labelShop); this.Name = "FormShop"; this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); this.Click += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); @@ -174,15 +174,15 @@ private Button buttonSave; private Button buttonCancel; - private TextBox textBoxDateOpening; private TextBox textBoxAddress; private Label labelTime; private Label labelAddress; private DataGridView dataGridView; - private DataGridViewTextBoxColumn SushiName; - private DataGridViewTextBoxColumn Price; - private DataGridViewTextBoxColumn Count; - private ComboBox comboBoxShop; private Label labelShop; + private TextBox textBoxShop; + private DateTimePicker dateTimePicker; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnSushiName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormShop.cs b/SushiBar/SushiBar/FormShop.cs index 671f7b8..00724e3 100644 --- a/SushiBar/SushiBar/FormShop.cs +++ b/SushiBar/SushiBar/FormShop.cs @@ -1,131 +1,111 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; -using SushiBarContracts.ViewModels; +using SushiBarContracts.SearchModels; using SushiBarDataModels.Models; namespace SushiBarView { public partial class FormShop : Form { - private readonly List? _listShops; - private readonly IShopLogic _logic; private readonly ILogger _logger; - public int Id { get; set; } - - private IShopModel? GetShop(int id) - { - if (_listShops == null) - { - return null; - } - foreach (var elem in _listShops) - { - if (elem.Id == id) - { - return elem; - } - } - return null; - } + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopListSushi; + public int Id { set { _id = value; } } public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; - _listShops = logic.ReadList(null); _logic = logic; - if (_listShops != null) - { - comboBoxShop.DisplayMember = "ShopName"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _listShops; - comboBoxShop.SelectedItem = null; - } + _shopListSushi = new(); } + private void FormShop_Load(object sender, EventArgs e) { - LoadData(); - } - private void LoadData(bool extendDate = true) - { - try + + if (_id.HasValue) { - var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); - if (model != null) + _logger.LogInformation("Загрузка магазина"); + try { - comboBoxShop.Text = model.ShopName; - textBoxAddress.Text = model.Address; - textBoxDateOpening.Text = Convert.ToString(model.DateOpening); - dataGridView.Rows.Clear(); - foreach (var el in model.ListSushi.Values) + var view = _logic.ReadElement(new ShopSearchModel { - dataGridView.Rows.Add(new object[] { el.Item1.SushiName, el.Item1.Price, el.Item2 }); + Id = _id.Value + }); + if (view != null) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + _shopListSushi = view.ListSushi ?? new Dictionary(); + LoadData(); } } - _logger.LogInformation("Загрузка магазинов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } } } - private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) + private void LoadData() { - LoadData(false); + _logger.LogInformation("Загрузка суши магазина"); + try + { + if (_shopListSushi != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopListSushi) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.SushiName, 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(comboBoxShop.Text)) + if (string.IsNullOrEmpty(textBoxShop.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxAddress.Text)) { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение суши"); + _logger.LogInformation("Сохранение магазина"); try { - DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); - ShopBindingModel model = new() + var model = new ShopBindingModel { - ShopName = comboBoxShop.Text, + Id = _id ?? 0, + ShopName = textBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime + DateOpening = dateTimePicker.Value.Date }; - var vmodel = GetShop(Id); - bool operationResult = false; - - if (vmodel != null) - { - model.Id = vmodel.Id; - operationResult = _logic.Update(model); - } - else - { - operationResult = _logic.Create(model); - } + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения суши"); + _logger.LogError(ex, "Ошибка сохранения магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/SushiBar/SushiBar/FormShop.resx b/SushiBar/SushiBar/FormShop.resx index a34aa69..aa7de0d 100644 --- a/SushiBar/SushiBar/FormShop.resx +++ b/SushiBar/SushiBar/FormShop.resx @@ -57,13 +57,13 @@ 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/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs index 50017b7..a36aef1 100644 --- a/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ShopStorage.cs @@ -13,21 +13,31 @@ namespace SushiBarListImplement.Implements { _source = DataListSingleton.GetInstance(); } - - public ShopViewModel? Delete(ShopBindingModel model) + public List GetFullList() { - for (int i = 0; i < _source.Shops.Count; ++i) + var result = new List(); + foreach (var shop in _source.Shops) { - if (_source.Shops[i].Id == model.Id) + 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)) { - var element = _source.Shops[i]; - _source.Shops.RemoveAt(i); - return element.GetViewModel; + result.Add(shop.GetViewModel); } } - return null; + return result; } - public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -45,34 +55,6 @@ namespace SushiBarListImplement.Implements } return null; } - - public List GetFilteredList(ShopSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.ShopName)) - { - return result; - } - foreach (var shop in _source.Shops) - { - if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) - { - result.Add(shop.GetViewModel); - } - } - return result; - } - - public List GetFullList() - { - var result = new List(); - foreach (var shop in _source.Shops) - { - result.Add(shop.GetViewModel); - } - return result; - } - public ShopViewModel? Insert(ShopBindingModel model) { model.Id = 1; @@ -91,7 +73,6 @@ namespace SushiBarListImplement.Implements _source.Shops.Add(newShop); return newShop.GetViewModel; } - public ShopViewModel? Update(ShopBindingModel model) { foreach (var shop in _source.Shops) @@ -104,5 +85,18 @@ namespace SushiBarListImplement.Implements } 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/SushiBar/SushiBarListImplement/Models/Shop.cs b/SushiBar/SushiBarListImplement/Models/Shop.cs index aeaf3de..abbecfc 100644 --- a/SushiBar/SushiBarListImplement/Models/Shop.cs +++ b/SushiBar/SushiBarListImplement/Models/Shop.cs @@ -6,20 +6,15 @@ namespace SushiBarListImplement.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 ListSushi { get; private set; } = new(); - - public int Id { get; private set; } - public static Shop? Create(ShopBindingModel? model) { if (model == null) -- 2.25.1 From 2b8ef3fac07404b30faed5b4ebbb4d54e7a2d5b8 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 11:25:23 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.cs | 4 ++-- ...AddSushiInShop.Designer.cs => FormShopSushi.Designer.cs} | 6 +++--- .../SushiBar/{FormAddSushiInShop.cs => FormShopSushi.cs} | 4 ++-- .../{FormAddSushiInShop.resx => FormShopSushi.resx} | 0 SushiBar/SushiBar/Program.cs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename SushiBar/SushiBar/{FormAddSushiInShop.Designer.cs => FormShopSushi.Designer.cs} (98%) rename SushiBar/SushiBar/{FormAddSushiInShop.cs => FormShopSushi.cs} (95%) rename SushiBar/SushiBar/{FormAddSushiInShop.resx => FormShopSushi.resx} (100%) diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index d79cbd6..3fcbfa0 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -169,8 +169,8 @@ namespace SushiBarView private void ButtonAddSushiInShop_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormAddSushiInShop)); - if (service is FormAddSushiInShop form) + var service = Program.ServiceProvider?.GetService(typeof(FormShopSushi)); + if (service is FormShopSushi form) { form.ShowDialog(); } diff --git a/SushiBar/SushiBar/FormAddSushiInShop.Designer.cs b/SushiBar/SushiBar/FormShopSushi.Designer.cs similarity index 98% rename from SushiBar/SushiBar/FormAddSushiInShop.Designer.cs rename to SushiBar/SushiBar/FormShopSushi.Designer.cs index 89627cc..799a9ce 100644 --- a/SushiBar/SushiBar/FormAddSushiInShop.Designer.cs +++ b/SushiBar/SushiBar/FormShopSushi.Designer.cs @@ -1,6 +1,6 @@ namespace SushiBarView { - partial class FormAddSushiInShop + partial class FormShopSushi { /// /// Required designer variable. @@ -116,7 +116,7 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // - // FormAddSushiInShop + // FormShopSushi // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -129,7 +129,7 @@ this.Controls.Add(this.labelSushi); this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.labelShop); - this.Name = "FormAddSushiInShop"; + this.Name = "FormShopSushi"; this.Text = "Поступление суши в суши-бар"; ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); diff --git a/SushiBar/SushiBar/FormAddSushiInShop.cs b/SushiBar/SushiBar/FormShopSushi.cs similarity index 95% rename from SushiBar/SushiBar/FormAddSushiInShop.cs rename to SushiBar/SushiBar/FormShopSushi.cs index 32ce4c7..5e32359 100644 --- a/SushiBar/SushiBar/FormAddSushiInShop.cs +++ b/SushiBar/SushiBar/FormShopSushi.cs @@ -4,7 +4,7 @@ using SushiBarContracts.ViewModels; namespace SushiBarView { - public partial class FormAddSushiInShop : Form + public partial class FormShopSushi : Form { private readonly ILogger _logger; private readonly IShopLogic _shopLogic; @@ -12,7 +12,7 @@ namespace SushiBarView private readonly List? _listShops; private readonly List? _listSushi; - public FormAddSushiInShop(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) + public FormShopSushi(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) { InitializeComponent(); _shopLogic = shopLogic; diff --git a/SushiBar/SushiBar/FormAddSushiInShop.resx b/SushiBar/SushiBar/FormShopSushi.resx similarity index 100% rename from SushiBar/SushiBar/FormAddSushiInShop.resx rename to SushiBar/SushiBar/FormShopSushi.resx diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 8615648..190fe12 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -52,7 +52,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); } -- 2.25.1 From 77bb780e69512385ff2e0664abee6a9bbe563814 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 12:10:14 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=20=D0=B2=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormShop.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SushiBar/SushiBar/FormShop.cs b/SushiBar/SushiBar/FormShop.cs index 00724e3..c97776f 100644 --- a/SushiBar/SushiBar/FormShop.cs +++ b/SushiBar/SushiBar/FormShop.cs @@ -38,6 +38,7 @@ namespace SushiBarView { textBoxShop.Text = view.ShopName; textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); _shopListSushi = view.ListSushi ?? new Dictionary(); LoadData(); } -- 2.25.1 From cb4a75d90d36c439c0a2a6edbd6e9aaab7ad0e3b Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 12:28:32 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20FormMain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.cs | 21 +++---------------- .../BusinessLogics/OrderLogic.cs | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index f92c133..cf0fa99 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -73,12 +73,7 @@ namespace SushiBarView { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].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()), + Id = id }); if (!operationResult) { @@ -103,12 +98,7 @@ namespace SushiBarView { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].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()), + Id = id }); if (!operationResult) { @@ -133,12 +123,7 @@ namespace SushiBarView { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].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()), + Id = id }); if (!operationResult) { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 2d37796..3baee63 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -91,7 +91,7 @@ namespace SushiBarBusinessLogic.BusinessLogics { model.DateImplement = viewModel.DateImplement; } - CheckModel(model); + CheckModel(model, false); if (_orderStorage.Update(model) == null) { model.Status--; -- 2.25.1