From 32d416e795e3fb0c27c325e168f7dcce6a1f9871 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, 27 Feb 2024 15:35:42 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D1=87=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCreateOrder.Designer.cs | 139 ++++++++++++++++++ .../ConfectioneryView/FormCreateOrder.cs | 116 +++++++++++++++ .../ConfectioneryView/FormCreateOrder.resx | 60 ++++++++ .../ConfectioneryView/FormPastry.Designer.cs | 2 +- 4 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.cs create mode 100644 Confectionery/ConfectioneryView/FormCreateOrder.resx diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..420ff18 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -0,0 +1,139 @@ +namespace ConfectioneryView +{ + partial class FormCreateOrder + { + /// + /// 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.labelPastry = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPastry + // + this.labelPastry.AutoSize = true; + this.labelPastry.Location = new System.Drawing.Point(38, 30); + this.labelPastry.Name = "labelPastry"; + this.labelPastry.Size = new System.Drawing.Size(71, 20); + this.labelPastry.TabIndex = 0; + this.labelPastry.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(38, 67); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(38, 102); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(58, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(150, 22); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(337, 28); + this.comboBoxPastry.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 60); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(337, 27); + this.textBoxCount.TabIndex = 4; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(150, 95); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(337, 27); + this.textBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(216, 137); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(361, 137); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(499, 180); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPastry); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPastry; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPastry; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs new file mode 100644 index 0000000..08894b5 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -0,0 +1,116 @@ +using ConfectioneryContracts.BindingModels; +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 FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPastryLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + // прописать логику + } + private void CalcSum() + { + if (comboBoxPastry.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPastry.SelectedValue); + var product = _logicP.ReadElement(new PastrySearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxProduct_SelectedIndexChanged(object sender, + EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.resx b/Confectionery/ConfectioneryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.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/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index b2d43bf..196a105 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -138,7 +138,7 @@ this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Size = new System.Drawing.Size(94, 29); this.ButtonCancel.TabIndex = 8; - this.ButtonCancel.Text = "Удалить"; + this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); //