From 8628d80362d0ec1e0722c131d2a08952bb9945c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 23 Apr 2024 22:54:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0=202?= =?UTF-8?q?=20=D1=85=D0=B0=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormMain.Designer.cs | 18 +++- Confectionery/ConfectioneryView/FormMain.cs | 11 ++- .../FormPastrySale.Designer.cs | 87 ++++++++++++++++++- .../ConfectioneryView/FormPastrySale.cs | 78 ++++++++++++++++- .../ConfectioneryView/FormPastrySale.resx | 62 +------------ .../ConfectioneryView/FormShop.Designer.cs | 32 ++++++- Confectionery/ConfectioneryView/FormShop.cs | 7 ++ Confectionery/ConfectioneryView/Program.cs | 1 + 8 files changed, 220 insertions(+), 76 deletions(-) diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 320c09a..ff3ee6f 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button(); + this.продажаВыпечкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -49,7 +50,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.продажаВыпечкиToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1376, 28); @@ -69,21 +71,21 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); this.изделияToolStripMenuItem.Text = "Выпечка"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // магазиныToolStripMenuItem // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(182, 26); this.магазиныToolStripMenuItem.Text = "Магазины"; this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); // @@ -154,6 +156,13 @@ this.ButtonRef.UseVisualStyleBackColor = true; this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // продажаВыпечкиToolStripMenuItem + // + this.продажаВыпечкиToolStripMenuItem.Name = "продажаВыпечкиToolStripMenuItem"; + this.продажаВыпечкиToolStripMenuItem.Size = new System.Drawing.Size(151, 24); + this.продажаВыпечкиToolStripMenuItem.Text = "Продажа выпечки"; + this.продажаВыпечкиToolStripMenuItem.Click += new System.EventHandler(this.продажаВыпечкиToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -192,5 +201,6 @@ private Button ButtonRef; private ToolStripMenuItem магазиныToolStripMenuItem; 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 5aec936..a0909d7 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -85,6 +85,14 @@ namespace ConfectioneryView form.ShowDialog(); } } + private void продажаВыпечкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastrySale)); + if (service is FormPastrySale form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { @@ -179,7 +187,6 @@ namespace ConfectioneryView private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); - } - + } } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastrySale.Designer.cs b/Confectionery/ConfectioneryView/FormPastrySale.Designer.cs index 6d16ae7..8fbc2e9 100644 --- a/Confectionery/ConfectioneryView/FormPastrySale.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastrySale.Designer.cs @@ -28,12 +28,93 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSale = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelPastry = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(336, 113); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 13; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSale + // + this.ButtonSale.Location = new System.Drawing.Point(191, 113); + this.ButtonSale.Name = "ButtonSale"; + this.ButtonSale.Size = new System.Drawing.Size(94, 29); + this.ButtonSale.TabIndex = 12; + this.ButtonSale.Text = "Продать"; + this.ButtonSale.UseVisualStyleBackColor = true; + this.ButtonSale.Click += new System.EventHandler(this.ButtonSale_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(129, 65); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(429, 27); + this.textBoxCount.TabIndex = 11; + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(129, 27); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(429, 28); + this.comboBoxPastry.TabIndex = 10; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(17, 72); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 9; + this.labelCount.Text = "Количество:"; + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(17, 35); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(72, 20); + this.labelPastry.TabIndex = 8; + this.labelPastry.Text = "Выпечка:"; + // + // FormPastrySale + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormPastrySale"; + this.ClientSize = new System.Drawing.Size(573, 168); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSale); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPastry); + this.Name = "FormPastrySale"; + this.Text = "Продажа выпечки"; + this.Load += new System.EventHandler(this.FormPastrySale_Load); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Button ButtonCancel; + private Button ButtonSale; + private TextBox textBoxCount; + private ComboBox comboBoxPastry; + private Label labelCount; + private Label labelPastry; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastrySale.cs b/Confectionery/ConfectioneryView/FormPastrySale.cs index 2d444ef..2a59bea 100644 --- a/Confectionery/ConfectioneryView/FormPastrySale.cs +++ b/Confectionery/ConfectioneryView/FormPastrySale.cs @@ -1,4 +1,7 @@ -using System; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.BindingModels; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,80 @@ namespace ConfectioneryView { public partial class FormPastrySale : Form { - public FormPastrySale() + private readonly ILogger _logger; + + private readonly IPastryLogic _logicPastry; + + private readonly IShopLogic _logicShop; + public FormPastrySale(ILogger logger, IPastryLogic logicPastry, IShopLogic logicShop) { InitializeComponent(); + _logger = logger; + _logicPastry = logicPastry; + _logicShop = logicShop; + } + private void FormPastrySale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Pastries 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, "Pastries loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSale_Click(object sender, EventArgs e) + { + 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("Pastry sale"); + try + { + var operationResult = _logicShop.Sale( + new PastryBindingModel + { + Id = Convert.ToInt32(comboBoxPastry.SelectedValue) + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже."); + } + MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Pastry sale error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/Confectionery/ConfectioneryView/FormPastrySale.resx b/Confectionery/ConfectioneryView/FormPastrySale.resx index 1af7de1..f298a7b 100644 --- a/Confectionery/ConfectioneryView/FormPastrySale.resx +++ b/Confectionery/ConfectioneryView/FormPastrySale.resx @@ -1,64 +1,4 @@ - - - + diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index b0a9b9a..fe74f33 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -41,6 +41,8 @@ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxMaximum = new System.Windows.Forms.TextBox(); + this.labelMax = new System.Windows.Forms.Label(); this.groupBoxPastries.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -102,7 +104,7 @@ // groupBoxPastries // this.groupBoxPastries.Controls.Add(this.dataGridView); - this.groupBoxPastries.Location = new System.Drawing.Point(31, 133); + this.groupBoxPastries.Location = new System.Drawing.Point(23, 166); this.groupBoxPastries.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); this.groupBoxPastries.Name = "groupBoxPastries"; this.groupBoxPastries.Padding = new System.Windows.Forms.Padding(5, 4, 5, 4); @@ -160,7 +162,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(449, 529); + this.buttonCancel.Location = new System.Drawing.Point(441, 562); 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); @@ -171,7 +173,7 @@ // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(330, 529); + this.buttonSave.Location = new System.Drawing.Point(322, 562); 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); @@ -180,11 +182,31 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // textBoxMaximum + // + this.textBoxMaximum.Location = new System.Drawing.Point(191, 133); + this.textBoxMaximum.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.textBoxMaximum.Name = "textBoxMaximum"; + this.textBoxMaximum.Size = new System.Drawing.Size(217, 27); + this.textBoxMaximum.TabIndex = 17; + // + // labelMax + // + this.labelMax.AutoSize = true; + this.labelMax.Location = new System.Drawing.Point(32, 137); + this.labelMax.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.labelMax.Name = "labelMax"; + this.labelMax.Size = new System.Drawing.Size(149, 20); + this.labelMax.TabIndex = 16; + this.labelMax.Text = "Максимум выпечки:"; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(603, 578); + this.ClientSize = new System.Drawing.Size(603, 631); + this.Controls.Add(this.textBoxMaximum); + this.Controls.Add(this.labelMax); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.groupBoxPastries); @@ -219,5 +241,7 @@ private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ColumnName; private DataGridViewTextBoxColumn ColumnCount; + private TextBox textBoxMaximum; + private Label labelMax; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs index b9a3230..ef0fda6 100644 --- a/Confectionery/ConfectioneryView/FormShop.cs +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -47,6 +47,7 @@ namespace ConfectioneryView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePicker.Value = view.DateOpening; + textBoxMaximum.Text = view.PastriesMaximum.ToString(); _shopPastries = view.ShopPastries ?? new Dictionary(); LoadData(); } @@ -97,6 +98,11 @@ namespace ConfectioneryView MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (string.IsNullOrEmpty(textBoxMaximum.Text)) + { + MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Shop saving"); try { @@ -106,6 +112,7 @@ namespace ConfectioneryView ShopName = textBoxName.Text, Address = textBoxAddress.Text, DateOpening = dateTimePicker.Value, + PastriesMaximum = Convert.ToInt32(textBoxMaximum.Text), ShopPastries = _shopPastries }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index e7965fe..b2f52c8 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -53,6 +53,7 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file