Сливание с веткой лаб 2 усл
This commit is contained in:
commit
eaf87f159e
144
GarmentFactory/FormAddTextile.Designer.cs
generated
Normal file
144
GarmentFactory/FormAddTextile.Designer.cs
generated
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
namespace GarmentFactoryView
|
||||||
|
{
|
||||||
|
partial class FormAddTextile
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
labelShop = new Label();
|
||||||
|
labelCount = new Label();
|
||||||
|
labelTextile = new Label();
|
||||||
|
comboBoxShop = new ComboBox();
|
||||||
|
textBoxCount = new TextBox();
|
||||||
|
comboBoxTextile = new ComboBox();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
buttonSave = new Button();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelShop
|
||||||
|
//
|
||||||
|
labelShop.AutoSize = true;
|
||||||
|
labelShop.Location = new Point(38, 37);
|
||||||
|
labelShop.Name = "labelShop";
|
||||||
|
labelShop.Size = new Size(72, 20);
|
||||||
|
labelShop.TabIndex = 0;
|
||||||
|
labelShop.Text = "Магазин:";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(29, 123);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(93, 20);
|
||||||
|
labelCount.TabIndex = 3;
|
||||||
|
labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// labelTextile
|
||||||
|
//
|
||||||
|
labelTextile.AutoSize = true;
|
||||||
|
labelTextile.Location = new Point(38, 79);
|
||||||
|
labelTextile.Name = "labelTextile";
|
||||||
|
labelTextile.Size = new Size(71, 20);
|
||||||
|
labelTextile.TabIndex = 2;
|
||||||
|
labelTextile.Text = "Изделие:";
|
||||||
|
//
|
||||||
|
// comboBoxShop
|
||||||
|
//
|
||||||
|
comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxShop.FormattingEnabled = true;
|
||||||
|
comboBoxShop.Location = new Point(140, 37);
|
||||||
|
comboBoxShop.Name = "comboBoxShop";
|
||||||
|
comboBoxShop.Size = new Size(262, 28);
|
||||||
|
comboBoxShop.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
textBoxCount.Location = new Point(140, 123);
|
||||||
|
textBoxCount.Name = "textBoxCount";
|
||||||
|
textBoxCount.Size = new Size(262, 27);
|
||||||
|
textBoxCount.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// comboBoxTextile
|
||||||
|
//
|
||||||
|
comboBoxTextile.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxTextile.FormattingEnabled = true;
|
||||||
|
comboBoxTextile.Location = new Point(140, 79);
|
||||||
|
comboBoxTextile.Name = "comboBoxTextile";
|
||||||
|
comboBoxTextile.Size = new Size(262, 28);
|
||||||
|
comboBoxTextile.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(342, 181);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(94, 29);
|
||||||
|
buttonCancel.TabIndex = 13;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Location = new Point(242, 181);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(94, 29);
|
||||||
|
buttonSave.TabIndex = 12;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// FormAddTextile
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(455, 222);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(comboBoxShop);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(comboBoxTextile);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(labelTextile);
|
||||||
|
Controls.Add(labelShop);
|
||||||
|
Name = "FormAddTextile";
|
||||||
|
Text = "Пополнение магазина";
|
||||||
|
Load += FormAddTextile_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelShop;
|
||||||
|
private Label labelCount;
|
||||||
|
private Label labelTextile;
|
||||||
|
private ComboBox comboBoxShop;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private ComboBox comboBoxTextile;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
}
|
||||||
|
}
|
109
GarmentFactory/FormAddTextile.cs
Normal file
109
GarmentFactory/FormAddTextile.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
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 GarmentFactoryView
|
||||||
|
{
|
||||||
|
public partial class FormAddTextile : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ITextileLogic _logicT;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
//Списки для ComboBox
|
||||||
|
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
|
||||||
|
private List<TextileViewModel> _textileList = new List<TextileViewModel>();
|
||||||
|
public FormAddTextile(ILogger<FormAddTextile> logger, ITextileLogic logicT, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicT = logicT;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormAddTextile_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_shopList = _logicS.ReadList(null);
|
||||||
|
_textileList = _logicT.ReadList(null);
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка списка магазинов при пополнении");
|
||||||
|
if (_shopList != null)
|
||||||
|
{
|
||||||
|
comboBoxShop.DisplayMember = "ShopName";
|
||||||
|
comboBoxShop.ValueMember = "Id";
|
||||||
|
comboBoxShop.DataSource = _shopList;
|
||||||
|
comboBoxShop.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка списка товаров при пополнении");
|
||||||
|
if (_textileList != null)
|
||||||
|
{
|
||||||
|
comboBoxTextile.DisplayMember = "TextileName";
|
||||||
|
comboBoxTextile.ValueMember = "Id";
|
||||||
|
comboBoxTextile.DataSource = _textileList;
|
||||||
|
comboBoxTextile.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxShop.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxTextile.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле \"Количество\"", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Пополнение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
||||||
|
{
|
||||||
|
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
||||||
|
TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue),
|
||||||
|
Count = 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
GarmentFactory/FormAddTextile.resx
Normal file
120
GarmentFactory/FormAddTextile.resx
Normal 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>
|
40
GarmentFactory/FormMain.Designer.cs
generated
40
GarmentFactory/FormMain.Designer.cs
generated
@ -38,6 +38,10 @@
|
|||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
текстилиToolStripMenuItem = new ToolStripMenuItem();
|
текстилиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
операцииToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
пополнениеМагазинаToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
|
продажаТовараToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
menuStrip1.SuspendLayout();
|
menuStrip1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -116,7 +120,7 @@
|
|||||||
// menuStrip1
|
// menuStrip1
|
||||||
//
|
//
|
||||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
|
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem });
|
||||||
menuStrip1.Location = new Point(0, 0);
|
menuStrip1.Location = new Point(0, 0);
|
||||||
menuStrip1.Name = "menuStrip1";
|
menuStrip1.Name = "menuStrip1";
|
||||||
menuStrip1.Size = new Size(1169, 28);
|
menuStrip1.Size = new Size(1169, 28);
|
||||||
@ -125,7 +129,7 @@
|
|||||||
//
|
//
|
||||||
// справочникиToolStripMenuItem
|
// справочникиToolStripMenuItem
|
||||||
//
|
//
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem });
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, текстилиToolStripMenuItem, магазиныToolStripMenuItem });
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
@ -144,6 +148,34 @@
|
|||||||
текстилиToolStripMenuItem.Text = "Текстили";
|
текстилиToolStripMenuItem.Text = "Текстили";
|
||||||
текстилиToolStripMenuItem.Click += текстилиToolStripMenuItem_Click;
|
текстилиToolStripMenuItem.Click += текстилиToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// магазиныToolStripMenuItem
|
||||||
|
//
|
||||||
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
|
магазиныToolStripMenuItem.Size = new Size(182, 26);
|
||||||
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
|
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// операцииToolStripMenuItem
|
||||||
|
//
|
||||||
|
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { пополнениеМагазинаToolStripMenuItem1, продажаТовараToolStripMenuItem });
|
||||||
|
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
|
||||||
|
операцииToolStripMenuItem.Size = new Size(95, 24);
|
||||||
|
операцииToolStripMenuItem.Text = "Операции";
|
||||||
|
//
|
||||||
|
// пополнениеМагазинаToolStripMenuItem1
|
||||||
|
//
|
||||||
|
пополнениеМагазинаToolStripMenuItem1.Name = "пополнениеМагазинаToolStripMenuItem1";
|
||||||
|
пополнениеМагазинаToolStripMenuItem1.Size = new Size(251, 26);
|
||||||
|
пополнениеМагазинаToolStripMenuItem1.Text = "Пополнение магазина";
|
||||||
|
пополнениеМагазинаToolStripMenuItem1.Click += пополнениеМагазинаToolStripMenuItem1_Click;
|
||||||
|
//
|
||||||
|
// продажаТовараToolStripMenuItem
|
||||||
|
//
|
||||||
|
продажаТовараToolStripMenuItem.Name = "продажаТовараToolStripMenuItem";
|
||||||
|
продажаТовараToolStripMenuItem.Size = new Size(251, 26);
|
||||||
|
продажаТовараToolStripMenuItem.Text = "Продажа товара";
|
||||||
|
продажаТовараToolStripMenuItem.Click += продажаТовараToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -179,5 +211,9 @@
|
|||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem текстилиToolStripMenuItem;
|
private ToolStripMenuItem текстилиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem операцииToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem1;
|
||||||
|
private ToolStripMenuItem продажаТовараToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,6 +68,16 @@ namespace GarmentFactoryView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
|
|
||||||
|
if (service is FormShops form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
@ -148,5 +158,24 @@ namespace GarmentFactoryView
|
|||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile));
|
||||||
|
|
||||||
|
if (service is FormAddTextile form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile));
|
||||||
|
if (service is FormSellTextile form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
119
GarmentFactory/FormSellTextile.Designer.cs
generated
Normal file
119
GarmentFactory/FormSellTextile.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
namespace GarmentFactoryView
|
||||||
|
{
|
||||||
|
partial class FormSellTextile
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
labelTextile = new Label();
|
||||||
|
comboBoxTextile = new ComboBox();
|
||||||
|
labelCount = new Label();
|
||||||
|
textBoxCount = new TextBox();
|
||||||
|
buttonSell = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelTextile
|
||||||
|
//
|
||||||
|
labelTextile.AutoSize = true;
|
||||||
|
labelTextile.Location = new Point(12, 14);
|
||||||
|
labelTextile.Name = "labelTextile";
|
||||||
|
labelTextile.Size = new Size(77, 20);
|
||||||
|
labelTextile.TabIndex = 0;
|
||||||
|
labelTextile.Text = "Текстиль: ";
|
||||||
|
//
|
||||||
|
// comboBoxTextile
|
||||||
|
//
|
||||||
|
comboBoxTextile.FormattingEnabled = true;
|
||||||
|
comboBoxTextile.Location = new Point(115, 11);
|
||||||
|
comboBoxTextile.Name = "comboBoxTextile";
|
||||||
|
comboBoxTextile.Size = new Size(239, 28);
|
||||||
|
comboBoxTextile.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(12, 55);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(97, 20);
|
||||||
|
labelCount.TabIndex = 2;
|
||||||
|
labelCount.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
textBoxCount.Location = new Point(115, 52);
|
||||||
|
textBoxCount.Name = "textBoxCount";
|
||||||
|
textBoxCount.Size = new Size(239, 27);
|
||||||
|
textBoxCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSell
|
||||||
|
//
|
||||||
|
buttonSell.Location = new Point(128, 99);
|
||||||
|
buttonSell.Name = "buttonSell";
|
||||||
|
buttonSell.Size = new Size(94, 29);
|
||||||
|
buttonSell.TabIndex = 4;
|
||||||
|
buttonSell.Text = "Продать";
|
||||||
|
buttonSell.UseVisualStyleBackColor = true;
|
||||||
|
buttonSell.Click += ButtonSell_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(242, 99);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(94, 29);
|
||||||
|
buttonCancel.TabIndex = 5;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// FormSellTextile
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(366, 140);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSell);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(comboBoxTextile);
|
||||||
|
Controls.Add(labelTextile);
|
||||||
|
Name = "FormSellTextile";
|
||||||
|
Text = "Продажа текстиля";
|
||||||
|
Load += FormSellingTextile_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelTextile;
|
||||||
|
private ComboBox comboBoxTextile;
|
||||||
|
private Label labelCount;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Button buttonSell;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
87
GarmentFactory/FormSellTextile.cs
Normal file
87
GarmentFactory/FormSellTextile.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using GarmentFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
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 GarmentFactoryView
|
||||||
|
{
|
||||||
|
public partial class FormSellTextile : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ITextileLogic _logicT;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
private List<TextileViewModel> _TextileList = new List<TextileViewModel>();
|
||||||
|
|
||||||
|
public FormSellTextile(ILogger<FormSellTextile> logger, ITextileLogic logicT, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicT = logicT;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormSellingTextile_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_TextileList = _logicT.ReadList(null);
|
||||||
|
if (_TextileList != null)
|
||||||
|
{
|
||||||
|
comboBoxTextile.DisplayMember = "TextileName";
|
||||||
|
comboBoxTextile.ValueMember = "Id";
|
||||||
|
comboBoxTextile.DataSource = _TextileList;
|
||||||
|
comboBoxTextile.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка пиццы для продажи");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSell_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxTextile.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание покупки");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool resout = _logicS.Sell(new SupplySearchModel
|
||||||
|
{
|
||||||
|
TextileId = Convert.ToInt32(comboBoxTextile.SelectedValue),
|
||||||
|
Count = Convert.ToInt32(textBoxCount.Text)
|
||||||
|
});
|
||||||
|
if (resout)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Проверка была выполнена");
|
||||||
|
MessageBox.Show("Продажа выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Проверка не пройдена");
|
||||||
|
MessageBox.Show("Продажа не может быть выполнена.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
GarmentFactory/FormSellTextile.resx
Normal file
120
GarmentFactory/FormSellTextile.resx
Normal 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>
|
230
GarmentFactory/FormShop.Designer.cs
generated
Normal file
230
GarmentFactory/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
namespace GarmentFactoryView
|
||||||
|
{
|
||||||
|
partial class FormShop
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
labelName = new Label();
|
||||||
|
labelAddress = new Label();
|
||||||
|
labelDateOpen = new Label();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
textBoxAddress = new TextBox();
|
||||||
|
dateTimePicker = new DateTimePicker();
|
||||||
|
groupBoxTextiles = new GroupBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
ID = new DataGridViewTextBoxColumn();
|
||||||
|
ColumnTextileName = new DataGridViewTextBoxColumn();
|
||||||
|
ColumnCount = new DataGridViewTextBoxColumn();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
buttonSave = new Button();
|
||||||
|
numericUpTextileMaxCount = new NumericUpDown();
|
||||||
|
label2 = new Label();
|
||||||
|
groupBoxTextiles.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpTextileMaxCount).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(30, 21);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(84, 20);
|
||||||
|
labelName.TabIndex = 0;
|
||||||
|
labelName.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// labelAddress
|
||||||
|
//
|
||||||
|
labelAddress.AutoSize = true;
|
||||||
|
labelAddress.Location = new Point(40, 71);
|
||||||
|
labelAddress.Name = "labelAddress";
|
||||||
|
labelAddress.Size = new Size(58, 20);
|
||||||
|
labelAddress.TabIndex = 1;
|
||||||
|
labelAddress.Text = "Адрес: ";
|
||||||
|
//
|
||||||
|
// labelDateOpen
|
||||||
|
//
|
||||||
|
labelDateOpen.AutoSize = true;
|
||||||
|
labelDateOpen.Location = new Point(12, 118);
|
||||||
|
labelDateOpen.Name = "labelDateOpen";
|
||||||
|
labelDateOpen.Size = new Size(117, 20);
|
||||||
|
labelDateOpen.TabIndex = 2;
|
||||||
|
labelDateOpen.Text = "Дата открытия: ";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(135, 21);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(243, 27);
|
||||||
|
textBoxName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// textBoxAddress
|
||||||
|
//
|
||||||
|
textBoxAddress.Location = new Point(135, 68);
|
||||||
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
|
textBoxAddress.Size = new Size(243, 27);
|
||||||
|
textBoxAddress.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
dateTimePicker.Location = new Point(135, 113);
|
||||||
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
|
dateTimePicker.Size = new Size(243, 27);
|
||||||
|
dateTimePicker.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// groupBoxTextiles
|
||||||
|
//
|
||||||
|
groupBoxTextiles.Controls.Add(dataGridView);
|
||||||
|
groupBoxTextiles.Location = new Point(12, 209);
|
||||||
|
groupBoxTextiles.Name = "groupBoxTextiles";
|
||||||
|
groupBoxTextiles.Size = new Size(651, 306);
|
||||||
|
groupBoxTextiles.TabIndex = 6;
|
||||||
|
groupBoxTextiles.TabStop = false;
|
||||||
|
groupBoxTextiles.Text = "Изделия";
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnTextileName, ColumnCount });
|
||||||
|
dataGridView.Location = new Point(6, 26);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.ReadOnly = true;
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 29;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(633, 274);
|
||||||
|
dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
ID.HeaderText = "ID";
|
||||||
|
ID.MinimumWidth = 6;
|
||||||
|
ID.Name = "ID";
|
||||||
|
ID.ReadOnly = true;
|
||||||
|
ID.Visible = false;
|
||||||
|
//
|
||||||
|
// ColumnTextileName
|
||||||
|
//
|
||||||
|
ColumnTextileName.HeaderText = "Изделие";
|
||||||
|
ColumnTextileName.MinimumWidth = 6;
|
||||||
|
ColumnTextileName.Name = "ColumnTextileName";
|
||||||
|
ColumnTextileName.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// ColumnCount
|
||||||
|
//
|
||||||
|
ColumnCount.HeaderText = "Количество";
|
||||||
|
ColumnCount.MinimumWidth = 6;
|
||||||
|
ColumnCount.Name = "ColumnCount";
|
||||||
|
ColumnCount.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||||
|
buttonCancel.Location = new Point(550, 532);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(103, 40);
|
||||||
|
buttonCancel.TabIndex = 9;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||||
|
buttonSave.Location = new Point(432, 532);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(103, 40);
|
||||||
|
buttonSave.TabIndex = 8;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// numericUpTextileMaxCount
|
||||||
|
//
|
||||||
|
numericUpTextileMaxCount.Location = new Point(135, 163);
|
||||||
|
numericUpTextileMaxCount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
|
||||||
|
numericUpTextileMaxCount.Name = "numericUpTextileMaxCount";
|
||||||
|
numericUpTextileMaxCount.Size = new Size(243, 27);
|
||||||
|
numericUpTextileMaxCount.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(19, 165);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(103, 20);
|
||||||
|
label2.TabIndex = 12;
|
||||||
|
label2.Text = "Вместимость:";
|
||||||
|
//
|
||||||
|
// FormShop
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(682, 584);
|
||||||
|
Controls.Add(numericUpTextileMaxCount);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(groupBoxTextiles);
|
||||||
|
Controls.Add(dateTimePicker);
|
||||||
|
Controls.Add(textBoxAddress);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(labelDateOpen);
|
||||||
|
Controls.Add(labelAddress);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Name = "FormShop";
|
||||||
|
Text = "Магазин";
|
||||||
|
Load += FormShop_Load;
|
||||||
|
groupBoxTextiles.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpTextileMaxCount).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelAddress;
|
||||||
|
private Label labelDateOpen;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxAddress;
|
||||||
|
private DateTimePicker dateTimePicker;
|
||||||
|
private GroupBox groupBoxTextiles;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn ColumnTextileName;
|
||||||
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
private NumericUpDown numericUpTextileMaxCount;
|
||||||
|
private Label label2;
|
||||||
|
}
|
||||||
|
}
|
135
GarmentFactory/FormShop.cs
Normal file
135
GarmentFactory/FormShop.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
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 GarmentFactoryView
|
||||||
|
{
|
||||||
|
public partial class FormShop : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
|
||||||
|
private int? _id;
|
||||||
|
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
|
private Dictionary<int, (ITextileModel, int)> _shopTextiles;
|
||||||
|
|
||||||
|
|
||||||
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_shopTextiles = new Dictionary<int, (ITextileModel, int)>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new ShopSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.ShopName;
|
||||||
|
textBoxAddress.Text = view.Address.ToString();
|
||||||
|
dateTimePicker.Value = view.DateOpen;
|
||||||
|
numericUpTextileMaxCount.Value = view.TextileMaxCount;
|
||||||
|
_shopTextiles = view.ShopTextiles ?? new Dictionary<int, (ITextileModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделий в магазине");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_shopTextiles != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var element in _shopTextiles)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.TextileName, element.Value.Item2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
DateOpen = dateTimePicker.Value.Date,
|
||||||
|
ShopTextiles = _shopTextiles,
|
||||||
|
TextileMaxCount = (int)numericUpTextileMaxCount.Value
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
129
GarmentFactory/FormShop.resx
Normal file
129
GarmentFactory/FormShop.resx
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
<?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>
|
||||||
|
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ColumnTextileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
116
GarmentFactory/FormShops.Designer.cs
generated
Normal file
116
GarmentFactory/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
namespace GarmentFactoryView
|
||||||
|
{
|
||||||
|
partial class FormShops
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(-3, -4);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.ReadOnly = true;
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 29;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(640, 455);
|
||||||
|
dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(658, 252);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(120, 40);
|
||||||
|
buttonRefresh.TabIndex = 12;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(658, 183);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(120, 40);
|
||||||
|
buttonDelete.TabIndex = 11;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(658, 115);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(120, 40);
|
||||||
|
buttonUpdate.TabIndex = 10;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(658, 50);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(120, 40);
|
||||||
|
buttonAdd.TabIndex = 9;
|
||||||
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += ButtonAdd_Click;
|
||||||
|
//
|
||||||
|
// FormShops
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonRefresh);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Name = "FormShops";
|
||||||
|
Text = "Магазины";
|
||||||
|
Load += FormShops_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonAdd;
|
||||||
|
}
|
||||||
|
}
|
115
GarmentFactory/FormShops.cs
Normal file
115
GarmentFactory/FormShops.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using GarmentFactory;
|
||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.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 GarmentFactoryView
|
||||||
|
{
|
||||||
|
public partial class FormShops : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShops_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["ShopTextiles"].Visible = false;
|
||||||
|
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка магазинов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||||
|
if (service is FormShop form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||||
|
if (service is FormShop form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
GarmentFactory/FormShops.resx
Normal file
120
GarmentFactory/FormShops.resx
Normal 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>
|
4
GarmentFactory/FormTextile.Designer.cs
generated
4
GarmentFactory/FormTextile.Designer.cs
generated
@ -138,6 +138,7 @@
|
|||||||
//
|
//
|
||||||
dataGridView.AllowUserToAddRows = false;
|
dataGridView.AllowUserToAddRows = false;
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3 });
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3 });
|
||||||
dataGridView.Dock = DockStyle.Left;
|
dataGridView.Dock = DockStyle.Left;
|
||||||
@ -159,7 +160,6 @@
|
|||||||
Column1.Name = "Column1";
|
Column1.Name = "Column1";
|
||||||
Column1.ReadOnly = true;
|
Column1.ReadOnly = true;
|
||||||
Column1.Visible = false;
|
Column1.Visible = false;
|
||||||
Column1.Width = 125;
|
|
||||||
//
|
//
|
||||||
// Column2
|
// Column2
|
||||||
//
|
//
|
||||||
@ -167,7 +167,6 @@
|
|||||||
Column2.MinimumWidth = 6;
|
Column2.MinimumWidth = 6;
|
||||||
Column2.Name = "Column2";
|
Column2.Name = "Column2";
|
||||||
Column2.ReadOnly = true;
|
Column2.ReadOnly = true;
|
||||||
Column2.Width = 125;
|
|
||||||
//
|
//
|
||||||
// Column3
|
// Column3
|
||||||
//
|
//
|
||||||
@ -175,7 +174,6 @@
|
|||||||
Column3.MinimumWidth = 6;
|
Column3.MinimumWidth = 6;
|
||||||
Column3.Name = "Column3";
|
Column3.Name = "Column3";
|
||||||
Column3.ReadOnly = true;
|
Column3.ReadOnly = true;
|
||||||
Column3.Width = 125;
|
|
||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
|
3
GarmentFactory/FormTextiles.Designer.cs
generated
3
GarmentFactory/FormTextiles.Designer.cs
generated
@ -38,6 +38,9 @@
|
|||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Dock = DockStyle.Left;
|
dataGridView.Dock = DockStyle.Left;
|
||||||
dataGridView.Location = new Point(0, 0);
|
dataGridView.Location = new Point(0, 0);
|
||||||
|
@ -38,10 +38,12 @@ namespace GarmentFactory
|
|||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
services.AddTransient<ITextileStorage, TextileStorage>();
|
services.AddTransient<ITextileStorage, TextileStorage>();
|
||||||
|
services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<ITextileLogic, TextileLogic>();
|
services.AddTransient<ITextileLogic, TextileLogic>();
|
||||||
|
services.AddTransient<IShopLogic, ShopLogic>();
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormComponent>();
|
services.AddTransient<FormComponent>();
|
||||||
@ -50,6 +52,11 @@ namespace GarmentFactory
|
|||||||
services.AddTransient<FormTextile>();
|
services.AddTransient<FormTextile>();
|
||||||
services.AddTransient<FormTextileComponent>();
|
services.AddTransient<FormTextileComponent>();
|
||||||
services.AddTransient<FormTextiles>();
|
services.AddTransient<FormTextiles>();
|
||||||
|
|
||||||
|
services.AddTransient<FormShop>();
|
||||||
|
services.AddTransient<FormShops>();
|
||||||
|
services.AddTransient<FormAddTextile>();
|
||||||
|
services.AddTransient<FormSellTextile>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,10 +19,12 @@ namespace GarmentFactoryBusinessLogic
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//Хранение всех заказов
|
//Хранение всех заказов
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly IShopStorage _shopStorage;
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Чтение всего списка заказов
|
//Чтение всего списка заказов
|
||||||
@ -133,6 +135,17 @@ namespace GarmentFactoryBusinessLogic
|
|||||||
//Перевод заказа в состояние выдачи (окончательное завершение)
|
//Перевод заказа в состояние выдачи (окончательное завершение)
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
|
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(order));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Если нельзя пополнить магазины таким кол-вом товаров (не хавтает места), то статус не меняем
|
||||||
|
if (!_shopStorage.RestockShops(new SupplyBindingModel { TextileId = order.TextileId, Count = order.Count }))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Недостаточно места");
|
||||||
|
}
|
||||||
return ChangeStatus(model, OrderStatus.Выдан);
|
return ChangeStatus(model, OrderStatus.Выдан);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
221
GarmentFactoryBusinessLogic/ShopLogic.cs
Normal file
221
GarmentFactoryBusinessLogic/ShopLogic.cs
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.StoragesContracts;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryBusinessLogic
|
||||||
|
{
|
||||||
|
public class ShopLogic : IShopLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
// Хранилище всех магазинов
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
|
private readonly ITextileStorage _textileStorage;
|
||||||
|
|
||||||
|
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, ITextileStorage textileStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
_textileStorage = textileStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Чтение конкретного магазина
|
||||||
|
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(model);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Чтение всех магазинов
|
||||||
|
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
|
||||||
|
|
||||||
|
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание магазина
|
||||||
|
public bool Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
|
||||||
|
if (_shopStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновление магазина
|
||||||
|
public bool Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Удаление магазина
|
||||||
|
public bool Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
|
if (_shopStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Пополнение магазина
|
||||||
|
public bool MakeSupply(SupplyBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
var textile = _textileStorage.GetElement(new TextileSearchModel { Id = model.TextileId });
|
||||||
|
if (textile == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"При добавлении товара в магазин товар с id={model.TextileId} не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.ShopId });
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"При добавлении товара в магазин магазин c id={model.ShopId} не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
int countTextilesInShop = shop.ShopTextiles.Select(x => x.Value.Item2).Sum();
|
||||||
|
|
||||||
|
//Если в текущий магазин помещается столько товаров
|
||||||
|
if (countTextilesInShop + model.Count <= shop.TextileMaxCount)
|
||||||
|
{
|
||||||
|
// Если такой товар есть, то прибавление переданного кол-ва
|
||||||
|
if (shop.ShopTextiles.ContainsKey(model.TextileId))
|
||||||
|
{
|
||||||
|
var oldValue = shop.ShopTextiles[model.TextileId];
|
||||||
|
oldValue.Item2 += model.Count;
|
||||||
|
shop.ShopTextiles[model.TextileId] = oldValue;
|
||||||
|
}
|
||||||
|
// Если такого товара нет, то кол-во такого товара равно переданному кол-ву
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.ShopTextiles.Add(model.TextileId, (textile, model.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Address = shop.Address,
|
||||||
|
DateOpen = shop.DateOpen,
|
||||||
|
ShopTextiles = shop.ShopTextiles,
|
||||||
|
TextileMaxCount = shop.TextileMaxCount,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//Если не поместилось столько товара
|
||||||
|
_logger.LogWarning("Required shop is overflowed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка данных магазина при добавлении/удалении/обновлении
|
||||||
|
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
// При удалении проверка дальше не нужна
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка наличия названия
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Отсутствует название магазина", nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка наличия адреса
|
||||||
|
if (string.IsNullOrEmpty(model.Address))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id);
|
||||||
|
|
||||||
|
var element = _shopStorage.GetElement(new ShopSearchModel { ShopName = model.ShopName });
|
||||||
|
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sell(SupplySearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.TextileId.HasValue || !model.Count.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_shopStorage.Sell(model))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Selling sucsess");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Selling failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
GarmentFactoryContracts/BindingModels/ShopBindingModel.cs
Normal file
23
GarmentFactoryContracts/BindingModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ShopBindingModel : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Address { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public Dictionary<int, (ITextileModel, int)> ShopTextiles { get; set; } = new();
|
||||||
|
|
||||||
|
public int TextileMaxCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
16
GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs
Normal file
16
GarmentFactoryContracts/BindingModels/SupplyBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class SupplyBindingModel : ISupplyModel
|
||||||
|
{
|
||||||
|
public int ShopId { get; set; }
|
||||||
|
public int TextileId { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IShopLogic
|
||||||
|
{
|
||||||
|
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||||
|
|
||||||
|
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||||
|
|
||||||
|
bool Create(ShopBindingModel model);
|
||||||
|
|
||||||
|
bool Update(ShopBindingModel model);
|
||||||
|
|
||||||
|
bool Delete(ShopBindingModel model);
|
||||||
|
|
||||||
|
bool MakeSupply(SupplyBindingModel model);
|
||||||
|
|
||||||
|
bool Sell(SupplySearchModel model);
|
||||||
|
}
|
||||||
|
}
|
14
GarmentFactoryContracts/SearchModels/ShopSearchModel.cs
Normal file
14
GarmentFactoryContracts/SearchModels/ShopSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ShopName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
GarmentFactoryContracts/SearchModels/SupplySearchModel.cs
Normal file
14
GarmentFactoryContracts/SearchModels/SupplySearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class SupplySearchModel
|
||||||
|
{
|
||||||
|
public int? TextileId { get; set; }
|
||||||
|
public int? Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
25
GarmentFactoryContracts/StoragesContracts/IShopStorage.cs
Normal file
25
GarmentFactoryContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IShopStorage
|
||||||
|
{
|
||||||
|
List<ShopViewModel> GetFullList();
|
||||||
|
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||||
|
ShopViewModel? GetElement(ShopSearchModel model);
|
||||||
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
//Продажа изделий в нужном кол-ве
|
||||||
|
bool Sell(SupplySearchModel model);
|
||||||
|
//Пополнение магаз-ов
|
||||||
|
bool RestockShops(SupplyBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
29
GarmentFactoryContracts/ViewModels/ShopViewModel.cs
Normal file
29
GarmentFactoryContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ShopViewModel : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Название магазина")]
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Адрес магазина")]
|
||||||
|
public string Address { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата открытия")]
|
||||||
|
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public Dictionary<int, (ITextileModel, int)> ShopTextiles { get; set; } = new();
|
||||||
|
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int TextileMaxCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
GarmentFactoryDataModels/Models/IShopModel.cs
Normal file
19
GarmentFactoryDataModels/Models/IShopModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IShopModel : IId
|
||||||
|
{
|
||||||
|
string ShopName { get; }
|
||||||
|
string Address { get; }
|
||||||
|
DateTime DateOpen { get; }
|
||||||
|
//Изделия в магазине
|
||||||
|
Dictionary<int, (ITextileModel, int)> ShopTextiles { get; }
|
||||||
|
//макс. кол-во изделий
|
||||||
|
int TextileMaxCount { get; }
|
||||||
|
}
|
||||||
|
}
|
16
GarmentFactoryDataModels/Models/ISupplyModel.cs
Normal file
16
GarmentFactoryDataModels/Models/ISupplyModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryDataModels.Models
|
||||||
|
{
|
||||||
|
//Сущность для связи многие-ко-многим между товарами и магазинами
|
||||||
|
public class ISupplyModel
|
||||||
|
{
|
||||||
|
int ShopId { get; }
|
||||||
|
int TextileId { get; }
|
||||||
|
int Count { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -14,9 +14,11 @@ namespace GarmentFactoryFileImplement
|
|||||||
private readonly string ComponentFileName = "Component.xml";
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string TextileFileName = "Textile.xml";
|
private readonly string TextileFileName = "Textile.xml";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Textile> Textiles { get; private set; }
|
public List<Textile> Textiles { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -28,12 +30,13 @@ namespace GarmentFactoryFileImplement
|
|||||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
public void SaveTextiles() => SaveData(Textiles, TextileFileName, "Textiles", x => x.GetXElement);
|
public void SaveTextiles() => SaveData(Textiles, TextileFileName, "Textiles", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Textiles = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!;
|
Textiles = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
177
GarmentFactoryFileImplement/Implements/ShopStorage.cs
Normal file
177
GarmentFactoryFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.StoragesContracts;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sell(SupplySearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null || !model.TextileId.HasValue || !model.Count.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remainingSpace = source.Shops.Select(x => x.Textiles.ContainsKey(model.TextileId.Value) ? x.Textiles[model.TextileId.Value] : 0).Sum();
|
||||||
|
|
||||||
|
if (remainingSpace < model.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var shops = source.Shops.Where(x => x.Textiles.ContainsKey(model.TextileId.Value)).OrderByDescending(x => x.Textiles[model.TextileId.Value]).ToList();
|
||||||
|
|
||||||
|
foreach (var shop in shops)
|
||||||
|
{
|
||||||
|
int residue = model.Count.Value - shop.Textiles[model.TextileId.Value];
|
||||||
|
if (residue > 0)
|
||||||
|
{
|
||||||
|
shop.Textiles.Remove(model.TextileId.Value);
|
||||||
|
shop.TextilesUpdate();
|
||||||
|
model.Count = residue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (residue == 0)
|
||||||
|
{
|
||||||
|
shop.Textiles.Remove(model.TextileId.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Textiles[model.TextileId.Value] = -residue;
|
||||||
|
}
|
||||||
|
shop.TextilesUpdate();
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
source.SaveShops();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RestockShops(SupplyBindingModel model)
|
||||||
|
{
|
||||||
|
//подсчёт свободных мест через сумму свободных мест в каждом магазине
|
||||||
|
//в каждом магазине кол-во свободных мест = макс. кол-во - занятые места
|
||||||
|
int totalFreeSpace = source.Shops
|
||||||
|
.Select(x => x.TextileMaxCount - x.ShopTextiles.Select(y => y.Value.Item2).Sum())
|
||||||
|
.Sum();
|
||||||
|
|
||||||
|
//если места не хватает
|
||||||
|
if (totalFreeSpace < model.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Shop shop in source.Shops)
|
||||||
|
{
|
||||||
|
int freeSpace = shop.TextileMaxCount - shop.ShopTextiles.Select(x => x.Value.Item2).Sum();
|
||||||
|
|
||||||
|
if (freeSpace <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeSpace = Math.Min(freeSpace, model.Count);
|
||||||
|
model.Count -= freeSpace;
|
||||||
|
|
||||||
|
if (shop.Textiles.ContainsKey(model.TextileId))
|
||||||
|
{
|
||||||
|
shop.Textiles[model.TextileId] += freeSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Textiles.Add(model.TextileId, freeSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.TextilesUpdate();
|
||||||
|
|
||||||
|
if (model.Count == 0)
|
||||||
|
{
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
GarmentFactoryFileImplement/Models/Shop.cs
Normal file
111
GarmentFactoryFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace GarmentFactoryFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
public DateTime DateOpen { get; private set; }
|
||||||
|
public Dictionary<int, int> Textiles { get; private set; } = new();
|
||||||
|
private Dictionary<int, (ITextileModel, int)>? _shopTextiles = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (ITextileModel, int)> ShopTextiles
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopTextiles == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopTextiles = Textiles.ToDictionary(x => x.Key, y => ((source.Textiles.FirstOrDefault(z => z.Id == y.Key) as ITextileModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _shopTextiles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TextileMaxCount { get; private set; }
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Address = model.Address,
|
||||||
|
DateOpen = model.DateOpen,
|
||||||
|
Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||||
|
TextileMaxCount = model.TextileMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Address = element.Element("Address")!.Value,
|
||||||
|
DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value),
|
||||||
|
Textiles = element.Element("ShopTextiles")!.Elements("ShopTextile")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)),
|
||||||
|
TextileMaxCount = Convert.ToInt32(element.Element("TextileMaxCount")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Address = model.Address;
|
||||||
|
DateOpen = model.DateOpen;
|
||||||
|
TextileMaxCount = model.TextileMaxCount;
|
||||||
|
Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopTextiles = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Address = Address,
|
||||||
|
DateOpen = DateOpen,
|
||||||
|
ShopTextiles = ShopTextiles,
|
||||||
|
TextileMaxCount = TextileMaxCount
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Address", Address),
|
||||||
|
new XElement("DateOpen", DateOpen.ToString()),
|
||||||
|
new XElement("ShopTextiles", Textiles.Select(
|
||||||
|
x => new XElement("ShopTextile", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||||
|
new XElement("TextileMaxCount", TextileMaxCount.ToString())
|
||||||
|
);
|
||||||
|
|
||||||
|
public void TextilesUpdate()
|
||||||
|
{
|
||||||
|
_shopTextiles = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,11 +8,13 @@ namespace GarmentFactoryListImplement
|
|||||||
public List<Component> Components { get; set; }
|
public List<Component> Components { get; set; }
|
||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Textile> Textiles { get; set; }
|
public List<Textile> Textiles { get; set; }
|
||||||
|
public List<Shop> Shops { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Textiles = new List<Textile>();
|
Textiles = new List<Textile>();
|
||||||
|
Shops = new List<Shop>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
124
GarmentFactoryListImplement/Implements/ShopStorage.cs
Normal file
124
GarmentFactoryListImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.SearchModels;
|
||||||
|
using GarmentFactoryContracts.StoragesContracts;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using GarmentFactoryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.ShopName.Contains(model.ShopName))
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && shop.Id == model.Id))
|
||||||
|
{
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (model.Id <= shop.Id)
|
||||||
|
{
|
||||||
|
model.Id = shop.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Shops.Add(newShop);
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.Id == model.Id)
|
||||||
|
{
|
||||||
|
shop.Update(model);
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Shops[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Shops[i];
|
||||||
|
_source.Shops.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sell(SupplySearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RestockShops(SupplyBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
GarmentFactoryListImplement/Models/Shop.cs
Normal file
66
GarmentFactoryListImplement/Models/Shop.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryListImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpen { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (ITextileModel, int)> ShopTextiles { get; private set; } = new();
|
||||||
|
|
||||||
|
public int TextileMaxCount { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Address = model.Address,
|
||||||
|
DateOpen = model.DateOpen,
|
||||||
|
ShopTextiles = model.ShopTextiles,
|
||||||
|
TextileMaxCount = model.TextileMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Address = model.Address;
|
||||||
|
DateOpen = model.DateOpen;
|
||||||
|
ShopTextiles = model.ShopTextiles;
|
||||||
|
TextileMaxCount = model.TextileMaxCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Address = Address,
|
||||||
|
DateOpen = DateOpen,
|
||||||
|
ShopTextiles = ShopTextiles,
|
||||||
|
TextileMaxCount = TextileMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user