PIbd-21_MasenkinMS_LabWork02_Hard #5

Closed
Factorino73 wants to merge 9 commits from LabWork02_Hard into LabWork02_Basic
7 changed files with 398 additions and 4 deletions
Showing only changes of commit 30b284dda5 - Show all commits

View File

@ -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");

View File

@ -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;
}
}

View File

@ -207,6 +207,20 @@ namespace AircraftPlantView
}
}
/// <summary>
/// Кнопка "Продать изделия"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSellPlanes_Click(object sender, EventArgs e)
{
var services = Program.ServiceProvider?.GetService(typeof(FormSell));
if (services is FormSell form)
{
form.ShowDialog();
}
}
/// <summary>
/// Кнопка "Обновить список"
/// </summary>

View File

@ -0,0 +1,119 @@
namespace AircraftPlantView
{
partial class FormSell
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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
{
/// <summary>
/// Форма продажи изделий
/// </summary>
public partial class FormSell : Form
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Бизнес-логика для изделий
/// </summary>
private readonly IPlaneLogic _logicP;
/// <summary>
/// Бизнес-логика для магазинов
/// </summary>
private readonly IShopLogic _logicS;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
/// <param name="planeLogic"></param>
/// <param name="shopLogic"></param>
public FormSell(ILogger logger, IPlaneLogic planeLogic, IShopLogic shopLogic)
{
InitializeComponent();
_logger = logger;
_logicP = planeLogic;
_logicS = shopLogic;
}
/// <summary>
/// Загрузка списка изделий
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// Кнопка "Сохранить"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// Кнопка "Отмена"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -66,6 +66,7 @@ namespace AircraftPlantView
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormCreateSupply>();
services.AddTransient<FormSell>();
}
}
}