From 30b284dda5c5ae475ebc6789ae942e133180d4f3 Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Mon, 11 Mar 2024 03:09:05 +0400 Subject: [PATCH] Fix --- .../BusinessLogics/OrderLogic.cs | 2 +- .../AircraftPlantView/FormMain.Designer.cs | 19 ++- AircraftPlant/AircraftPlantView/FormMain.cs | 14 ++ .../AircraftPlantView/FormSell.Designer.cs | 119 ++++++++++++++++ AircraftPlant/AircraftPlantView/FormSell.cs | 127 ++++++++++++++++++ AircraftPlant/AircraftPlantView/FormSell.resx | 120 +++++++++++++++++ AircraftPlant/AircraftPlantView/Program.cs | 1 + 7 files changed, 398 insertions(+), 4 deletions(-) create mode 100644 AircraftPlant/AircraftPlantView/FormSell.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormSell.cs create mode 100644 AircraftPlant/AircraftPlantView/FormSell.resx diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs index 408900e..870f28f 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -186,7 +186,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics if (newStatus == OrderStatus.Готов) { - var plane = _planeStorage.GetElement(new PlaneSearchModel { Id = model.Id }); + var plane = _planeStorage.GetElement(new PlaneSearchModel { Id = model.PlaneId }); if (plane == null) { _logger.LogWarning("Status change error. Plane not found"); diff --git a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs index 8b19960..bbefa1b 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs @@ -40,6 +40,7 @@ изделияToolStripMenuItem = new ToolStripMenuItem(); магазиныToolStripMenuItem = new ToolStripMenuItem(); buttonAddPlaneInShop = new Button(); + buttonSellPlanes = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -131,21 +132,21 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Size = new Size(145, 22); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // изделияToolStripMenuItem // изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(180, 22); + изделияToolStripMenuItem.Size = new Size(145, 22); изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; // // магазиныToolStripMenuItem // магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(180, 22); + магазиныToolStripMenuItem.Size = new Size(145, 22); магазиныToolStripMenuItem.Text = "Магазины"; магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; // @@ -159,11 +160,22 @@ buttonAddPlaneInShop.UseVisualStyleBackColor = true; buttonAddPlaneInShop.Click += buttonAddPlaneInShop_Click; // + // buttonSellPlanes + // + buttonSellPlanes.Location = new Point(822, 266); + buttonSellPlanes.Name = "buttonSellPlanes"; + buttonSellPlanes.Size = new Size(150, 23); + buttonSellPlanes.TabIndex = 8; + buttonSellPlanes.Text = "Продать изделия"; + buttonSellPlanes.UseVisualStyleBackColor = true; + buttonSellPlanes.Click += buttonSellPlanes_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(984, 361); + Controls.Add(buttonSellPlanes); Controls.Add(buttonAddPlaneInShop); Controls.Add(buttonRefresh); Controls.Add(buttonIssuedOrder); @@ -197,5 +209,6 @@ private ToolStripMenuItem изделияToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonAddPlaneInShop; + private Button buttonSellPlanes; } } \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs index 2006e9f..8241ddb 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.cs @@ -207,6 +207,20 @@ namespace AircraftPlantView } } + /// + /// Кнопка "Продать изделия" + /// + /// + /// + private void buttonSellPlanes_Click(object sender, EventArgs e) + { + var services = Program.ServiceProvider?.GetService(typeof(FormSell)); + if (services is FormSell form) + { + form.ShowDialog(); + } + } + /// /// Кнопка "Обновить список" /// diff --git a/AircraftPlant/AircraftPlantView/FormSell.Designer.cs b/AircraftPlant/AircraftPlantView/FormSell.Designer.cs new file mode 100644 index 0000000..000ee23 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSell.Designer.cs @@ -0,0 +1,119 @@ +namespace AircraftPlantView +{ + partial class FormSell + { + /// + /// 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() + { + comboBoxPlane = new ComboBox(); + labelPlane = new Label(); + labelCount = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // comboBoxPlane + // + comboBoxPlane.FormattingEnabled = true; + comboBoxPlane.Location = new Point(90, 12); + comboBoxPlane.Name = "comboBoxPlane"; + comboBoxPlane.Size = new Size(282, 23); + comboBoxPlane.TabIndex = 0; + // + // labelPlane + // + labelPlane.AutoSize = true; + labelPlane.Location = new Point(12, 15); + labelPlane.Name = "labelPlane"; + labelPlane.Size = new Size(56, 15); + labelPlane.TabIndex = 2; + labelPlane.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 43); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 3; + labelCount.Text = "Количество:"; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 76); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(216, 76); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(282, 23); + textBoxCount.TabIndex = 6; + // + // FormSell + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 111); + Controls.Add(textBoxCount); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(labelCount); + Controls.Add(labelPlane); + Controls.Add(comboBoxPlane); + Name = "FormSell"; + Text = "Продажа"; + Load += FormSell_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxPlane; + private Label labelPlane; + private Label labelCount; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormSell.cs b/AircraftPlant/AircraftPlantView/FormSell.cs new file mode 100644 index 0000000..e95a35d --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSell.cs @@ -0,0 +1,127 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +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 AircraftPlantView +{ + /// + /// Форма продажи изделий + /// + public partial class FormSell : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для изделий + /// + private readonly IPlaneLogic _logicP; + + /// + /// Бизнес-логика для магазинов + /// + private readonly IShopLogic _logicS; + + /// + /// Конструктор + /// + /// + /// + /// + public FormSell(ILogger logger, IPlaneLogic planeLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _logger = logger; + _logicP = planeLogic; + _logicS = shopLogic; + } + + /// + /// Загрузка списка изделий + /// + /// + /// + private void FormSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для продажи"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPlane.DisplayMember = "PlaneName"; + comboBoxPlane.ValueMember = "Id"; + comboBoxPlane.DataSource = list; + comboBoxPlane.SelectedItem = null; + } + } + 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 (comboBoxPlane.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа изделий"); + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicS.SellPlanes( + _logicP.ReadElement(new() { Id = Convert.ToInt32(comboBoxPlane.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, "Ошибка продажи изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormSell.resx b/AircraftPlant/AircraftPlantView/FormSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSell.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AircraftPlant/AircraftPlantView/Program.cs b/AircraftPlant/AircraftPlantView/Program.cs index f9be320..4899db7 100644 --- a/AircraftPlant/AircraftPlantView/Program.cs +++ b/AircraftPlant/AircraftPlantView/Program.cs @@ -66,6 +66,7 @@ namespace AircraftPlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file