From f930b4b56c4cafe991c0dcd7b33533371bf3d6e6 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Sun, 11 Feb 2024 18:49:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B6=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/FormCreateOrder.Designer.cs | 102 +++++++++- ProjectFlowerShop/FormCreateOrder.cs | 126 +++++++++++- ProjectFlowerShop/MainForm.Designer.cs | 171 ++++++++++++++++ ProjectFlowerShop/MainForm.cs | 183 ++++++++++++++++++ ProjectFlowerShop/MainForm.resx | 123 ++++++++++++ 5 files changed, 702 insertions(+), 3 deletions(-) create mode 100644 ProjectFlowerShop/MainForm.Designer.cs create mode 100644 ProjectFlowerShop/MainForm.cs create mode 100644 ProjectFlowerShop/MainForm.resx diff --git a/ProjectFlowerShop/FormCreateOrder.Designer.cs b/ProjectFlowerShop/FormCreateOrder.Designer.cs index 12fc38e..ba89839 100644 --- a/ProjectFlowerShop/FormCreateOrder.Designer.cs +++ b/ProjectFlowerShop/FormCreateOrder.Designer.cs @@ -28,18 +28,118 @@ /// private void InitializeComponent() { + labelProduct = new Label(); + labelNumber = new Label(); + LabelSum = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxCount = new TextBox(); + comboBoxProduct = new ComboBox(); + textBoxSum = new TextBox(); SuspendLayout(); // + // labelProduct + // + labelProduct.AutoSize = true; + labelProduct.Location = new Point(12, 29); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(68, 20); + labelProduct.TabIndex = 0; + labelProduct.Text = "Изделие"; + // + // labelNumber + // + labelNumber.AutoSize = true; + labelNumber.Location = new Point(12, 71); + labelNumber.Name = "labelNumber"; + labelNumber.Size = new Size(58, 20); + labelNumber.TabIndex = 1; + labelNumber.Text = "Кол-во"; + // + // LabelSum + // + LabelSum.AutoSize = true; + LabelSum.Location = new Point(12, 113); + LabelSum.Name = "LabelSum"; + LabelSum.Size = new Size(55, 20); + LabelSum.TabIndex = 2; + LabelSum.Text = "Сумма"; + // + // buttonSave + // + buttonSave.Location = new Point(292, 158); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(411, 158); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(97, 68); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(274, 27); + textBoxCount.TabIndex = 5; + textBoxCount.TextChanged += textBox1_TextChanged; + // + // comboBoxProduct + // + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(97, 26); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(274, 28); + comboBoxProduct.TabIndex = 6; + comboBoxProduct.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(97, 110); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(274, 27); + textBoxSum.TabIndex = 7; + textBoxSum.TextChanged += textBox2_TextChanged; + // // FormCreateOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(517, 193); + ClientSize = new Size(514, 199); + Controls.Add(textBoxSum); + Controls.Add(comboBoxProduct); + Controls.Add(textBoxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(LabelSum); + Controls.Add(labelNumber); + Controls.Add(labelProduct); Name = "FormCreateOrder"; Text = "Заказ"; + Load += FormCreateOrder_Load; ResumeLayout(false); + PerformLayout(); } #endregion + + private Label labelProduct; + private Label labelNumber; + private Label LabelSum; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxCount; + private ComboBox comboBoxProduct; + private TextBox textBoxSum; } } \ No newline at end of file diff --git a/ProjectFlowerShop/FormCreateOrder.cs b/ProjectFlowerShop/FormCreateOrder.cs index 0cd9a8e..10bd326 100644 --- a/ProjectFlowerShop/FormCreateOrder.cs +++ b/ProjectFlowerShop/FormCreateOrder.cs @@ -1,4 +1,9 @@ -using System; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.BindingModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +17,126 @@ namespace ProjectFlowerShop { public partial class FormCreateOrder : Form { - public FormCreateOrder() + private readonly ILogger _logger; + private readonly IFlowerLogic _logicF; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IFlowerLogic logicP, IOrderLogic logicO) { InitializeComponent(); + _logger = logger; + _logicF = logicP; + _logicO = logicO; + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBox2_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicF.ReadList(null); + if (list != null) + { + comboBoxProduct.DisplayMember = "FlowerName"; + comboBoxProduct.ValueMember = "Id"; + comboBoxProduct.DataSource = list; + comboBoxProduct.SelectedItem = null; + } + _logger.LogInformation("Цветы загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки цветов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxProduct.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxProduct.SelectedValue); + var product = _logicF.ReadElement(new FlowerSearchModel + { + 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 buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxProduct.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + FlowerId = Convert.ToInt32(comboBoxProduct.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/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs new file mode 100644 index 0000000..2b62d4f --- /dev/null +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -0,0 +1,171 @@ +namespace IceCreamShop +{ + partial class MainForm + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + ToolStripMenu = new ToolStripMenuItem(); + КомпонентыStripMenuItem = new ToolStripMenuItem(); + МороженноеStripMenuItem = new ToolStripMenuItem(); + DataGridView = new DataGridView(); + CreateOrderButton = new Button(); + TakeInWorkButton = new Button(); + ReadyButton = new Button(); + IssuedButton = new Button(); + RefreshButton = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenu }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1296, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // ToolStripMenu + // + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, МороженноеStripMenuItem }); + ToolStripMenu.Name = "ToolStripMenu"; + ToolStripMenu.Size = new Size(117, 24); + ToolStripMenu.Text = "Справочники"; + // + // КомпонентыStripMenuItem + // + КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; + КомпонентыStripMenuItem.Size = new Size(186, 26); + КомпонентыStripMenuItem.Text = "Компоненты"; + КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; + // + // МороженноеStripMenuItem + // + МороженноеStripMenuItem.Name = "МороженноеStripMenuItem"; + МороженноеStripMenuItem.Size = new Size(186, 26); + МороженноеStripMenuItem.Text = "Мороженное"; + МороженноеStripMenuItem.Click += МороженноеStripMenuItem_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 31); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(1007, 407); + DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + CreateOrderButton.Location = new Point(1025, 31); + CreateOrderButton.Name = "CreateOrderButton"; + CreateOrderButton.Size = new Size(259, 29); + CreateOrderButton.TabIndex = 2; + CreateOrderButton.Text = "Создать заказ"; + CreateOrderButton.UseVisualStyleBackColor = true; + CreateOrderButton.Click += CreateOrderButton_Click; + // + // TakeInWorkButton + // + TakeInWorkButton.Location = new Point(1025, 66); + TakeInWorkButton.Name = "TakeInWorkButton"; + TakeInWorkButton.Size = new Size(259, 29); + TakeInWorkButton.TabIndex = 3; + TakeInWorkButton.Text = "Отдать заказ в работу"; + TakeInWorkButton.UseVisualStyleBackColor = true; + TakeInWorkButton.Click += TakeInWorkButton_Click; + // + // ReadyButton + // + ReadyButton.Location = new Point(1025, 101); + ReadyButton.Name = "ReadyButton"; + ReadyButton.Size = new Size(259, 29); + ReadyButton.TabIndex = 4; + ReadyButton.Text = "Заказ готов"; + ReadyButton.UseVisualStyleBackColor = true; + ReadyButton.Click += ReadyButton_Click; + // + // IssuedButton + // + IssuedButton.Location = new Point(1025, 136); + IssuedButton.Name = "IssuedButton"; + IssuedButton.Size = new Size(259, 29); + IssuedButton.TabIndex = 5; + IssuedButton.Text = "Заказ выдан"; + IssuedButton.UseVisualStyleBackColor = true; + IssuedButton.Click += IssuedButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(1025, 171); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(259, 29); + RefreshButton.TabIndex = 6; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // MainForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1296, 450); + Controls.Add(RefreshButton); + Controls.Add(IssuedButton); + Controls.Add(ReadyButton); + Controls.Add(TakeInWorkButton); + Controls.Add(CreateOrderButton); + Controls.Add(DataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "MainForm"; + Text = "MainForm"; + Load += MainForm_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenu; + private ToolStripMenuItem КомпонентыStripMenuItem; + private ToolStripMenuItem МороженноеStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button TakeInWorkButton; + private Button ReadyButton; + private Button IssuedButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs new file mode 100644 index 0000000..613d82d --- /dev/null +++ b/ProjectFlowerShop/MainForm.cs @@ -0,0 +1,183 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopDataModels; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using ProjectFlowerShop; +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 IceCreamShop +{ + public partial class MainForm : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public MainForm(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void КомпонентыStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + + } + + private void MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["IceCreamId"].Visible = false; + DataGridView.Columns["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void МороженноеStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IceCreamsForm)); + if (service is IceCreamsForm form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + FlowerId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["IceCreamId"].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()), + }; + } + + private void TakeInWorkButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void ReadyButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void IssuedButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ProjectFlowerShop/MainForm.resx b/ProjectFlowerShop/MainForm.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/ProjectFlowerShop/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file