This commit is contained in:
10Г Егор Романов 2023-03-07 13:01:38 +04:00
commit 88e7175c9c
32 changed files with 383 additions and 443 deletions

View File

@ -28,8 +28,8 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.labelManufacture = new System.Windows.Forms.Label(); this.labelSecure = new System.Windows.Forms.Label();
this.comboBoxManufacture = new System.Windows.Forms.ComboBox(); this.comboBoxSecure = new System.Windows.Forms.ComboBox();
this.labelCount = new System.Windows.Forms.Label(); this.labelCount = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox(); this.textBoxCount = new System.Windows.Forms.TextBox();
this.labelSum = new System.Windows.Forms.Label(); this.labelSum = new System.Windows.Forms.Label();
@ -38,23 +38,23 @@
this.buttonSave = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// labelManufacture // labelSecure
// //
this.labelManufacture.AutoSize = true; this.labelSecure.AutoSize = true;
this.labelManufacture.Location = new System.Drawing.Point(12, 15); this.labelSecure.Location = new System.Drawing.Point(12, 15);
this.labelManufacture.Name = "labelManufacture"; this.labelSecure.Name = "labelSecure";
this.labelManufacture.Size = new System.Drawing.Size(75, 20); this.labelSecure.Size = new System.Drawing.Size(75, 20);
this.labelManufacture.TabIndex = 0; this.labelSecure.TabIndex = 0;
this.labelManufacture.Text = "Изделие: "; this.labelSecure.Text = "Изделие: ";
// //
// comboBoxManufacture // comboBoxSecure
// //
this.comboBoxManufacture.FormattingEnabled = true; this.comboBoxSecure.FormattingEnabled = true;
this.comboBoxManufacture.Location = new System.Drawing.Point(115, 12); this.comboBoxSecure.Location = new System.Drawing.Point(115, 12);
this.comboBoxManufacture.Name = "comboBoxManufacture"; this.comboBoxSecure.Name = "comboBoxSecure";
this.comboBoxManufacture.Size = new System.Drawing.Size(358, 28); this.comboBoxSecure.Size = new System.Drawing.Size(358, 28);
this.comboBoxManufacture.TabIndex = 1; this.comboBoxSecure.TabIndex = 1;
this.comboBoxManufacture.SelectedIndexChanged += new System.EventHandler(this.ComboBoxManufacture_SelectedIndexChanged); this.comboBoxSecure.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSecure_SelectedIndexChanged);
// //
// labelCount // labelCount
// //
@ -121,8 +121,8 @@
this.Controls.Add(this.labelSum); this.Controls.Add(this.labelSum);
this.Controls.Add(this.textBoxCount); this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelCount); this.Controls.Add(this.labelCount);
this.Controls.Add(this.comboBoxManufacture); this.Controls.Add(this.comboBoxSecure);
this.Controls.Add(this.labelManufacture); this.Controls.Add(this.labelSecure);
this.Name = "FormCreateOrder"; this.Name = "FormCreateOrder";
this.Text = "Заказ"; this.Text = "Заказ";
this.Load += new System.EventHandler(this.FormCreateOrder_Load); this.Load += new System.EventHandler(this.FormCreateOrder_Load);
@ -133,8 +133,8 @@
#endregion #endregion
private Label labelManufacture; private Label labelSecure;
private ComboBox comboBoxManufacture; private ComboBox comboBoxSecure;
private Label labelCount; private Label labelCount;
private TextBox textBoxCount; private TextBox textBoxCount;
private Label labelSum; private Label labelSum;

View File

@ -18,10 +18,10 @@ namespace SecuritySystemView
public partial class FormCreateOrder : Form public partial class FormCreateOrder : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IManufactureLogic _logicM; private readonly ISecureLogic _logicM;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
private List<ManufactureViewModel>? _list; private List<SecureViewModel>? _list;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IManufactureLogic logicM, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicM, IOrderLogic logicO)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
@ -33,23 +33,23 @@ namespace SecuritySystemView
_list = _logicM.ReadList(null); _list = _logicM.ReadList(null);
if (_list != null) if (_list != null)
{ {
comboBoxManufacture.DisplayMember = "ManufactureName"; comboBoxSecure.DisplayMember = "SecureName";
comboBoxManufacture.ValueMember = "Id"; comboBoxSecure.ValueMember = "Id";
comboBoxManufacture.DataSource = _list; comboBoxSecure.DataSource = _list;
comboBoxManufacture.SelectedItem = null; comboBoxSecure.SelectedItem = null;
_logger.LogInformation("Загрузка изделий для заказа"); _logger.LogInformation("Загрузка изделий для заказа");
} }
} }
private void CalcSum() private void CalcSum()
{ {
if (comboBoxManufacture.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) if (comboBoxSecure.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{ {
try try
{ {
int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); int id = Convert.ToInt32(comboBoxSecure.SelectedValue);
var Manufacture = _logicM.ReadElement(new ManufactureSearchModel { Id = id }); var Secure = _logicM.ReadElement(new SecureSearchModel { Id = id });
int count = Convert.ToInt32(textBoxCount.Text); int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (Manufacture?.Price ?? 0), 2).ToString(); textBoxSum.Text = Math.Round(count * (Secure?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа"); _logger.LogInformation("Расчет суммы заказа");
} }
catch (Exception ex) catch (Exception ex)
@ -63,7 +63,7 @@ namespace SecuritySystemView
{ {
CalcSum(); CalcSum();
} }
private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSecure_SelectedIndexChanged(object sender, EventArgs e)
{ {
CalcSum(); CalcSum();
} }
@ -74,7 +74,7 @@ namespace SecuritySystemView
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxManufacture.SelectedValue == null) if (comboBoxSecure.SelectedValue == null)
{ {
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -84,8 +84,8 @@ namespace SecuritySystemView
{ {
var operationResult = _logicO.CreateOrder(new OrderBindingModel var operationResult = _logicO.CreateOrder(new OrderBindingModel
{ {
ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue), SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue),
ManufactureName = comboBoxManufacture.Text, SecureName = comboBoxSecure.Text,
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text)
}); });

View File

@ -37,8 +37,8 @@ namespace SecuritySystemView
if (list != null) if (list != null)
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["ManufactureId"].Visible = false; dataGridView.Columns["SecureId"].Visible = false;
dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
@ -58,8 +58,8 @@ namespace SecuritySystemView
} }
private void GoodsToolStripMenuItem_Click(object sender, EventArgs e) private void GoodsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormManufacturies)); var service = Program.ServiceProvider?.GetService(typeof(FormSecuries));
if (service is FormManufacturies form) if (service is FormSecuries form)
{ {
form.ShowDialog(); form.ShowDialog();
} }
@ -84,8 +84,8 @@ namespace SecuritySystemView
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
@ -115,8 +115,8 @@ namespace SecuritySystemView
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
@ -147,8 +147,8 @@ namespace SecuritySystemView
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = id, Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),

View File

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

View File

@ -1,6 +1,6 @@
namespace SecuritySystemView namespace SecuritySystemView
{ {
partial class FormManufacture partial class FormSecure
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -38,11 +38,11 @@
this.buttonUpd = new System.Windows.Forms.Button(); this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.groupBoxComponents.SuspendLayout(); this.groupBoxComponents.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -76,6 +76,7 @@
// //
this.textBoxPrice.Location = new System.Drawing.Point(112, 51); this.textBoxPrice.Location = new System.Drawing.Point(112, 51);
this.textBoxPrice.Name = "textBoxPrice"; this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.ReadOnly = true;
this.textBoxPrice.Size = new System.Drawing.Size(171, 27); this.textBoxPrice.Size = new System.Drawing.Size(171, 27);
this.textBoxPrice.TabIndex = 3; this.textBoxPrice.TabIndex = 3;
// //
@ -151,26 +152,6 @@
this.dataGridView.Size = new System.Drawing.Size(476, 287); this.dataGridView.Size = new System.Drawing.Size(476, 287);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
// //
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(514, 417);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(126, 34);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(368, 417);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(126, 34);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// id // id
// //
this.id.HeaderText = "id"; this.id.HeaderText = "id";
@ -193,6 +174,26 @@
this.Count.Name = "Count"; this.Count.Name = "Count";
this.Count.ReadOnly = true; this.Count.ReadOnly = true;
// //
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(514, 417);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(126, 34);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(368, 417);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(126, 34);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// FormManufacture // FormManufacture
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
@ -207,7 +208,7 @@
this.Controls.Add(this.labelName); this.Controls.Add(this.labelName);
this.Name = "FormManufacture"; this.Name = "FormManufacture";
this.Text = "Изделие"; this.Text = "Изделие";
this.Load += new System.EventHandler(this.FormManufacture_Load); this.Load += new System.EventHandler(this.FormSecure_Load);
this.groupBoxComponents.ResumeLayout(false); this.groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -16,33 +16,33 @@ using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormManufacture : Form public partial class FormSecure : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IManufactureLogic _logic; private readonly ISecureLogic _logic;
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _ManufactureComponents; private Dictionary<int, (IComponentModel, int)> _SecureComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormManufacture(ILogger<FormManufacture> logger, IManufactureLogic logic) public FormSecure(ILogger<FormSecure> logger, ISecureLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_ManufactureComponents = new Dictionary<int, (IComponentModel, int)>(); _SecureComponents = new Dictionary<int, (IComponentModel, int)>();
} }
private void FormManufacture_Load(object sender, EventArgs e) private void FormSecure_Load(object sender, EventArgs e)
{ {
if (_id.HasValue) if (_id.HasValue)
{ {
_logger.LogInformation("Загрузка изделия"); _logger.LogInformation("Загрузка изделия");
try try
{ {
var view = _logic.ReadElement(new ManufactureSearchModel { Id = _id.Value }); var view = _logic.ReadElement(new SecureSearchModel { Id = _id.Value });
if (view != null) if (view != null)
{ {
textBoxName.Text = view.ManufactureName; textBoxName.Text = view.SecureName;
textBoxPrice.Text = view.Price.ToString(); textBoxPrice.Text = view.Price.ToString();
_ManufactureComponents = view.ManufactureComponents ?? new _SecureComponents = view.SecureComponents ?? new
Dictionary<int, (IComponentModel, int)>(); Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
@ -60,10 +60,10 @@ namespace SecuritySystemView
_logger.LogInformation("Загрузка компонент изделия"); _logger.LogInformation("Загрузка компонент изделия");
try try
{ {
if (_ManufactureComponents != null) if (_SecureComponents != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _ManufactureComponents) foreach (var pc in _SecureComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
} }
@ -79,8 +79,8 @@ namespace SecuritySystemView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
if (service is FormManufactureComponent form) if (service is FormSecuriesComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -89,13 +89,13 @@ namespace SecuritySystemView
return; return;
} }
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
if (_ManufactureComponents.ContainsKey(form.Id)) if (_SecureComponents.ContainsKey(form.Id))
{ {
_ManufactureComponents[form.Id] = (form.ComponentModel, form.Count); _SecureComponents[form.Id] = (form.ComponentModel, form.Count);
} }
else else
{ {
_ManufactureComponents.Add(form.Id, (form.ComponentModel, form.Count)); _SecureComponents.Add(form.Id, (form.ComponentModel, form.Count));
} }
LoadData(); LoadData();
} }
@ -105,12 +105,12 @@ namespace SecuritySystemView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
if (service is FormManufactureComponent form) if (service is FormSecuriesComponent form)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _ManufactureComponents[id].Item2; form.Count = _SecureComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
@ -118,7 +118,7 @@ namespace SecuritySystemView
return; return;
} }
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_ManufactureComponents[form.Id] = (form.ComponentModel, form.Count); _SecureComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData(); LoadData();
} }
} }
@ -134,7 +134,7 @@ namespace SecuritySystemView
try try
{ {
_logger.LogInformation("Удаление компонента: {ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента: {ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_ManufactureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _SecureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -161,7 +161,7 @@ namespace SecuritySystemView
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (_ManufactureComponents == null || _ManufactureComponents.Count == 0) if (_SecureComponents == null || _SecureComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -169,12 +169,12 @@ namespace SecuritySystemView
_logger.LogInformation("Сохранение изделия"); _logger.LogInformation("Сохранение изделия");
try try
{ {
var model = new ManufactureBindingModel var model = new SecureBindingModel
{ {
Id = _id ?? 0, Id = _id ?? 0,
ManufactureName = textBoxName.Text, SecureName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text), Price = Convert.ToDouble(textBoxPrice.Text),
ManufactureComponents = _ManufactureComponents SecureComponents = _SecureComponents
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult) if (!operationResult)
@ -199,7 +199,7 @@ namespace SecuritySystemView
private double CalcPrice() private double CalcPrice()
{ {
double price = 0; double price = 0;
foreach (var elem in _ManufactureComponents) foreach (var elem in _SecureComponents)
{ {
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
} }

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,6 +1,6 @@
namespace SecuritySystemView namespace SecuritySystemView
{ {
partial class FormManufacturies partial class FormSecuries
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -102,16 +102,16 @@
this.dataGridView.Size = new System.Drawing.Size(590, 426); this.dataGridView.Size = new System.Drawing.Size(590, 426);
this.dataGridView.TabIndex = 2; this.dataGridView.TabIndex = 2;
// //
// FormManufacturies // FormSecure
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.ToolsPanel);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormManufacturies"; this.Name = "FormSecuries";
this.Text = "Изделия"; this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormManufacturies_Load); this.Load += new System.EventHandler(this.FormSecuries_Load);
this.ToolsPanel.ResumeLayout(false); this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -14,17 +14,17 @@ using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormManufacturies : Form public partial class FormSecuries : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IManufactureLogic _logic; private readonly ISecureLogic _logic;
public FormManufacturies(ILogger<FormManufacturies> logger, IManufactureLogic logic) public FormSecuries(ILogger<FormSecuries> logger, ISecureLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormManufacturies_Load(object sender, EventArgs e) private void FormSecuries_Load(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
@ -37,8 +37,8 @@ namespace SecuritySystemView
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ManufactureComponents"].Visible = false; dataGridView.Columns["SecureComponents"].Visible = false;
dataGridView.Columns["ManufactureName"].AutoSizeMode = dataGridView.Columns["SecureName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка изделий"); _logger.LogInformation("Загрузка изделий");
@ -51,8 +51,8 @@ namespace SecuritySystemView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); var service = Program.ServiceProvider?.GetService(typeof(FormSecure));
if (service is FormManufacture form) if (service is FormSecure form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -64,8 +64,8 @@ namespace SecuritySystemView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); var service = Program.ServiceProvider?.GetService(typeof(FormSecure));
if (service is FormManufacture form) if (service is FormSecure form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -85,7 +85,7 @@ namespace SecuritySystemView
_logger.LogInformation("Удаление изделия"); _logger.LogInformation("Удаление изделия");
try try
{ {
if (!_logic.Delete(new ManufactureBindingModel { Id = id })) if (!_logic.Delete(new SecureBindingModel { Id = id }))
{ {
throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
} }

View File

@ -1,6 +1,6 @@
namespace SecuritySystemView namespace SecuritySystemView
{ {
partial class FormManufactureComponent partial class FormSecuriesComponent
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.

View File

@ -13,7 +13,7 @@ using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormManufactureComponent : Form public partial class FormSecuriesComponent : Form
{ {
private readonly List<ComponentViewModel>? _list; private readonly List<ComponentViewModel>? _list;
public int Id public int Id
@ -50,7 +50,7 @@ namespace SecuritySystemView
get { return Convert.ToInt32(textBoxCount.Text); } get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); } set { textBoxCount.Text = value.ToString(); }
} }
public FormManufactureComponent(IComponentLogic logic) public FormSecuriesComponent(IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_list = logic.ReadList(null); _list = logic.ReadList(null);

View File

@ -38,17 +38,16 @@ namespace SecuritySystem
services.AddTransient<IComponentStorage, ComponentStorage>(); services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IManufactureStorage, ManufactureStorage>(); services.AddTransient<ISecureStorage, SecureStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IManufactureLogic, ManufactureLogic>(); services.AddTransient<ISecureLogic, SecureLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>(); services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>(); services.AddTransient<FormCreateOrder>();
services.AddTransient<FormManufacture>(); services.AddTransient<FormSecure>();
services.AddTransient<FormManufactureComponent>(); services.AddTransient<FormSecuriesComponent>();
services.AddTransient<FormManufacturies>(); services.AddTransient<FormSecuries>();
} }
} }
} }

View File

@ -6,10 +6,10 @@ namespace SecuritySystemContracts.BindingModels
public class OrderBindingModel : IOrderModel public class OrderBindingModel : IOrderModel
{ {
public int Id { get; set; } public int Id { get; set; }
public int ManufactureId { get; set; } public int SecureId { get; set; }
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public string ManufactureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }

View File

@ -3,12 +3,12 @@ using SecuritySystemDataModels.Models;
namespace SecuritySystemContracts.BindingModels namespace SecuritySystemContracts.BindingModels
{ {
public class ManufactureBindingModel : IManufactureModel public class SecureBindingModel : ISecureModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string ManufactureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ManufactureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get; get;
set; set;

View File

@ -1,21 +0,0 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BusinessLogicsContracts
{
public interface IManufactureLogic
{
List<ManufactureViewModel>? ReadList(ManufactureSearchModel? model);
ManufactureViewModel? ReadElement(ManufactureSearchModel model);
bool Create(ManufactureBindingModel model);
bool Update(ManufactureBindingModel model);
bool Delete(ManufactureBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BusinessLogicsContracts
{
public interface ISecureLogic
{
List<SecureViewModel>? ReadList(SecureSearchModel? model);
SecureViewModel? ReadElement(SecureSearchModel model);
bool Create(SecureBindingModel model);
bool Update(SecureBindingModel model);
bool Delete(SecureBindingModel model);
}
}

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels namespace SecuritySystemContracts.SearchModels
{ {
public class ManufactureSearchModel public class SecureSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? ManufactureName { get; set; } public string? SecureName { get; set; }
} }
} }

View File

@ -1,21 +0,0 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts
{
public interface IManufactureStorage
{
List<ManufactureViewModel> GetFullList();
List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model);
ManufactureViewModel? GetElement(ManufactureSearchModel model);
ManufactureViewModel? Insert(ManufactureBindingModel model);
ManufactureViewModel? Update(ManufactureBindingModel model);
ManufactureViewModel? Delete(ManufactureBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts
{
public interface ISecureStorage
{
List<SecureViewModel> GetFullList();
List<SecureViewModel> GetFilteredList(SecureSearchModel model);
SecureViewModel? GetElement(SecureSearchModel model);
SecureViewModel? Insert(SecureBindingModel model);
SecureViewModel? Update(SecureBindingModel model);
SecureViewModel? Delete(SecureBindingModel model);
}
}

View File

@ -13,9 +13,9 @@ namespace SecuritySystemContracts.ViewModels
{ {
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int ManufactureId { get; set; } public int SecureId { get; set; }
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string ManufactureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]

View File

@ -8,14 +8,14 @@ using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class ManufactureViewModel : IManufactureModel public class SecureViewModel : ISecureModel
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название изделия")] [DisplayName("Название изделия")]
public string ManufactureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public double Price { get; set; } public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> ManufactureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get; get;
set; set;

View File

@ -10,7 +10,7 @@ namespace SecuritySystemDataModels.Models
{ {
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int ManufactureId { get; } int SecureId { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }

View File

@ -7,10 +7,10 @@ using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models namespace SecuritySystemDataModels.Models
{ {
public interface IManufactureModel : IId public interface ISecureModel : IId
{ {
string ManufactureName { get; } string SecureName { get; }
double Price { get; } double Price { get; }
Dictionary<int, (IComponentModel, int)> ManufactureComponents { get; } Dictionary<int, (IComponentModel, int)> SecureComponents { get; }
} }
} }

View File

@ -13,12 +13,12 @@ namespace SecuritySystemListImplement
private static DataListSingleton? _instance; private static DataListSingleton? _instance;
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<Manufacture> Manufactures { get; set; } public List<Secure> Securies { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Manufactures = new List<Manufacture>(); Securies = new List<Secure>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@ -1,102 +0,0 @@
using SecuritySystemListImplement.Models;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemListImplement.Implements
{
public class ManufactureStorage : IManufactureStorage
{
private readonly DataListSingleton _source;
public ManufactureStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ManufactureViewModel> GetFullList()
{
var result = new List<ManufactureViewModel>();
foreach (var Manufacture in _source.Manufactures)
{
result.Add(Manufacture.GetViewModel);
}
return result;
}
public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model)
{
var result = new List<ManufactureViewModel>();
if (string.IsNullOrEmpty(model.ManufactureName))
{
return result;
}
foreach (var Manufacture in _source.Manufactures)
{
if (Manufacture.ManufactureName.Contains(model.ManufactureName))
{
result.Add(Manufacture.GetViewModel);
}
}
return result;
}
public ManufactureViewModel? GetElement(ManufactureSearchModel model)
{
if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue)
{
return null;
}
foreach (var Manufacture in _source.Manufactures)
{
if ((!string.IsNullOrEmpty(model.ManufactureName) && Manufacture.ManufactureName == model.ManufactureName) ||
(model.Id.HasValue && Manufacture.Id == model.Id))
{
return Manufacture.GetViewModel;
}
}
return null;
}
public ManufactureViewModel? Insert(ManufactureBindingModel model)
{
model.Id = 1;
foreach (var Manufacture in _source.Manufactures)
{
if (model.Id <= Manufacture.Id)
{
model.Id = Manufacture.Id + 1;
}
}
var newManufacture = Manufacture.Create(model);
if (newManufacture == null)
{
return null;
}
_source.Manufactures.Add(newManufacture);
return newManufacture.GetViewModel;
}
public ManufactureViewModel? Update(ManufactureBindingModel model)
{
foreach (var Manufacture in _source.Manufactures)
{
if (Manufacture.Id == model.Id)
{
Manufacture.Update(model);
return Manufacture.GetViewModel;
}
}
return null;
}
public ManufactureViewModel? Delete(ManufactureBindingModel model)
{
for (int i = 0; i < _source.Manufactures.Count; ++i)
{
if (_source.Manufactures[i].Id == model.Id)
{
var element = _source.Manufactures[i];
_source.Manufactures.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -98,13 +98,13 @@ namespace OrdersShopListImplement.Implements
} }
return null; return null;
} }
private OrderViewModel AttachManufactureName(OrderViewModel model) private OrderViewModel AttachSecureName(OrderViewModel model)
{ {
foreach (var manufacture in _source.Manufactures) foreach (var secure in _source.Securies)
{ {
if (manufacture.Id == model.ManufactureId) if (secure.Id == model.SecureId)
{ {
model.ManufactureName = manufacture.ManufactureName; model.SecureName = secure.SecureName;
return model; return model;
} }
} }

View File

@ -0,0 +1,102 @@
using SecuritySystemListImplement.Models;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemListImplement.Implements
{
public class SecureStorage : ISecureStorage
{
private readonly DataListSingleton _source;
public SecureStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<SecureViewModel> GetFullList()
{
var result = new List<SecureViewModel>();
foreach (var Secure in _source.Securies)
{
result.Add(Secure.GetViewModel);
}
return result;
}
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
{
var result = new List<SecureViewModel>();
if (string.IsNullOrEmpty(model.SecureName))
{
return result;
}
foreach (var Secure in _source.Securies)
{
if (Secure.SecureName.Contains(model.SecureName))
{
result.Add(Secure.GetViewModel);
}
}
return result;
}
public SecureViewModel? GetElement(SecureSearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
{
return null;
}
foreach (var Secure in _source.Securies)
{
if ((!string.IsNullOrEmpty(model.SecureName) && Secure.SecureName == model.SecureName) ||
(model.Id.HasValue && Secure.Id == model.Id))
{
return Secure.GetViewModel;
}
}
return null;
}
public SecureViewModel? Insert(SecureBindingModel model)
{
model.Id = 1;
foreach (var Secure in _source.Securies)
{
if (model.Id <= Secure.Id)
{
model.Id = Secure.Id + 1;
}
}
var newSecure = Secure.Create(model);
if (newSecure == null)
{
return null;
}
_source.Securies.Add(newSecure);
return newSecure.GetViewModel;
}
public SecureViewModel? Update(SecureBindingModel model)
{
foreach (var Secure in _source.Securies)
{
if (Secure.Id == model.Id)
{
Secure.Update(model);
return Secure.GetViewModel;
}
}
return null;
}
public SecureViewModel? Delete(SecureBindingModel model)
{
for (int i = 0; i < _source.Securies.Count; ++i)
{
if (_source.Securies[i].Id == model.Id)
{
var element = _source.Securies[i];
_source.Securies.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -10,46 +10,46 @@ using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.Models namespace SecuritySystemListImplement.Models
{ {
public class Manufacture : IManufactureModel public class Secure : ISecureModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ManufactureName { get; private set; } = string.Empty; public string SecureName { get; private set; } = string.Empty;
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> ManufactureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get; get;
private set; private set;
} = new Dictionary<int, (IComponentModel, int)>(); } = new Dictionary<int, (IComponentModel, int)>();
public static Manufacture? Create(ManufactureBindingModel? model) public static Secure? Create(SecureBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
return null; return null;
} }
return new Manufacture() return new Secure()
{ {
Id = model.Id, Id = model.Id,
ManufactureName = model.ManufactureName, SecureName = model.SecureName,
Price = model.Price, Price = model.Price,
ManufactureComponents = model.ManufactureComponents SecureComponents = model.SecureComponents
}; };
} }
public void Update(ManufactureBindingModel? model) public void Update(SecureBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
return; return;
} }
ManufactureName = model.ManufactureName; SecureName = model.SecureName;
Price = model.Price; Price = model.Price;
ManufactureComponents = model.ManufactureComponents; SecureComponents = model.SecureComponents;
} }
public ManufactureViewModel GetViewModel => new() public SecureViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ManufactureName = ManufactureName, SecureName = SecureName,
Price = Price, Price = Price,
ManufactureComponents = ManufactureComponents SecureComponents = SecureComponents
}; };
} }
} }

View File

@ -75,9 +75,9 @@ namespace SecuritySystemBusinessLogic
{ {
return; return;
} }
if (model.ManufactureId < 0) if (model.SecureId < 0)
{ {
throw new ArgumentNullException("Некорректный идентификатор камеры", nameof(model.ManufactureId)); throw new ArgumentNullException("Некорректный идентификатор камеры", nameof(model.SecureId));
} }
if (model.Count <= 0) if (model.Count <= 0)
{ {
@ -87,7 +87,7 @@ namespace SecuritySystemBusinessLogic
{ {
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
} }
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. ManufactureId: { ManufactureId}", model.Id, model.Sum, model.ManufactureId); _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. SecureId: { SecureId}", model.Id, model.Sum, model.SecureId);
} }
private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true) private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true)

View File

@ -8,21 +8,21 @@ using Microsoft.Extensions.Logging;
namespace SecuritySystemBusinessLogic namespace SecuritySystemBusinessLogic
{ {
public class ManufactureLogic : IManufactureLogic public class SecureLogic : ISecureLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IManufactureStorage _ManufactureStorage; private readonly ISecureStorage _SecureStorage;
public ManufactureLogic(ILogger<ManufactureLogic> logger, IManufactureStorage ManufactureStorage) public SecureLogic(ILogger<SecureLogic> logger, ISecureStorage SecureStorage)
{ {
_logger = logger; _logger = logger;
_ManufactureStorage = ManufactureStorage; _SecureStorage = SecureStorage;
} }
public List<ManufactureViewModel>? ReadList(ManufactureSearchModel? model) public List<SecureViewModel>? ReadList(SecureSearchModel? model)
{ {
_logger.LogInformation("ReadList. ManufactureName:{ManufactureName}.Id:{ Id}", model?.ManufactureName, model?.Id); _logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{ Id}", model?.SecureName, model?.Id);
var list = model == null ? _ManufactureStorage.GetFullList() : _ManufactureStorage.GetFilteredList(model); var list = model == null ? _SecureStorage.GetFullList() : _SecureStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
@ -32,14 +32,14 @@ namespace SecuritySystemBusinessLogic
return list; return list;
} }
public ManufactureViewModel? ReadElement(ManufactureSearchModel model) public SecureViewModel? ReadElement(SecureSearchModel model)
{ {
if (model == null) if (model == null)
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation("ReadElement. ManufactureName:{ManufactureName}.Id:{ Id}", model.ManufactureName, model.Id); _logger.LogInformation("ReadElement. SecureName:{SecureName}.Id:{ Id}", model.SecureName, model.Id);
var element = _ManufactureStorage.GetElement(model); var element = _SecureStorage.GetElement(model);
if (element == null) if (element == null)
{ {
_logger.LogWarning("ReadElement element not found"); _logger.LogWarning("ReadElement element not found");
@ -49,10 +49,10 @@ namespace SecuritySystemBusinessLogic
return element; return element;
} }
public bool Create(ManufactureBindingModel model) public bool Create(SecureBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_ManufactureStorage.Insert(model) == null) if (_SecureStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
@ -60,10 +60,10 @@ namespace SecuritySystemBusinessLogic
return true; return true;
} }
public bool Update(ManufactureBindingModel model) public bool Update(SecureBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_ManufactureStorage.Update(model) == null) if (_SecureStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
@ -71,11 +71,11 @@ namespace SecuritySystemBusinessLogic
return true; return true;
} }
public bool Delete(ManufactureBindingModel model) public bool Delete(SecureBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id); _logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_ManufactureStorage.Delete(model) == null) if (_SecureStorage.Delete(model) == null)
{ {
_logger.LogWarning("Delete operation failed"); _logger.LogWarning("Delete operation failed");
return false; return false;
@ -83,7 +83,7 @@ namespace SecuritySystemBusinessLogic
return true; return true;
} }
private void CheckModel(ManufactureBindingModel model, bool withParams = true) private void CheckModel(SecureBindingModel model, bool withParams = true)
{ {
if (model == null) if (model == null)
{ {
@ -93,18 +93,18 @@ namespace SecuritySystemBusinessLogic
{ {
return; return;
} }
if (string.IsNullOrEmpty(model.ManufactureName)) if (string.IsNullOrEmpty(model.SecureName))
{ {
throw new ArgumentNullException("Нет названия камеры", nameof(model.ManufactureName)); throw new ArgumentNullException("Нет названия камеры", nameof(model.SecureName));
} }
if (model.Price <= 0) if (model.Price <= 0)
{ {
throw new ArgumentNullException("Цена камеры должна быть больше 0", nameof(model.Price)); throw new ArgumentNullException("Цена камеры должна быть больше 0", nameof(model.Price));
} }
_logger.LogInformation("Manufacture. ManufactureName:{ManufactureName}.Cost:{ Cost}. Id: { Id}", model.ManufactureName, model.Price, model.Id); _logger.LogInformation("Secure. SecureName:{SecureName}.Cost:{ Cost}. Id: { Id}", model.SecureName, model.Price, model.Id);
var element = _ManufactureStorage.GetElement(new ManufactureSearchModel var element = _SecureStorage.GetElement(new SecureSearchModel
{ {
ManufactureName = model.ManufactureName SecureName = model.SecureName
}); });
if (element != null && element.Id != model.Id) if (element != null && element.Id != model.Id)
{ {