Compare commits

...

1 Commits

Author SHA1 Message Date
e8a62f7cc5 labwork1 2024-05-07 15:10:34 +04:00
60 changed files with 4618 additions and 77 deletions

View File

@ -5,6 +5,14 @@ VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystem", "SecuritySystem\SecuritySystem.csproj", "{0548AE9D-59FF-4288-A519-85FF31627D7E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDataModels", "SecuritySystemDataModels\SecuritySystemDataModels.csproj", "{0A4860B4-91DC-4174-A4A5-789729F0E206}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogiс", "SecuritySystemBusinessLogiс\SecuritySystemBusinessLogiс.csproj", "{4A8ECDB2-CD12-4A42-8580-C75F044851A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemContracts", "SecuritySystemContracts\SecuritySystemContracts.csproj", "{96317F35-0916-4563-B898-069D6EC0B303}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{EEFB1807-2668-4DBF-80A0-06594D2C811C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +23,22 @@ Global
{0548AE9D-59FF-4288-A519-85FF31627D7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0548AE9D-59FF-4288-A519-85FF31627D7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0548AE9D-59FF-4288-A519-85FF31627D7E}.Release|Any CPU.Build.0 = Release|Any CPU
{0A4860B4-91DC-4174-A4A5-789729F0E206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A4860B4-91DC-4174-A4A5-789729F0E206}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A4860B4-91DC-4174-A4A5-789729F0E206}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A4860B4-91DC-4174-A4A5-789729F0E206}.Release|Any CPU.Build.0 = Release|Any CPU
{4A8ECDB2-CD12-4A42-8580-C75F044851A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A8ECDB2-CD12-4A42-8580-C75F044851A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A8ECDB2-CD12-4A42-8580-C75F044851A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A8ECDB2-CD12-4A42-8580-C75F044851A0}.Release|Any CPU.Build.0 = Release|Any CPU
{96317F35-0916-4563-B898-069D6EC0B303}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96317F35-0916-4563-B898-069D6EC0B303}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96317F35-0916-4563-B898-069D6EC0B303}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96317F35-0916-4563-B898-069D6EC0B303}.Release|Any CPU.Build.0 = Release|Any CPU
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEFB1807-2668-4DBF-80A0-06594D2C811C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,39 +0,0 @@
namespace SecuritySystem
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace SecuritySystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,148 @@
namespace SecuritySystem
{
partial class FormCreateOrder
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonCancel = new Button();
buttonSave = new Button();
textBoxSum = new TextBox();
textBoxCount = new TextBox();
comboBoxSecure = new ComboBox();
labelSum = new Label();
labelCount = new Label();
labelSecure = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(302, 115);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 15;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(205, 115);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 14;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// textBoxSum
//
textBoxSum.Location = new Point(149, 81);
textBoxSum.Margin = new Padding(3, 2, 3, 2);
textBoxSum.Name = "textBoxSum";
textBoxSum.Size = new Size(244, 23);
textBoxSum.TabIndex = 13;
//
// textBoxCount
//
textBoxCount.Location = new Point(149, 49);
textBoxCount.Margin = new Padding(3, 2, 3, 2);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(244, 23);
textBoxCount.TabIndex = 12;
textBoxCount.TextChanged += TextBoxCount_TextChanged;
//
// comboBoxSecure
//
comboBoxSecure.FormattingEnabled = true;
comboBoxSecure.Location = new Point(149, 15);
comboBoxSecure.Margin = new Padding(3, 2, 3, 2);
comboBoxSecure.Name = "comboBoxSecure";
comboBoxSecure.Size = new Size(244, 23);
comboBoxSecure.TabIndex = 11;
comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged;
//
// labelSum
//
labelSum.AutoSize = true;
labelSum.Location = new Point(25, 84);
labelSum.Name = "labelSum";
labelSum.Size = new Size(48, 15);
labelSum.TabIndex = 10;
labelSum.Text = "Сумма:";
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(25, 51);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 9;
labelCount.Text = "Количество:";
//
// labelSecure
//
labelSecure.AutoSize = true;
labelSecure.Location = new Point(25, 17);
labelSecure.Name = "labelSecure";
labelSecure.Size = new Size(56, 15);
labelSecure.TabIndex = 8;
labelSecure.Text = "Изделие:";
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(419, 152);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxSum);
Controls.Add(textBoxCount);
Controls.Add(comboBoxSecure);
Controls.Add(labelSum);
Controls.Add(labelCount);
Controls.Add(labelSecure);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxSum;
private TextBox textBoxCount;
private ComboBox comboBoxSecure;
private Label labelSum;
private Label labelCount;
private Label labelSecure;
}
}

View File

@ -0,0 +1,146 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISecureLogic _logicM;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicM, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicM = logicM;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка изделий для заказа");
try
{
var list = _logicM.ReadList(null);
if (list != null)
{
comboBoxSecure.DisplayMember = "SecureName";
comboBoxSecure.ValueMember = "Id";
comboBoxSecure.DataSource = list;
comboBoxSecure.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий для заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxSecure.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
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 * (secure?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxSecure_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSecure.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,178 @@
namespace SecuritySystem
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonRef = new Button();
buttonIssuedOrder = new Button();
buttonOrderReady = new Button();
buttonTakeOrderInWork = new Button();
buttonCreateOrder = new Button();
dataGridView = new DataGridView();
menuStrip1 = new MenuStrip();
toolStripMenuItem = new ToolStripMenuItem();
SensorToolStripMenuItem = new ToolStripMenuItem();
SecureToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// buttonRef
//
buttonRef.Location = new Point(887, 282);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(206, 22);
buttonRef.TabIndex = 12;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(887, 227);
buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(206, 22);
buttonIssuedOrder.TabIndex = 11;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(887, 170);
buttonOrderReady.Margin = new Padding(3, 2, 3, 2);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(206, 22);
buttonOrderReady.TabIndex = 10;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(887, 112);
buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(206, 22);
buttonTakeOrderInWork.TabIndex = 9;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(887, 55);
buttonCreateOrder.Margin = new Padding(3, 2, 3, 2);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(206, 22);
buttonCreateOrder.TabIndex = 8;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(10, 32);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(820, 302);
dataGridView.TabIndex = 7;
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(5, 2, 0, 2);
menuStrip1.Size = new Size(1135, 24);
menuStrip1.TabIndex = 13;
menuStrip1.Text = "menuStrip1";
//
// toolStripMenuItem
//
toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SensorToolStripMenuItem, SecureToolStripMenuItem });
toolStripMenuItem.Name = "toolStripMenuItem";
toolStripMenuItem.Size = new Size(94, 20);
toolStripMenuItem.Text = "Справочники";
//
// SensorToolStripMenuItem
//
SensorToolStripMenuItem.Name = "SensorToolStripMenuItem";
SensorToolStripMenuItem.Size = new Size(180, 22);
SensorToolStripMenuItem.Text = "Заготовки";
SensorToolStripMenuItem.Click += SensorToolStripMenuItem_Click;
//
// SecureToolStripMenuItem
//
SecureToolStripMenuItem.Name = "SecureToolStripMenuItem";
SecureToolStripMenuItem.Size = new Size(180, 22);
SecureToolStripMenuItem.Text = "Изделия";
SecureToolStripMenuItem.Click += SecureToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1135, 338);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
Name = "FormMain";
Text = "SecuritySystem";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonRef;
private Button buttonIssuedOrder;
private Button buttonOrderReady;
private Button buttonTakeOrderInWork;
private Button buttonCreateOrder;
private DataGridView dataGridView;
private MenuStrip menuStrip1;
private ToolStripMenuItem toolStripMenuItem;
private ToolStripMenuItem SensorToolStripMenuItem;
private ToolStripMenuItem SecureToolStripMenuItem;
}
}

View File

@ -0,0 +1,186 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Çàãðóçêà çàêàçîâ");
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SecureId"].Visible = false;
}
_logger.LogInformation("Çàãðóçêà çàêàçîâ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà çàãðóçêè çàêàçîâ");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SensorToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSensors));
if (service is FormSensors form)
{
form.ShowDialog();
}
}
private void SecureToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecures));
if (service is FormSecures form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Â ðàáîòå'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id
});
if (!operationResult)
{
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà ïåðåäà÷è çàêàçà â ðàáîòó");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Ãîòîâ'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id
});
if (!operationResult)
{
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà îòìåòêè î ãîòîâíîñòè çàêàçà");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Âûäàí'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = id
});
if (!operationResult)
{
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
}
_logger.LogInformation("Çàêàç ¹{id} âûäàí", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Îøèáêà îòìåòêè î âûäà÷è çàêàçà");
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

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

View File

@ -0,0 +1,239 @@
namespace SecuritySystem
{
partial class FormSecure
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBoxSensor = new GroupBox();
buttonRef = new Button();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
ColumnID = new DataGridViewTextBoxColumn();
ColumnName = new DataGridViewTextBoxColumn();
ColumnPrice = new DataGridViewTextBoxColumn();
textBoxPrice = new TextBox();
textBoxName = new TextBox();
labelCost = new Label();
labelName = new Label();
buttonCancel = new Button();
buttonSave = new Button();
groupBoxSensor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// groupBoxSensor
//
groupBoxSensor.Controls.Add(buttonRef);
groupBoxSensor.Controls.Add(buttonDel);
groupBoxSensor.Controls.Add(buttonUpd);
groupBoxSensor.Controls.Add(buttonAdd);
groupBoxSensor.Controls.Add(dataGridView);
groupBoxSensor.Location = new Point(23, 92);
groupBoxSensor.Margin = new Padding(3, 2, 3, 2);
groupBoxSensor.Name = "groupBoxSensor";
groupBoxSensor.Padding = new Padding(3, 2, 3, 2);
groupBoxSensor.Size = new Size(496, 225);
groupBoxSensor.TabIndex = 11;
groupBoxSensor.TabStop = false;
groupBoxSensor.Text = "Заготовки";
//
// buttonRef
//
buttonRef.Location = new Point(397, 147);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(82, 22);
buttonRef.TabIndex = 4;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonDel
//
buttonDel.Location = new Point(397, 109);
buttonDel.Margin = new Padding(3, 2, 3, 2);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(82, 22);
buttonDel.TabIndex = 3;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(397, 71);
buttonUpd.Margin = new Padding(3, 2, 3, 2);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(82, 22);
buttonUpd.TabIndex = 2;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(397, 32);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(82, 22);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnName, ColumnPrice });
dataGridView.Location = new Point(5, 20);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(382, 201);
dataGridView.TabIndex = 0;
//
// ColumnID
//
ColumnID.HeaderText = "Id";
ColumnID.MinimumWidth = 6;
ColumnID.Name = "ColumnID";
ColumnID.Visible = false;
ColumnID.Width = 125;
//
// ColumnName
//
ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnName.HeaderText = "Название";
ColumnName.MinimumWidth = 6;
ColumnName.Name = "ColumnName";
//
// ColumnPrice
//
ColumnPrice.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnPrice.HeaderText = "Количество";
ColumnPrice.MinimumWidth = 6;
ColumnPrice.Name = "ColumnPrice";
//
// textBoxPrice
//
textBoxPrice.Location = new Point(119, 59);
textBoxPrice.Margin = new Padding(3, 2, 3, 2);
textBoxPrice.Name = "textBoxPrice";
textBoxPrice.Size = new Size(172, 23);
textBoxPrice.TabIndex = 10;
//
// textBoxName
//
textBoxName.Location = new Point(119, 18);
textBoxName.Margin = new Padding(3, 2, 3, 2);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(291, 23);
textBoxName.TabIndex = 9;
//
// labelCost
//
labelCost.AutoSize = true;
labelCost.Location = new Point(23, 61);
labelCost.Name = "labelCost";
labelCost.Size = new Size(70, 15);
labelCost.TabIndex = 8;
labelCost.Text = "Стоимость:";
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(23, 20);
labelName.Name = "labelName";
labelName.Size = new Size(62, 15);
labelName.TabIndex = 7;
labelName.Text = "Название:";
//
// buttonCancel
//
buttonCancel.Location = new Point(404, 334);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 13;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(301, 334);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(83, 22);
buttonSave.TabIndex = 12;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// FormSecure
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(542, 375);
Controls.Add(groupBoxSensor);
Controls.Add(textBoxPrice);
Controls.Add(textBoxName);
Controls.Add(labelCost);
Controls.Add(labelName);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Name = "FormSecure";
Text = "Изделие";
Click += FormSecure_Load;
groupBoxSensor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private GroupBox groupBoxSensor;
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn ColumnID;
private DataGridViewTextBoxColumn ColumnName;
private DataGridViewTextBoxColumn ColumnPrice;
private TextBox textBoxPrice;
private TextBox textBoxName;
private Label labelCost;
private Label labelName;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,246 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormSecure : Form
{
private readonly ILogger _logger;
private readonly ISecureLogic _logic;
private int? _id;
private Dictionary<int, (ISensorModel, int)> _secureSensors;
public int Id { set { _id = value; } }
public FormSecure(ILogger<FormSecure> logger, ISecureLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_secureSensors = new Dictionary<int, (ISensorModel, int)>();
}
private void FormSecure_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка изделия");
try
{
var view = _logic.ReadElement(new SecureSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.SecureName;
textBoxPrice.Text = view.Price.ToString();
_secureSensors = view.SecureSensors ?? new Dictionary<int, (ISensorModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка заготовок для изделия");
try
{
if (_secureSensors != null)
{
dataGridView.Rows.Clear();
foreach (var awp in _secureSensors)
{
dataGridView.Rows.Add(new object[] { awp.Key, awp.Value.Item1.SensorName, awp.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заготовки для изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecureSensor));
if (service is FormSecureSensor form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.SensorModel == null)
{
return;
}
_logger.LogInformation("Добавление новой заготовки:{SensorName} - {Count}", form.SensorModel.SensorName, form.Count);
if (_secureSensors.ContainsKey(form.Id))
{
_secureSensors[form.Id] = (form.SensorModel, form.Count);
}
else
{
_secureSensors.Add(form.Id, (form.SensorModel, form.Count));
}
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecureSensor));
if (service is FormSecureSensor form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _secureSensors[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.SensorModel == null)
{
return;
}
_logger.LogInformation("Изменение компонента:{SensorName} - {Count}", form.SensorModel.SensorName, form.Count);
_secureSensors[form.Id] = (form.SensorModel, form.Count);
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление заготовки:{SensorName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_secureSensors?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_secureSensors == null || _secureSensors.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение изделия");
try
{
var model = new SecureBindingModel
{
Id = _id ?? 0,
SecureName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
SecureSensors = _secureSensors
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
//в конце умножить на 1.1, так как прибавляем к итоговой стоимости некоторый процент (в данном случае 10%)
private double CalcPrice()
{
double price = 0;
foreach (var elem in _secureSensors)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
}
}

View File

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

View File

@ -0,0 +1,122 @@
namespace SecuritySystem
{
partial class FormSecureSensor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonCancel = new Button();
buttonSave = new Button();
textBoxCount = new TextBox();
comboBoxSensor = new ComboBox();
labelCount = new Label();
labelSensor = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(318, 85);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 11;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(215, 85);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 10;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(145, 54);
textBoxCount.Margin = new Padding(3, 2, 3, 2);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(280, 23);
textBoxCount.TabIndex = 9;
//
// comboBoxSensor
//
comboBoxSensor.FormattingEnabled = true;
comboBoxSensor.Location = new Point(145, 19);
comboBoxSensor.Margin = new Padding(3, 2, 3, 2);
comboBoxSensor.Name = "comboBoxSensor";
comboBoxSensor.Size = new Size(280, 23);
comboBoxSensor.TabIndex = 8;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(36, 56);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 7;
labelCount.Text = "Количество:";
//
// labelSensor
//
labelSensor.AutoSize = true;
labelSensor.Location = new Point(36, 22);
labelSensor.Name = "labelSensor";
labelSensor.Size = new Size(65, 15);
labelSensor.TabIndex = 6;
labelSensor.Text = "Заготовка:";
//
// FormSecureSensors
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(460, 126);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(comboBoxSensor);
Controls.Add(labelCount);
Controls.Add(labelSensor);
Name = "FormSecureSensors";
Text = "Заготовки для изделия";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxCount;
private ComboBox comboBoxSensor;
private Label labelCount;
private Label labelSensor;
}
}

View File

@ -0,0 +1,98 @@
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormSecureSensor : Form
{
private readonly List<SensorViewModel>? _list;
public int Id
{
get { return Convert.ToInt32(comboBoxSensor.SelectedValue); }
set { comboBoxSensor.SelectedValue = value; }
}
public ISensorModel? SensorModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set
{
textBoxCount.Text = value.ToString();
}
}
public FormSecureSensor(ISensorLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxSensor.DisplayMember = "SensorName";
comboBoxSensor.ValueMember = "Id";
comboBoxSensor.DataSource = _list;
comboBoxSensor.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSensor.SelectedValue == null)
{
MessageBox.Show("Выберите заготовку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

View File

@ -0,0 +1,119 @@
namespace SecuritySystem
{
partial class FormSecures
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonRef = new Button();
buttonDelete = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(20, 9);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(528, 320);
dataGridView.TabIndex = 9;
//
// buttonRef
//
buttonRef.Location = new Point(581, 152);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(82, 22);
buttonRef.TabIndex = 8;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(581, 113);
buttonDelete.Margin = new Padding(3, 2, 3, 2);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(82, 22);
buttonDelete.TabIndex = 7;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += ButtonDelete_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(581, 69);
buttonUpd.Margin = new Padding(3, 2, 3, 2);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(82, 22);
buttonUpd.TabIndex = 6;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(581, 27);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(82, 22);
buttonAdd.TabIndex = 5;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// FormSecures
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(683, 338);
Controls.Add(dataGridView);
Controls.Add(buttonRef);
Controls.Add(buttonDelete);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Name = "FormSecures";
Text = "Изделия";
Load += FormSecures_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonRef;
private Button buttonDelete;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,125 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormSecures : Form
{
private readonly ILogger _logger;
private readonly ISecureLogic _logic;
public FormSecures(ILogger<FormSecures> logger, ISecureLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormSecures_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SecureSensors"].Visible = false;
dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка изделий");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecure));
if (service is FormSecure form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
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)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление изделия");
try
{
if (!_logic.Delete(new SecureBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

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

View File

@ -0,0 +1,122 @@
namespace SecuritySystem
{
partial class FormSensor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonSave = new Button();
buttonCancel = new Button();
textBoxCost = new TextBox();
textBoxName = new TextBox();
labelPrice = new Label();
labelName = new Label();
SuspendLayout();
//
// buttonSave
//
buttonSave.Location = new Point(192, 77);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 11;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(291, 77);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 10;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxCost
//
textBoxCost.Location = new Point(117, 45);
textBoxCost.Margin = new Padding(3, 2, 3, 2);
textBoxCost.Name = "textBoxCost";
textBoxCost.Size = new Size(157, 23);
textBoxCost.TabIndex = 9;
//
// textBoxName
//
textBoxName.Location = new Point(117, 15);
textBoxName.Margin = new Padding(3, 2, 3, 2);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(257, 23);
textBoxName.TabIndex = 8;
//
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(32, 48);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(38, 15);
labelPrice.TabIndex = 7;
labelPrice.Text = "Цена:";
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(32, 17);
labelName.Name = "labelName";
labelName.Size = new Size(62, 15);
labelName.TabIndex = 6;
labelName.Text = "Название:";
//
// FormSensor
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(406, 115);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(textBoxCost);
Controls.Add(textBoxName);
Controls.Add(labelPrice);
Controls.Add(labelName);
Name = "FormSensor";
Text = "Заготовка";
Load += FormSensor_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxCost;
private TextBox textBoxName;
private Label labelPrice;
private Label labelName;
}
}

View File

@ -0,0 +1,104 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace SecuritySystem
{
//форма "Заготовка"
public partial class FormSensor : Form
{
private readonly ILogger _logger;
private readonly ISensorLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
//конструктор
public FormSensor(ILogger<FormSensor> logger, ISensorLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
//при загрузке формы
private void FormSensor_Load(object sender, EventArgs e)
{
//проверка на заполнение поля id. Если оно заполнено, то пробуем получить запись и выести её на экран
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение заготовки");
var view = _logic.ReadElement(new SensorSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.SensorName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
//обработка нажатия кнопки Сохранить. Либо пеердаёт данные для создания заготовки, либо её обновления
private void ButtonSave_Click(object sender, EventArgs e)
{
//проверка на заполнение поля с названием заготовки
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение заготовки");
try
{
var model = new SensorBindingModel
{
Id = _id ?? 0,
SensorName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранеии. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//обработка нажатия кнопки Отмена. При нажатии просто закрываем форму
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

View File

@ -0,0 +1,119 @@
namespace SecuritySystem
{
partial class FormSensors
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonRef = new Button();
buttonDelete = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(20, 9);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(528, 320);
dataGridView.TabIndex = 9;
//
// buttonRef
//
buttonRef.Location = new Point(581, 152);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(82, 22);
buttonRef.TabIndex = 8;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(581, 113);
buttonDelete.Margin = new Padding(3, 2, 3, 2);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(82, 22);
buttonDelete.TabIndex = 7;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += ButtonDelete_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(581, 69);
buttonUpd.Margin = new Padding(3, 2, 3, 2);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(82, 22);
buttonUpd.TabIndex = 6;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(581, 27);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(82, 22);
buttonAdd.TabIndex = 5;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// FormSensors
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(683, 338);
Controls.Add(dataGridView);
Controls.Add(buttonRef);
Controls.Add(buttonDelete);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Name = "FormSensors";
Text = "Заготовки";
Load += FormSensor_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonRef;
private Button buttonDelete;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,126 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystem
{
public partial class FormSensors : Form
{
private readonly ILogger _logger;
private readonly ISensorLogic _logic;
public FormSensors(ILogger<FormSensors> logger, ISensorLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormSensor_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
//растягиваем колонку Название на всю ширину, колонку Id скрываем
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SensorName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заготовок");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заготовок");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSensor));
if (service is FormSensor form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
//проверяем наличие выделенной строки
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSensor));
if (service is FormSensor form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
//проверяем наличие выделенной строки
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new SensorBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

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

View File

@ -1,17 +1,57 @@
using SecuritySystemBusinessLogic.BusinessLogic;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemListImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System.Drawing;
namespace SecuritySystem
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// To customize application configuration such as set high DPI settings or default font;
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<ISensorStorage, SensorStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISecureStorage, SecureStorage>();
services.AddTransient<ISensorLogic, SensorLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISecureLogic, SecureLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormSensor>();
services.AddTransient<FormSensors>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSecure>();
services.AddTransient<FormSecures>();
services.AddTransient<FormSecureSensor>();
}
}
}

View File

@ -8,4 +8,17 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecuritySystemBusinessLogiс\SecuritySystemBusinessLogiс.csproj" />
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
<ProjectReference Include="..\SecuritySystemListImplement\SecuritySystemListImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,173 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
//вывод отфильтрованного списка компонентов
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
//list хранит весь список в случае, если model пришло со значением null на вход метода
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if(list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
//создание чека
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if(model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Insert operation failed, incorrect order status");
return false;
}
model.Status = OrderStatus.Принят;
if(_orderStorage.Insert(model) == null)
{
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
//проверка на пустоту входного параметра
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if(model == null)
{
throw new ArgumentNullException(nameof(model));
}
//так как при удалении параметром withParams передаём false
if (!withParams)
{
return;
}
//проверка на наличие товаров в заказе
if(model.Count <= 0)
{
throw new ArgumentNullException("В заказе не может быть 0 изделий", nameof(model.Count));
}
//проверка на наличие нормальной суммарной стоимости чека
if(model.Sum <= 0)
{
throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum));
}
//проверка корректности id у изделий
if (model.SecureId < 0)
{
throw new ArgumentNullException("Некорректный id у изделия", nameof(model.SecureId));
}
//проверка корректности дат
if(model.DateCreate > model.DateImplement)
{
throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения");
}
_logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. SecureId:{Id}", model.Id, model.Sum, model.SecureId);
}
//обновление статуса заказа
public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
//если не смогли найти указанный заказ по его Id
if(viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
//проверка на возможность обновления статуса на следующий
if (viewModel.Status + 1 != newOrderStatus)
{
_logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + " incorrect");
return false;
}
model.Status = newOrderStatus;
//проверка на выдачу
if(model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
}
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
//финальная проверка на возможность обновления
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,160 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemBusinessLogic.BusinessLogic
{
public class SecureLogic : ISecureLogic
{
private readonly ILogger _logger;
private readonly ISecureStorage _secureStorage;
//конструктор
public SecureLogic(ILogger<SecureLogic> logger, ISecureStorage secureStorage)
{
_logger = logger;
_secureStorage = secureStorage;
}
//вывод отфильтрованного списка
public List<SecureViewModel>? ReadList(SecureSearchModel? model)
{
_logger.LogInformation("ReadList. SecureName:{SecureName}. Id:{Id}", model?.SecureName, model?.Id);
//list хранит весь список в случае, если model пришло со значением null на вход метода
var list = model == null ? _secureStorage.GetFullList() : _secureStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
//вывод конкретного изделия
public SecureViewModel? ReadElement(SecureSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(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");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", model.Id);
return element;
}
//Создание изделия
public bool Create(SecureBindingModel model)
{
CheckModel(model);
if (_secureStorage.Insert(model) == null)
{
_logger.LogWarning("Create operation failed");
return false;
}
return true;
}
//обновление изделия
public bool Update(SecureBindingModel model)
{
CheckModel(model);
if (_secureStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
//удаление изделия
public bool Delete(SecureBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_secureStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
//проверка входного аргумента для методов Insert, Update и Delete
private void CheckModel(SecureBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
//так как при удалении параметром withParams передаём false
if (!withParams)
{
return;
}
//проверка на наличие названия изделия
if (string.IsNullOrEmpty(model.SecureName))
{
throw new ArgumentNullException("Нет названия изделия", nameof(model.SecureName));
}
//проверка на наличие нормальной цены у изделия
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Secure. SecureName:{SecureName}. Price:{Price}. Id:{Id}",
model.SecureName, model.Price, model.Id);
//проверка на наличие такого же изделия в списке
var element = _secureStorage.GetElement(new SecureSearchModel
{
SecureName = model.SecureName,
});
//если элемент найден и его Id не совпадает с Id объекта, переданного на вход
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Изделие с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,161 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemBusinessLogic.BusinessLogic
{
//класс, реализующий логику для заготовок
public class SensorLogic : ISensorLogic
{
private readonly ILogger _logger;
private readonly ISensorStorage _sensorStorage;
//конструктор
public SensorLogic(ILogger<SensorLogic> logger, ISensorStorage sensorStorage)
{
_logger = logger;
_sensorStorage = sensorStorage;
}
//вывод отфильтрованного списка компонентов
public List<SensorViewModel>? ReadList(SensorSearchModel? model)
{
_logger.LogInformation("ReadList. SensorName:{SensorName}. Id:{Id}", model?.SensorName, model?.Id);
//list хранит весь список в случае, если model пришло со значением null на вход метода
var list = model == null ? _sensorStorage.GetFullList() : _sensorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
//вывод конкретного заготовки
public SensorViewModel? ReadElement(SensorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. SensorName:{SensorName}. Id:{Id}", model.SensorName, model.Id);
var element = _sensorStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
//создание заготовки
public bool Create(SensorBindingModel model)
{
CheckModel(model);
if (_sensorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
//обновление заготовки
public bool Update(SensorBindingModel model)
{
CheckModel(model);
if (_sensorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
//удаление заготовки
public bool Delete(SensorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_sensorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
//проверка входного аргумента для методов Insert, Update и Delete
private void CheckModel(SensorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
//так как при удалении передаём как параметр false
if (!withParams)
{
return;
}
//проверка на наличие названия заготовки
if (string.IsNullOrEmpty(model.SensorName))
{
throw new ArgumentNullException("Нет названия заготовки", nameof(model.SensorName));
}
//проверка на наличие нормальной цены у заготовки
if (model.Cost <= 0)
{
throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Cost));
}
_logger.LogInformation("Sensor. SensorName:{SensorName}. Cost:{Cost}. Id:{Id}",
model.SensorName, model.Cost, model.Id);
//проверка на наличие такой же заготовки в списке
var element = _sensorStorage.GetElement(new SensorSearchModel
{
SensorName = model.SensorName,
});
//если элемент найден и его Id не совпадает с Id переданного объекта
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Заготовка с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,28 @@
using SecuritySystemDataModels.Enums;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BindingModels
{
//реализация сущности "Заказ"
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int SecureId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BindingModels
{
//реализация сущности "Изделие"
public class SecureBindingModel : ISecureModel
{
public int Id { get; set; }
public string SecureName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (ISensorModel, int)> SecureSensors { get; set; } = new();
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemDataModels.Models;
namespace SecuritySystemContracts.BindingModels
{
//реализация сущности "Компонент"
public class SensorBindingModel : ISensorModel
{
public int Id { get; set; }
public string SensorName { get; set; } = string.Empty;
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,25 @@
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 IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,25 @@
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

@ -0,0 +1,25 @@
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 ISensorLogic
{
List<SensorViewModel>? ReadList(SensorSearchModel? model);
SensorViewModel? ReadElement(SensorSearchModel model);
bool Create(SensorBindingModel model);
bool Update(SensorBindingModel model);
bool Delete(SensorBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels
{
//для поиска сущности "Заказ"
public class OrderSearchModel
{
//для поиска по идентификатору
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels
{
//модель для поиска заготовки "Продукт" (она же изделие)
public class SecureSearchModel
{
//для поиска по идентификатору
public int? Id { get; set; }
//для поиска по названию
public string? SecureName { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels
{
//модель для поиска сущности "Компонент" (она же заготовка)
public class SensorSearchModel
{
//для поиска по идентификатору
public int? Id { get; set; }
//для поиска по названию
public string? SensorName { get; set; }
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
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 IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,27 @@
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

@ -0,0 +1,27 @@
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 ISensorStorage
{
List<SensorViewModel> GetFullList();
List<SensorViewModel> GetFilteredList(SensorSearchModel model);
SensorViewModel? GetElement(SensorSearchModel model);
SensorViewModel? Insert(SensorBindingModel model);
SensorViewModel? Update(SensorBindingModel model);
SensorViewModel? Delete(SensorBindingModel model);
}
}

View File

@ -0,0 +1,38 @@
using SecuritySystemDataModels.Enums;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels
{
//класс для отображения пользователю информации о заказах
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
public int SecureId { get; set; }
[DisplayName("Изделие")]
public string SecureName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels
{
//класс для отображения пользователю информаци о продуктах (изделиях)
public class SecureViewModel : ISecureModel
{
public int Id { get; set; }
[DisplayName("Навание изделия")]
public string SecureName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (ISensorModel, int)> SecureSensors { get; set; } = new();
}
}

View File

@ -0,0 +1,22 @@
using SecuritySystemDataModels.Models;
using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels
{
//класс для отображения пользователю данных
public class SensorViewModel : ISensorModel
{
public int Id { get; set; }
[DisplayName("Название Датчика")]
public string SensorName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDataModels.Enums
{
//статус заказа
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDataModels
{
//интерфейс, отвечающий за id у компонентов, продуктов и чеков
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemDataModels.Enums;
namespace SecuritySystemDataModels.Models
{
//интерфейс, отвечающий за заказ
public interface IOrderModel : IId
{
//id продукта
int SecureId { get; }
//кол-во продуктов
int Count { get; }
//суммарная стоимость продуктов
double Sum { get; }
//статус заказа
OrderStatus Status { get; }
//дата создания заказа
DateTime DateCreate { get; }
//дата завершения заказа (не обязательна к указанию сразу)
DateTime? DateImplement { get; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models
{
//интерфейс, отвечающий за продукт
public interface ISecureModel : IId
{
//наименование изделия
string SecureName { get; }
//цена изделия
double Price { get; }
//словарь, хранящий пары кол-во + компонент и его цена
Dictionary<int, (ISensorModel, int)> SecureSensors { get; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models
{
//интерфейс, отвечающий за компоненты
public interface ISensorModel : IId
{
//название составляющей (изделие состоит из составляющих)
string SensorName { get; }
//цена составляющей
double Cost { get; }
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,41 @@
using SecuritySystemListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement
{
//класс для списков, в которых будет храниться информация при работе приложения
public class DataListSingleton
{
private static DataListSingleton? _instance;
//список для хранения заготовок
public List<Sensor> Sensors { get; set; }
//список для хранения изделий
public List<Secure> Secures { get; set; }
//список для хранения заказов
public List<Order> Orders { get; set; }
public DataListSingleton()
{
Sensors = new List<Sensor>();
Secures = new List<Secure>();
Orders = new List<Order>();
}
public static DataListSingleton GetInstance()
{
if(_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,155 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Implements
{
//класс, реализующий интерфейс хранилища заказов
public class OrderStorage : IOrderStorage
{
//поле для работы со списком заказов
private readonly DataListSingleton _source;
//получение в конструкторе объекта DataListSingleton
public OrderStorage()
{
_source = DataListSingleton.GetInstance();
}
//получение полного списка заготовок
public List<OrderViewModel> GetFullList()
{
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(GetViewModel(order));
}
return result;
}
//получение отфильтрованного списка заказов
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(GetViewModel(order));
}
}
return result;
}
//получение элемента из списка заказов
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return GetViewModel(order);
}
}
return null;
}
//метод для записи названия изделия на форме с заказами
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var secures in _source.Secures)
{
if (secures.Id == order.SecureId)
{
viewModel.SecureName = secures.SecureName;
break;
}
}
return viewModel;
}
//при создании заказа определяем для него новый id: ищем max id и прибавляем к нему 1
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = 1;
foreach (var order in _source.Orders)
{
if (model.Id <= order.Id)
{
model.Id = order.Id + 1;
}
}
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
_source.Orders.Add(newOrder);
return GetViewModel(newOrder);
}
//обновление заказа
public OrderViewModel? Update(OrderBindingModel model)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
order.Update(model);
return GetViewModel(order);
}
}
return null;
}
//удаление заказа
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
{
if (_source.Orders[i].Id == model.Id)
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return GetViewModel(element);
}
}
return null;
}
}
}

View File

@ -0,0 +1,138 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Implements
{
//класс, реализующий интерфейс хранилища изделий
public class SecureStorage : ISecureStorage
{
//поле для работы со списком изделий
private readonly DataListSingleton _source;
//получение в конструкторе объекта DataListSingleton
public SecureStorage()
{
_source = DataListSingleton.GetInstance();
}
//получение полного списка изделий
public List<SecureViewModel> GetFullList()
{
var result = new List<SecureViewModel>();
foreach (var secure in _source.Secures)
{
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.Secures)
{
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.Secures)
{
if ((!string.IsNullOrEmpty(model.SecureName) && secure.SecureName == model.SecureName) ||
(model.Id.HasValue && secure.Id == model.Id))
{
return secure.GetViewModel;
}
}
return null;
}
//при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1
public SecureViewModel? Insert(SecureBindingModel model)
{
model.Id = 1;
foreach (var secure in _source.Secures)
{
if (model.Id <= secure.Id)
{
model.Id = secure.Id + 1;
}
}
var newSecure = Secure.Create(model);
if (newSecure == null)
{
return null;
}
_source.Secures.Add(newSecure);
return newSecure.GetViewModel;
}
//обновление изделия
public SecureViewModel? Update(SecureBindingModel model)
{
foreach (var secure in _source.Secures)
{
if (secure.Id == model.Id)
{
secure.Update(model);
return secure.GetViewModel;
}
}
return null;
}
//удаление изделия
public SecureViewModel? Delete(SecureBindingModel model)
{
for (int i = 0; i < _source.Secures.Count; ++i)
{
if (_source.Secures[i].Id == model.Id)
{
var element = _source.Secures[i];
_source.Secures.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,138 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Implements
{
//класс, реализующий интерфейс хранилища заготовок
public class SensorStorage : ISensorStorage
{
//поле для работы со списком заготовок
private readonly DataListSingleton _source;
//получение в конструкторе объекта DataListSingleton
public SensorStorage()
{
_source = DataListSingleton.GetInstance();
}
//получение полного списка заготовок
public List<SensorViewModel> GetFullList()
{
var result = new List<SensorViewModel>();
foreach (var sensor in _source.Sensors)
{
result.Add(sensor.GetViewModel);
}
return result;
}
//получение отфильтрованного списка заготовок
public List<SensorViewModel> GetFilteredList(SensorSearchModel model)
{
var result = new List<SensorViewModel>();
if (string.IsNullOrEmpty(model.SensorName))
{
return result;
}
foreach (var sensor in _source.Sensors)
{
if (sensor.SensorName.Contains(model.SensorName))
{
result.Add(sensor.GetViewModel);
}
}
return result;
}
//получение элемента из списка заготовок
public SensorViewModel? GetElement(SensorSearchModel model)
{
if (string.IsNullOrEmpty(model.SensorName) && !model.Id.HasValue)
{
return null;
}
foreach (var sensor in _source.Sensors)
{
if ((!string.IsNullOrEmpty(model.SensorName) && sensor.SensorName == model.SensorName) ||
(model.Id.HasValue && sensor.Id == model.Id))
{
return sensor.GetViewModel;
}
}
return null;
}
//при создании заготовки определяем для него новый id: ищем max id и прибавляем к нему 1
public SensorViewModel? Insert(SensorBindingModel model)
{
model.Id = 1;
foreach (var sensor in _source.Sensors)
{
if (model.Id <= sensor.Id)
{
model.Id = sensor.Id + 1;
}
}
var newSensor = Sensor.Create(model);
if (newSensor == null)
{
return null;
}
_source.Sensors.Add(newSensor);
return newSensor.GetViewModel;
}
//обновление заготовки
public SensorViewModel? Update(SensorBindingModel model)
{
foreach (var sensor in _source.Sensors)
{
if (sensor.Id == model.Id)
{
sensor.Update(model);
return sensor.GetViewModel;
}
}
return null;
}
//удаление заготовки
public SensorViewModel? Delete(SensorBindingModel model)
{
for (int i = 0; i < _source.Sensors.Count; ++i)
{
if (_source.Sensors[i].Id == model.Id)
{
var element = _source.Sensors[i];
_source.Sensors.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,74 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Enums;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Models
{
//класс, реализующий интерфейс модели заказа
public class Order : IOrderModel
{
//методы set сделали приватными, чтобы исключить неразрешённые манипуляции
public int Id { get; private set; }
public int SecureId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
SecureId = model.SecureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
//метод изменения существующего объекта
public void Update(OrderBindingModel? model)
{
if(model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
public OrderViewModel GetViewModel => new()
{
Id = Id,
SecureId = SecureId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,63 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Models
{
//класс реализующий интерфейс модели изделия
public class Secure : ISecureModel
{
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
public int Id { get; private set; }
public string SecureName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (ISensorModel, int)> SecureSensors { get; private set; } = new Dictionary<int, (ISensorModel, int)>();
//метод для создания объекта от класса-компонента на основе класса-BindingModel
public static Secure? Create(SecureBindingModel? model)
{
if (model == null)
{
return null;
}
return new Secure()
{
Id = model.Id,
SecureName = model.SecureName,
Price = model.Price,
SecureSensors = model.SecureSensors
};
}
//метод изменения существующего объекта
public void Update(SecureBindingModel? model)
{
if (model == null)
{
return;
}
SecureName = model.SecureName;
Price = model.Price;
SecureSensors = model.SecureSensors;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
public SecureViewModel GetViewModel => new()
{
Id = Id,
SecureName = SecureName,
Price = Price,
SecureSensors = SecureSensors
};
}
}

View File

@ -0,0 +1,58 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Models
{
//реализация интерфейса модели заготовки
public class Sensor : ISensorModel
{
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
public int Id { get; private set; }
public string SensorName { get; private set; } = string.Empty;
public double Cost { get; private set; }
//метод для создания объекта от класса-компонента на основе класса-BindingModel
public static Sensor? Create(SensorBindingModel? model)
{
if(model == null)
{
return null;
}
return new Sensor()
{
Id = model.Id,
SensorName = model.SensorName,
Cost = model.Cost
};
}
//метод изменения существующего объекта
public void Update(SensorBindingModel? model)
{
if(model == null)
{
return;
}
SensorName = model.SensorName;
Cost = model.Cost;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
public SensorViewModel GetViewModel => new()
{
Id = Id,
SensorName = SensorName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
</ItemGroup>
</Project>