diff --git a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs index c192940..5cd6016 100644 --- a/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/Confectionery/ConfectionaryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,6 @@ namespace ConfectioneryContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count); + bool Supply(ShopSearchModel shopModel, IPastryModel pastry, int count); } } diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs index e46416e..47becbd 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -84,7 +84,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return true; } - public bool MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count) + public bool Supply(ShopSearchModel shopModel, IPastryModel Pastry, int count) { if (shopModel == null) { @@ -98,11 +98,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count)); } - _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + _logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); if (shop == null) { - _logger.LogWarning("MakeShipment(GetElement). Element not found"); + _logger.LogWarning("Supply(GetElement). Element not found"); return false; } if (shop.ShopPastries.ContainsKey(Pastry.Id)) @@ -110,13 +110,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics var shopIC = shop.ShopPastries[Pastry.Id]; shopIC.Item2 += count; shop.ShopPastries[Pastry.Id] = shopIC; - _logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } else { shop.ShopPastries.Add(Pastry.Id, (Pastry, count)); - _logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, + _logger.LogInformation("Supply. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -128,7 +128,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics ShopPastries = shop.ShopPastries, }) == null) { - _logger.LogWarning("MakeShipment. Update operation failed"); + _logger.LogWarning("Supply. Update operation failed"); return false; } return true; diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index a1b389c..7356071 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -32,6 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазина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(); @@ -46,7 +48,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1376, 28); @@ -57,7 +60,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -76,6 +80,20 @@ this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 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, 24); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -172,5 +190,7 @@ private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index a2460ec..5aec936 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -68,6 +68,24 @@ namespace ConfectioneryView } } + 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(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/Confectionery/ConfectioneryView/FormSupply.Designer.cs b/Confectionery/ConfectioneryView/FormSupply.Designer.cs new file mode 100644 index 0000000..040d631 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.Designer.cs @@ -0,0 +1,150 @@ +namespace ConfectioneryView +{ + partial class FormSupply + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.labelPastry = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(312, 170); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(101, 36); + this.buttonCancel.TabIndex = 19; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(205, 170); + this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(101, 36); + this.buttonSave.TabIndex = 18; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(139, 128); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(287, 27); + this.textBoxCount.TabIndex = 17; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 132); + this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 16; + this.labelCount.Text = "Количество:"; + // + // comboBoxPastry + // + this.comboBoxPastry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(139, 80); + this.comboBoxPastry.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(287, 28); + this.comboBoxPastry.TabIndex = 15; + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(38, 85); + this.labelPastry.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(72, 20); + this.labelPastry.TabIndex = 14; + this.labelPastry.Text = "Выпечка:"; + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(139, 34); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(287, 28); + this.comboBoxShop.TabIndex = 13; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(38, 38); + this.labelShop.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(72, 20); + this.labelShop.TabIndex = 12; + this.labelShop.Text = "Магазин:"; + // + // FormSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 233); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelPastry); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormSupply"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxPastry; + private Label labelPastry; + private ComboBox comboBoxShop; + private Label labelShop; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormSupply.cs b/Confectionery/ConfectioneryView/FormSupply.cs new file mode 100644 index 0000000..912a410 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.cs @@ -0,0 +1,124 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormSupply : Form + { + private readonly ILogger _logger; + + private readonly IPastryLogic _logicPastry; + + private readonly IShopLogic _logicShop; + public FormSupply(ILogger logger, IPastryLogic logicPastry, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPastry = logicPastry; + _logicShop = logicShop; + } + + private void FormSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicPastry.ReadList(null); + if (list != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = list; + comboBoxPastry.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var pastry = _logicPastry.ReadElement(new PastrySearchModel + { Id = Convert.ToInt32(comboBoxPastry.SelectedValue) }); + if (pastry == null) + { + throw new Exception("Мороженое не найдено."); + } + var operationResult = _logicShop.Supply(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + pastry, + Convert.ToInt32(textBoxCount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при проведении поставки."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormSupply.resx b/Confectionery/ConfectioneryView/FormSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormSupply.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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index cebaeea..af295d5 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -36,10 +36,12 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +50,9 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file