This commit is contained in:
10Г Егор Романов 2023-03-07 12:47:29 +04:00
parent ba933bf7f3
commit 21274bfbf0
34 changed files with 326 additions and 536 deletions

View File

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

View File

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

View File

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

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
{
partial class FormManufacture
partial class FormSecure
{
/// <summary>
/// Required designer variable.
@ -38,11 +38,11 @@
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
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.Component = 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();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -76,6 +76,7 @@
//
this.textBoxPrice.Location = new System.Drawing.Point(112, 51);
this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.ReadOnly = true;
this.textBoxPrice.Size = new System.Drawing.Size(171, 27);
this.textBoxPrice.TabIndex = 3;
//
@ -151,26 +152,6 @@
this.dataGridView.Size = new System.Drawing.Size(476, 287);
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
//
this.id.HeaderText = "id";
@ -193,6 +174,26 @@
this.Count.Name = "Count";
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
@ -207,7 +208,7 @@
this.Controls.Add(this.labelName);
this.Name = "FormManufacture";
this.Text = "Изделие";
this.Load += new System.EventHandler(this.FormManufacture_Load);
this.Load += new System.EventHandler(this.FormSecure_Load);
this.groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);

View File

@ -16,33 +16,33 @@ using System.Windows.Forms;
namespace SecuritySystemView
{
public partial class FormManufacture : Form
public partial class FormSecure : Form
{
private readonly ILogger _logger;
private readonly IManufactureLogic _logic;
private readonly ISecureLogic _logic;
private int? _id;
private Dictionary<int, (IComponentModel, int)> _ManufactureComponents;
private Dictionary<int, (IComponentModel, int)> _SecureComponents;
public int Id { set { _id = value; } }
public FormManufacture(ILogger<FormManufacture> logger, IManufactureLogic logic)
public FormSecure(ILogger<FormSecure> logger, ISecureLogic logic)
{
InitializeComponent();
_logger = logger;
_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)
{
_logger.LogInformation("Загрузка изделия");
try
{
var view = _logic.ReadElement(new ManufactureSearchModel { Id = _id.Value });
var view = _logic.ReadElement(new SecureSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ManufactureName;
textBoxName.Text = view.SecureName;
textBoxPrice.Text = view.Price.ToString();
_ManufactureComponents = view.ManufactureComponents ?? new
_SecureComponents = view.SecureComponents ?? new
Dictionary<int, (IComponentModel, int)>();
LoadData();
}
@ -60,10 +60,10 @@ namespace SecuritySystemView
_logger.LogInformation("Загрузка компонент изделия");
try
{
if (_ManufactureComponents != null)
if (_SecureComponents != null)
{
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 });
}
@ -79,8 +79,8 @@ namespace SecuritySystemView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent));
if (service is FormManufactureComponent form)
var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
if (service is FormSecuriesComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
@ -89,13 +89,13 @@ namespace SecuritySystemView
return;
}
_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
{
_ManufactureComponents.Add(form.Id, (form.ComponentModel, form.Count));
_SecureComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
@ -105,12 +105,12 @@ namespace SecuritySystemView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent));
if (service is FormManufactureComponent form)
var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
if (service is FormSecuriesComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _ManufactureComponents[id].Item2;
form.Count = _SecureComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
@ -118,7 +118,7 @@ namespace SecuritySystemView
return;
}
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_ManufactureComponents[form.Id] = (form.ComponentModel, form.Count);
_SecureComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
@ -134,7 +134,7 @@ namespace SecuritySystemView
try
{
_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)
{
@ -161,7 +161,7 @@ namespace SecuritySystemView
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_ManufactureComponents == null || _ManufactureComponents.Count == 0)
if (_SecureComponents == null || _SecureComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
@ -169,12 +169,12 @@ namespace SecuritySystemView
_logger.LogInformation("Сохранение изделия");
try
{
var model = new ManufactureBindingModel
var model = new SecureBindingModel
{
Id = _id ?? 0,
ManufactureName = textBoxName.Text,
SecureName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
ManufactureComponents = _ManufactureComponents
SecureComponents = _SecureComponents
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
@ -199,7 +199,7 @@ namespace SecuritySystemView
private double CalcPrice()
{
double price = 0;
foreach (var elem in _ManufactureComponents)
foreach (var elem in _SecureComponents)
{
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
{
partial class FormManufacturies
partial class FormSecuries
{
/// <summary>
/// Required designer variable.
@ -102,16 +102,16 @@
this.dataGridView.Size = new System.Drawing.Size(590, 426);
this.dataGridView.TabIndex = 2;
//
// FormManufacturies
// FormSecure
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel);
this.Controls.Add(this.dataGridView);
this.Name = "FormManufacturies";
this.Name = "FormSecuries";
this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormManufacturies_Load);
this.Load += new System.EventHandler(this.FormSecuries_Load);
this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);

View File

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

View File

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

View File

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

View File

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

View File

@ -6,10 +6,10 @@ namespace SecuritySystemContracts.BindingModels
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int ManufactureId { get; set; }
public int SecureId { get; set; }
public int Count { 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 DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }

View File

@ -3,12 +3,12 @@ using SecuritySystemDataModels.Models;
namespace SecuritySystemContracts.BindingModels
{
public class ManufactureBindingModel : IManufactureModel
public class SecureBindingModel : ISecureModel
{
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 Dictionary<int, (IComponentModel, int)> ManufactureComponents
public Dictionary<int, (IComponentModel, int)> SecureComponents
{
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.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
{
public class ManufactureSearchModel
public class SecureSearchModel
{
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("Номер")]
public int Id { get; set; }
public int ManufactureId { get; set; }
public int SecureId { get; set; }
[DisplayName("Изделие")]
public string ManufactureName { get; set; } = string.Empty;
public string SecureName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]

View File

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

View File

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

View File

@ -7,10 +7,10 @@ using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models
{
public interface IManufactureModel : IId
public interface ISecureModel : IId
{
string ManufactureName { get; }
string SecureName { 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;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Manufacture> Manufactures { get; set; }
public List<Secure> Securies { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Manufactures = new List<Manufacture>();
Securies = new List<Secure>();
}
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;
}
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;
}
}

View File

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

View File

@ -1,55 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
namespace SecuritySystemListImplement.Models
{
public class Manufacture : IManufactureModel
{
public int Id { get; private set; }
public string ManufactureName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> ManufactureComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Manufacture? Create(ManufactureBindingModel? model)
{
if (model == null)
{
return null;
}
return new Manufacture()
{
Id = model.Id,
ManufactureName = model.ManufactureName,
Price = model.Price,
ManufactureComponents = model.ManufactureComponents
};
}
public void Update(ManufactureBindingModel? model)
{
if (model == null)
{
return;
}
ManufactureName = model.ManufactureName;
Price = model.Price;
ManufactureComponents = model.ManufactureComponents;
}
public ManufactureViewModel GetViewModel => new()
{
Id = Id,
ManufactureName = ManufactureName,
Price = Price,
ManufactureComponents = ManufactureComponents
};
}
}

View File

@ -15,9 +15,9 @@ namespace SecuritySystemListImplement.Models
{
public int Id { get; private set; }
public int ManufactureId { get; private set; }
public int SecureId { get; private set; }
public string ManufactureName { get; private set; } = string.Empty;
public string SecureName { get; private set; } = string.Empty;
public int Count { get; private set; }
public double Sum { get; private set; }
@ -36,7 +36,13 @@ namespace SecuritySystemListImplement.Models
}
return new Order()
{
Id = model.Id,
SecureId = model.SecureId,
SecureName = model.SecureName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
@ -47,14 +53,15 @@ namespace SecuritySystemListImplement.Models
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ManufactureId = ManufactureId,
ManufactureName = ManufactureName,
SecureId = SecureId,
SecureName = SecureName,
Count = Count,
Sum = Sum,
Status = Status,

View File

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

View File

@ -75,9 +75,9 @@ namespace SecuritySystemBusinessLogic
{
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)
{
@ -87,7 +87,7 @@ namespace SecuritySystemBusinessLogic
{
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)

View File

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