diff --git a/SecuritySystem/Form1.Designer.cs b/SecuritySystem/Form1.Designer.cs
deleted file mode 100644
index 241ccba..0000000
--- a/SecuritySystem/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace SecuritySystem
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- 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
- }
-}
\ No newline at end of file
diff --git a/SecuritySystem/Form1.cs b/SecuritySystem/Form1.cs
deleted file mode 100644
index b9d425d..0000000
--- a/SecuritySystem/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace SecuritySystem
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
diff --git a/SecuritySystem/FormComponent.Designer.cs b/SecuritySystem/FormComponent.Designer.cs
new file mode 100644
index 0000000..280f9a6
--- /dev/null
+++ b/SecuritySystem/FormComponent.Designer.cs
@@ -0,0 +1,119 @@
+namespace SecuritySystemView
+{
+ partial class FormComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.labelCost = new System.Windows.Forms.Label();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 9);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(98, 9);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(366, 27);
+ this.textBoxName.TabIndex = 1;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(98, 42);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(133, 27);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // labelCost
+ //
+ this.labelCost.AutoSize = true;
+ this.labelCost.Location = new System.Drawing.Point(12, 42);
+ this.labelCost.Name = "labelCost";
+ this.labelCost.Size = new System.Drawing.Size(45, 20);
+ this.labelCost.TabIndex = 2;
+ this.labelCost.Text = "Цена";
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(171, 90);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(130, 40);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(328, 90);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(136, 40);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(478, 142);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.labelCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormComponent";
+ this.Text = "Компонент";
+ this.Load += new System.EventHandler(this.FormComponent_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Label labelCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormComponent.cs b/SecuritySystem/FormComponent.cs
new file mode 100644
index 0000000..bfd6ac0
--- /dev/null
+++ b/SecuritySystem/FormComponent.cs
@@ -0,0 +1,90 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+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 SecuritySystemView
+{
+ public partial class FormComponent : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormComponent(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponent_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение компонента");
+ var view = _logic.ReadElement(new ComponentSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ComponentName;
+ 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 ComponentBindingModel
+ {
+ Id = _id ?? 0,
+ ComponentName = 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();
+ }
+ }
+}
diff --git a/SecuritySystem/Form1.resx b/SecuritySystem/FormComponent.resx
similarity index 100%
rename from SecuritySystem/Form1.resx
rename to SecuritySystem/FormComponent.resx
diff --git a/SecuritySystem/FormComponents.Designer.cs b/SecuritySystem/FormComponents.Designer.cs
new file mode 100644
index 0000000..49f0d8f
--- /dev/null
+++ b/SecuritySystem/FormComponents.Designer.cs
@@ -0,0 +1,130 @@
+namespace SecuritySystemView
+{
+ partial class FormComponents
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ToolsPanel = new System.Windows.Forms.Panel();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.ToolsPanel.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(590, 426);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ToolsPanel
+ //
+ this.ToolsPanel.Controls.Add(this.buttonRef);
+ this.ToolsPanel.Controls.Add(this.buttonDel);
+ this.ToolsPanel.Controls.Add(this.buttonUpd);
+ this.ToolsPanel.Controls.Add(this.buttonAdd);
+ this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
+ this.ToolsPanel.Name = "ToolsPanel";
+ this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
+ this.ToolsPanel.TabIndex = 1;
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(31, 206);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(126, 36);
+ this.buttonRef.TabIndex = 3;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(31, 142);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(126, 36);
+ this.buttonDel.TabIndex = 2;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(31, 76);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(126, 36);
+ this.buttonUpd.TabIndex = 1;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(31, 16);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(126, 36);
+ this.buttonAdd.TabIndex = 0;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // FormComponents
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ToolsPanel);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormComponents";
+ this.Text = "Компоненты";
+ this.Load += new System.EventHandler(this.FormComponents_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ToolsPanel.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Panel ToolsPanel;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormComponents.cs b/SecuritySystem/FormComponents.cs
new file mode 100644
index 0000000..f1d5cf2
--- /dev/null
+++ b/SecuritySystem/FormComponents.cs
@@ -0,0 +1,114 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystem;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+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 SecuritySystemView
+{
+ public partial class FormComponents : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ public FormComponents(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponents_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["ComponentName"].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(FormComponent));
+ if (service is FormComponent 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(FormComponent));
+ if (service is FormComponent form)
+ {
+ form.Id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_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 ComponentBindingModel
+ {
+ 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();
+ }
+ }
+}
diff --git a/SecuritySystem/FormComponents.resx b/SecuritySystem/FormComponents.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormComponents.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/FormCreateOrder.Designer.cs b/SecuritySystem/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..ba1b6eb
--- /dev/null
+++ b/SecuritySystem/FormCreateOrder.Designer.cs
@@ -0,0 +1,145 @@
+namespace SecuritySystemView
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelSecure = new System.Windows.Forms.Label();
+ this.comboBoxSecure = new System.Windows.Forms.ComboBox();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.labelSum = new System.Windows.Forms.Label();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelSecure
+ //
+ this.labelSecure.AutoSize = true;
+ this.labelSecure.Location = new System.Drawing.Point(12, 15);
+ this.labelSecure.Name = "labelSecure";
+ this.labelSecure.Size = new System.Drawing.Size(75, 20);
+ this.labelSecure.TabIndex = 0;
+ this.labelSecure.Text = "Изделие: ";
+ //
+ // comboBoxSecure
+ //
+ this.comboBoxSecure.FormattingEnabled = true;
+ this.comboBoxSecure.Location = new System.Drawing.Point(115, 12);
+ this.comboBoxSecure.Name = "comboBoxSecure";
+ this.comboBoxSecure.Size = new System.Drawing.Size(358, 28);
+ this.comboBoxSecure.TabIndex = 1;
+ this.comboBoxSecure.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSecure_SelectedIndexChanged);
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(12, 49);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(97, 20);
+ this.labelCount.TabIndex = 2;
+ this.labelCount.Text = "Количество: ";
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(115, 46);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(358, 27);
+ this.textBoxCount.TabIndex = 3;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ //
+ // labelSum
+ //
+ this.labelSum.AutoSize = true;
+ this.labelSum.Location = new System.Drawing.Point(12, 80);
+ this.labelSum.Name = "labelSum";
+ this.labelSum.Size = new System.Drawing.Size(62, 20);
+ this.labelSum.TabIndex = 4;
+ this.labelSum.Text = "Сумма: ";
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(115, 80);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.ReadOnly = true;
+ this.textBoxSum.Size = new System.Drawing.Size(358, 27);
+ this.textBoxSum.TabIndex = 5;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(337, 113);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(110, 32);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(221, 113);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(110, 32);
+ this.buttonSave.TabIndex = 7;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(485, 158);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.labelSum);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.comboBoxSecure);
+ this.Controls.Add(this.labelSecure);
+ this.Name = "FormCreateOrder";
+ this.Text = "Заказ";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelSecure;
+ private ComboBox comboBoxSecure;
+ private Label labelCount;
+ private TextBox textBoxCount;
+ private Label labelSum;
+ private TextBox textBoxSum;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormCreateOrder.cs b/SecuritySystem/FormCreateOrder.cs
new file mode 100644
index 0000000..4af9c06
--- /dev/null
+++ b/SecuritySystem/FormCreateOrder.cs
@@ -0,0 +1,112 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+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 SecuritySystemView
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ISecureLogic _logicM;
+ private readonly IOrderLogic _logicO;
+ private List? _list;
+ public FormCreateOrder(ILogger logger, ISecureLogic logicM, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicM = logicM;
+ _logicO = logicO;
+ }
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _list = _logicM.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxSecure.DisplayMember = "SecureName";
+ comboBoxSecure.ValueMember = "Id";
+ comboBoxSecure.DataSource = _list;
+ comboBoxSecure.SelectedItem = null;
+ _logger.LogInformation("Загрузка изделий для заказа");
+ }
+ }
+ 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),
+ SecureName = comboBoxSecure.Text,
+ 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();
+ }
+ }
+}
diff --git a/SecuritySystem/FormCreateOrder.resx b/SecuritySystem/FormCreateOrder.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormCreateOrder.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/FormMain.Designer.cs b/SecuritySystem/FormMain.Designer.cs
new file mode 100644
index 0000000..0558535
--- /dev/null
+++ b/SecuritySystem/FormMain.Designer.cs
@@ -0,0 +1,187 @@
+namespace SecuritySystemView
+{
+ partial class FormMain
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.guideToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.goodsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonCreateOrder = new System.Windows.Forms.Button();
+ this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
+ this.buttonOrderReady = new System.Windows.Forms.Button();
+ this.buttonIssuedOrder = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.menuStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.guideToolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
+ this.menuStrip1.Size = new System.Drawing.Size(1149, 24);
+ this.menuStrip1.TabIndex = 0;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // guideToolStripMenuItem
+ //
+ this.guideToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.componentsToolStripMenuItem,
+ this.goodsToolStripMenuItem});
+ this.guideToolStripMenuItem.Name = "guideToolStripMenuItem";
+ this.guideToolStripMenuItem.Size = new System.Drawing.Size(87, 20);
+ this.guideToolStripMenuItem.Text = "Справочник";
+ //
+ // componentsToolStripMenuItem
+ //
+ this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
+ this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.componentsToolStripMenuItem.Text = "Компоненты";
+ this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
+ //
+ // goodsToolStripMenuItem
+ //
+ this.goodsToolStripMenuItem.Name = "goodsToolStripMenuItem";
+ this.goodsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.goodsToolStripMenuItem.Text = "Изделия";
+ this.goodsToolStripMenuItem.Click += new System.EventHandler(this.GoodsToolStripMenuItem_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(10, 23);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(855, 286);
+ this.dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ this.buttonCreateOrder.Location = new System.Drawing.Point(898, 53);
+ this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCreateOrder.Name = "buttonCreateOrder";
+ this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22);
+ this.buttonCreateOrder.TabIndex = 2;
+ this.buttonCreateOrder.Text = "Создать заказ";
+ this.buttonCreateOrder.UseVisualStyleBackColor = true;
+ this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // buttonTakeOrderInWork
+ //
+ this.buttonTakeOrderInWork.Location = new System.Drawing.Point(898, 92);
+ this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
+ this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22);
+ this.buttonTakeOrderInWork.TabIndex = 3;
+ this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
+ this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
+ this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // buttonOrderReady
+ //
+ this.buttonOrderReady.Location = new System.Drawing.Point(898, 129);
+ this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonOrderReady.Name = "buttonOrderReady";
+ this.buttonOrderReady.Size = new System.Drawing.Size(216, 22);
+ this.buttonOrderReady.TabIndex = 4;
+ this.buttonOrderReady.Text = "Заказ готов";
+ this.buttonOrderReady.UseVisualStyleBackColor = true;
+ this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // buttonIssuedOrder
+ //
+ this.buttonIssuedOrder.Location = new System.Drawing.Point(898, 169);
+ this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonIssuedOrder.Name = "buttonIssuedOrder";
+ this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22);
+ this.buttonIssuedOrder.TabIndex = 5;
+ this.buttonIssuedOrder.Text = "Заказ выдан";
+ this.buttonIssuedOrder.UseVisualStyleBackColor = true;
+ this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(898, 210);
+ this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(216, 22);
+ this.buttonRef.TabIndex = 6;
+ this.buttonRef.Text = "Обновить список";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1149, 319);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonIssuedOrder);
+ this.Controls.Add(this.buttonOrderReady);
+ this.Controls.Add(this.buttonTakeOrderInWork);
+ this.Controls.Add(this.buttonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormMain";
+ this.Text = "Система Охраны";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem guideToolStripMenuItem;
+ private ToolStripMenuItem componentsToolStripMenuItem;
+ private ToolStripMenuItem goodsToolStripMenuItem;
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private Button buttonTakeOrderInWork;
+ private Button buttonOrderReady;
+ private Button buttonIssuedOrder;
+ private Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormMain.cs b/SecuritySystem/FormMain.cs
new file mode 100644
index 0000000..2537a2f
--- /dev/null
+++ b/SecuritySystem/FormMain.cs
@@ -0,0 +1,177 @@
+using SecuritySystem;
+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;
+using Microsoft.Extensions.Logging;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemDataModels.Enums;
+
+namespace SecuritySystemView
+{
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ }
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["SecureId"].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 ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void GoodsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSecuries));
+ if (service is FormSecuries 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("Заказ No {id}. Меняется статус на 'В работе'", id);
+ try
+ {
+ var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = id,
+ SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
+ SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
+ Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ });
+ 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("Заказ No {id}. Меняется статус на 'Готов'", id);
+ try
+ {
+ var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = id,
+ SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
+ SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
+ Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ DateImplement = DateTime.Now,
+ });
+ 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("Заказ No {id}. Меняется статус на 'Выдан'", id);
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
+ {
+ Id = id,
+ SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
+ SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
+ Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()),
+ });
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Заказ No {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();
+ }
+ }
+}
diff --git a/SecuritySystem/FormMain.resx b/SecuritySystem/FormMain.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormMain.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/FormSecure.Designer.cs b/SecuritySystem/FormSecure.Designer.cs
new file mode 100644
index 0000000..934e2e7
--- /dev/null
+++ b/SecuritySystem/FormSecure.Designer.cs
@@ -0,0 +1,237 @@
+namespace SecuritySystemView
+{
+ partial class FormSecure
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.groupBoxComponents = new System.Windows.Forms.GroupBox();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.groupBoxComponents.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(16, 15);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(84, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название: ";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(112, 12);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(293, 27);
+ this.textBoxName.TabIndex = 1;
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(16, 51);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(90, 20);
+ this.labelPrice.TabIndex = 2;
+ this.labelPrice.Text = "Стоимость: ";
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(112, 51);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.ReadOnly = true;
+ this.textBoxPrice.Size = new System.Drawing.Size(171, 27);
+ this.textBoxPrice.TabIndex = 3;
+ //
+ // groupBoxComponents
+ //
+ this.groupBoxComponents.Controls.Add(this.buttonRef);
+ this.groupBoxComponents.Controls.Add(this.buttonDel);
+ this.groupBoxComponents.Controls.Add(this.buttonUpd);
+ this.groupBoxComponents.Controls.Add(this.buttonAdd);
+ this.groupBoxComponents.Controls.Add(this.dataGridView);
+ this.groupBoxComponents.Location = new System.Drawing.Point(12, 84);
+ this.groupBoxComponents.Name = "groupBoxComponents";
+ this.groupBoxComponents.Size = new System.Drawing.Size(661, 319);
+ this.groupBoxComponents.TabIndex = 4;
+ this.groupBoxComponents.TabStop = false;
+ this.groupBoxComponents.Text = "Компоненты";
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(502, 211);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(126, 34);
+ this.buttonRef.TabIndex = 4;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(502, 157);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(126, 34);
+ this.buttonDel.TabIndex = 3;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(502, 102);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(126, 34);
+ this.buttonUpd.TabIndex = 2;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(502, 47);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(126, 34);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.id,
+ this.Component,
+ this.Count});
+ this.dataGridView.Location = new System.Drawing.Point(6, 26);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(476, 287);
+ this.dataGridView.TabIndex = 0;
+ //
+ // id
+ //
+ this.id.HeaderText = "id";
+ this.id.MinimumWidth = 6;
+ this.id.Name = "id";
+ this.id.ReadOnly = true;
+ this.id.Visible = false;
+ //
+ // Component
+ //
+ this.Component.HeaderText = "Компонент";
+ this.Component.MinimumWidth = 6;
+ this.Component.Name = "Component";
+ this.Component.ReadOnly = true;
+ //
+ // Count
+ //
+ this.Count.HeaderText = "Количество";
+ this.Count.MinimumWidth = 6;
+ this.Count.Name = "Count";
+ this.Count.ReadOnly = true;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(514, 417);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(126, 34);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(368, 417);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(126, 34);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormManufacture
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(685, 463);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.groupBoxComponents);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormManufacture";
+ this.Text = "Изделие";
+ this.Load += new System.EventHandler(this.FormSecure_Load);
+ this.groupBoxComponents.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private TextBox textBoxName;
+ private Label labelPrice;
+ private TextBox textBoxPrice;
+ private GroupBox groupBoxComponents;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn Component;
+ private DataGridViewTextBoxColumn Count;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn id;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormSecure.cs b/SecuritySystem/FormSecure.cs
new file mode 100644
index 0000000..f328329
--- /dev/null
+++ b/SecuritySystem/FormSecure.cs
@@ -0,0 +1,209 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystem;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemDataModels.Models;
+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 SecuritySystemView
+{
+ public partial class FormSecure : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ISecureLogic _logic;
+ private int? _id;
+ private Dictionary _SecureComponents;
+ public int Id { set { _id = value; } }
+ public FormSecure(ILogger logger, ISecureLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _SecureComponents = new Dictionary();
+ }
+ 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();
+ _SecureComponents = view.SecureComponents ?? new
+ Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент изделия");
+ try
+ {
+ if (_SecureComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _SecureComponents)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.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(FormSecuriesComponent));
+ if (service is FormSecuriesComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_SecureComponents.ContainsKey(form.Id))
+ {
+ _SecureComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _SecureComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
+ if (service is FormSecuriesComponent form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _SecureComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
+ _SecureComponents[form.Id] = (form.ComponentModel, 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("Удаление компонента: {ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
+ _SecureComponents?.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 (_SecureComponents == null || _SecureComponents.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),
+ SecureComponents = _SecureComponents
+ };
+ 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();
+ }
+ private double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _SecureComponents)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/SecuritySystem/FormSecure.resx b/SecuritySystem/FormSecure.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/SecuritySystem/FormSecure.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/FormSecuries.Designer.cs b/SecuritySystem/FormSecuries.Designer.cs
new file mode 100644
index 0000000..718eb7d
--- /dev/null
+++ b/SecuritySystem/FormSecuries.Designer.cs
@@ -0,0 +1,130 @@
+namespace SecuritySystemView
+{
+ partial class FormSecuries
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.ToolsPanel = new System.Windows.Forms.Panel();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ToolsPanel.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // ToolsPanel
+ //
+ this.ToolsPanel.Controls.Add(this.buttonRef);
+ this.ToolsPanel.Controls.Add(this.buttonDel);
+ this.ToolsPanel.Controls.Add(this.buttonUpd);
+ this.ToolsPanel.Controls.Add(this.buttonAdd);
+ this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
+ this.ToolsPanel.Name = "ToolsPanel";
+ this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
+ this.ToolsPanel.TabIndex = 3;
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(31, 206);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(126, 36);
+ this.buttonRef.TabIndex = 3;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(31, 142);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(126, 36);
+ this.buttonDel.TabIndex = 2;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(31, 76);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(126, 36);
+ this.buttonUpd.TabIndex = 1;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(31, 16);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(126, 36);
+ this.buttonAdd.TabIndex = 0;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(590, 426);
+ this.dataGridView.TabIndex = 2;
+ //
+ // FormSecure
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ToolsPanel);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormSecuries";
+ this.Text = "Изделия";
+ this.Load += new System.EventHandler(this.FormSecuries_Load);
+ this.ToolsPanel.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Panel ToolsPanel;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormSecuries.cs b/SecuritySystem/FormSecuries.cs
new file mode 100644
index 0000000..acd9911
--- /dev/null
+++ b/SecuritySystem/FormSecuries.cs
@@ -0,0 +1,107 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystem;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+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 SecuritySystemView
+{
+ public partial class FormSecuries : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ISecureLogic _logic;
+ public FormSecuries(ILogger logger, ISecureLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormSecuries_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["SecureComponents"].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 ButtonDel_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();
+ }
+ }
+}
diff --git a/SecuritySystem/FormSecuries.resx b/SecuritySystem/FormSecuries.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormSecuries.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/FormSecuriesComponent.Designer.cs b/SecuritySystem/FormSecuriesComponent.Designer.cs
new file mode 100644
index 0000000..bb2b8c6
--- /dev/null
+++ b/SecuritySystem/FormSecuriesComponent.Designer.cs
@@ -0,0 +1,119 @@
+namespace SecuritySystemView
+{
+ partial class FormSecuriesComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelComponent = new System.Windows.Forms.Label();
+ this.comboBoxComponent = new System.Windows.Forms.ComboBox();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelComponent
+ //
+ this.labelComponent.AutoSize = true;
+ this.labelComponent.Location = new System.Drawing.Point(12, 9);
+ this.labelComponent.Name = "labelComponent";
+ this.labelComponent.Size = new System.Drawing.Size(91, 20);
+ this.labelComponent.TabIndex = 0;
+ this.labelComponent.Text = "Компонент:";
+ //
+ // comboBoxComponent
+ //
+ this.comboBoxComponent.FormattingEnabled = true;
+ this.comboBoxComponent.Location = new System.Drawing.Point(119, 9);
+ this.comboBoxComponent.Name = "comboBoxComponent";
+ this.comboBoxComponent.Size = new System.Drawing.Size(355, 28);
+ this.comboBoxComponent.TabIndex = 1;
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(12, 51);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(93, 20);
+ this.labelCount.TabIndex = 2;
+ this.labelCount.Text = "Количество:";
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(119, 51);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(355, 27);
+ this.textBoxCount.TabIndex = 3;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(317, 94);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(136, 41);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(175, 94);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(136, 41);
+ this.buttonSave.TabIndex = 5;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormManufactureComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(486, 147);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.comboBoxComponent);
+ this.Controls.Add(this.labelComponent);
+ this.Name = "FormManufactureComponent";
+ this.Text = "Компонент изделия";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelComponent;
+ private ComboBox comboBoxComponent;
+ private Label labelCount;
+ private TextBox textBoxCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormSecuriesComponent.cs b/SecuritySystem/FormSecuriesComponent.cs
new file mode 100644
index 0000000..ad94391
--- /dev/null
+++ b/SecuritySystem/FormSecuriesComponent.cs
@@ -0,0 +1,88 @@
+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.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SecuritySystemView
+{
+ public partial class FormSecuriesComponent : Form
+ {
+ private readonly List? _list;
+ public int Id
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxComponent.SelectedValue);
+ }
+ set
+ {
+ comboBoxComponent.SelectedValue = value;
+ }
+ }
+ public IComponentModel? ComponentModel
+ {
+ 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 FormSecuriesComponent(IComponentLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxComponent.DisplayMember = "ComponentName";
+ comboBoxComponent.ValueMember = "Id";
+ comboBoxComponent.DataSource = _list;
+ comboBoxComponent.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxComponent.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();
+ }
+ }
+}
diff --git a/SecuritySystem/FormSecuriesComponent.resx b/SecuritySystem/FormSecuriesComponent.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormSecuriesComponent.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/Program.cs b/SecuritySystem/Program.cs
index 1cae504..f433d42 100644
--- a/SecuritySystem/Program.cs
+++ b/SecuritySystem/Program.cs
@@ -1,9 +1,23 @@
+using SecuritySystemView;
+using SecuritySystemBusinessLogic.BusinessLogics;
+using SecuritySystemListImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+using SecuritySystemListImplement.Implements;
+using SecuritySystemBusinessLogic;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.StoragesContracts;
+using System;
+
namespace SecuritySystem
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -11,7 +25,34 @@ namespace SecuritySystem
// 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());
+ }
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
}
}
}
\ No newline at end of file
diff --git a/SecuritySystem/SecuritySystem.csproj b/SecuritySystem/SecuritySystem.csproj
deleted file mode 100644
index b57c89e..0000000
--- a/SecuritySystem/SecuritySystem.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- WinExe
- net6.0-windows
- enable
- true
- enable
-
-
-
\ No newline at end of file
diff --git a/SecuritySystem/SecuritySystem.sln b/SecuritySystem/SecuritySystem.sln
index 566394b..74c4eb3 100644
--- a/SecuritySystem/SecuritySystem.sln
+++ b/SecuritySystem/SecuritySystem.sln
@@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystem", "SecuritySystem.csproj", "{39A7185D-F1F5-4892-BE6F-72B1A849CA84}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemView", "SecuritySystemView.csproj", "{39A7185D-F1F5-4892-BE6F-72B1A849CA84}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemContracts", "..\SecuritySystemContracts\SecuritySystemContracts.csproj", "{C1C491F5-4CB7-4B6B-92CE-41688769709A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemDataModels", "..\SecuritySystemDataModels\SecuritySystemDataModels.csproj", "{D12D1329-4362-472B-B6E6-D62B0FF00C63}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemListImplement", "..\SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{A5A3381B-3592-41B6-880F-333C2502DF02}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemBusinessLogic", "..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{EF5F4167-954D-4414-8F76-372410029641}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +23,22 @@ Global
{39A7185D-F1F5-4892-BE6F-72B1A849CA84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39A7185D-F1F5-4892-BE6F-72B1A849CA84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39A7185D-F1F5-4892-BE6F-72B1A849CA84}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C1C491F5-4CB7-4B6B-92CE-41688769709A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C1C491F5-4CB7-4B6B-92CE-41688769709A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C1C491F5-4CB7-4B6B-92CE-41688769709A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C1C491F5-4CB7-4B6B-92CE-41688769709A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D12D1329-4362-472B-B6E6-D62B0FF00C63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D12D1329-4362-472B-B6E6-D62B0FF00C63}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D12D1329-4362-472B-B6E6-D62B0FF00C63}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D12D1329-4362-472B-B6E6-D62B0FF00C63}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A5A3381B-3592-41B6-880F-333C2502DF02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A5A3381B-3592-41B6-880F-333C2502DF02}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A5A3381B-3592-41B6-880F-333C2502DF02}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A5A3381B-3592-41B6-880F-333C2502DF02}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EF5F4167-954D-4414-8F76-372410029641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EF5F4167-954D-4414-8F76-372410029641}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EF5F4167-954D-4414-8F76-372410029641}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EF5F4167-954D-4414-8F76-372410029641}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/SecuritySystem/SecuritySystemView.csproj b/SecuritySystem/SecuritySystemView.csproj
new file mode 100644
index 0000000..d92a318
--- /dev/null
+++ b/SecuritySystem/SecuritySystemView.csproj
@@ -0,0 +1,21 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SecuritySystem/nlog.config b/SecuritySystem/nlog.config
new file mode 100644
index 0000000..dcd37c8
--- /dev/null
+++ b/SecuritySystem/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SecuritySystemBusinessLogic/ComponentLogic.cs b/SecuritySystemBusinessLogic/ComponentLogic.cs
new file mode 100644
index 0000000..3b74f22
--- /dev/null
+++ b/SecuritySystemBusinessLogic/ComponentLogic.cs
@@ -0,0 +1,110 @@
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace SecuritySystemBusinessLogic.BusinessLogics
+{
+ public class ComponentLogic : IComponentLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentStorage _componentStorage;
+ public ComponentLogic(ILogger logger, IComponentStorage componentStorage)
+ {
+ _logger = logger;
+ _componentStorage = componentStorage;
+ }
+
+ public List? ReadList(ComponentSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id);
+ var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ComponentViewModel? ReadElement(ComponentSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id);
+ var element = _componentStorage.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(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ComponentBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_componentStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ComponentBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ throw new ArgumentNullException("Нет названия компонента",
+ nameof(model.ComponentName));
+ }
+ if (model.Cost <= 0)
+ {
+ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
+ }
+ _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
+ var element = _componentStorage.GetElement(new ComponentSearchModel
+ {
+ ComponentName = model.ComponentName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystemBusinessLogic/OrderLogic.cs b/SecuritySystemBusinessLogic/OrderLogic.cs
new file mode 100644
index 0000000..41cc69a
--- /dev/null
+++ b/SecuritySystemBusinessLogic/OrderLogic.cs
@@ -0,0 +1,112 @@
+using Microsoft.Extensions.Logging;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Enums;
+
+namespace SecuritySystemBusinessLogic
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderStorage _orderStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
+ 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 (!CheckStatus(model, OrderStatus.Принят, false)) return false;
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (!CheckStatus(model, OrderStatus.Выполняется)) return false;
+ return true;
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (!CheckStatus(model, OrderStatus.Выдан)) return false;
+ return true;
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (!CheckStatus(model, OrderStatus.Готов)) return false;
+ return true;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.SecureId < 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор камеры", nameof(model.SecureId));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("Количество камер в заказе должно быть больше 0", nameof(model.Count));
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
+ }
+ _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. SecureId: { SecureId}", model.Id, model.Sum, model.SecureId);
+ }
+
+ private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true)
+ {
+ if (model.Status != newstatus - 1)
+ {
+ _logger.LogWarning("Failed to change status");
+ return false;
+ }
+ model.Status = newstatus;
+ if (!update) return true;
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
+ return true;
+ }
+
+ }
+}
diff --git a/SecuritySystemBusinessLogic/SecureLogic.cs b/SecuritySystemBusinessLogic/SecureLogic.cs
new file mode 100644
index 0000000..78f5cc0
--- /dev/null
+++ b/SecuritySystemBusinessLogic/SecureLogic.cs
@@ -0,0 +1,115 @@
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace SecuritySystemBusinessLogic
+{
+ public class SecureLogic : ISecureLogic
+ {
+ private readonly ILogger _logger;
+ private readonly ISecureStorage _SecureStorage;
+
+ public SecureLogic(ILogger logger, ISecureStorage SecureStorage)
+ {
+ _logger = logger;
+ _SecureStorage = SecureStorage;
+ }
+
+ public List? ReadList(SecureSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{ Id}", model?.SecureName, model?.Id);
+ var list = model == null ? _SecureStorage.GetFullList() : _SecureStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ 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}", element.Id);
+ return element;
+ }
+
+ public bool Create(SecureBindingModel model)
+ {
+ CheckModel(model);
+ if (_SecureStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert 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;
+ }
+
+ private void CheckModel(SecureBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ 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}.Cost:{ Cost}. Id: { Id}", model.SecureName, model.Price, model.Id);
+ var element = _SecureStorage.GetElement(new SecureSearchModel
+ {
+ SecureName = model.SecureName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Камера с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj b/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj
new file mode 100644
index 0000000..cd17517
--- /dev/null
+++ b/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs b/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs
new file mode 100644
index 0000000..715822b
--- /dev/null
+++ b/SecuritySystemContracts/BindingModels/ComponentBindingModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SecuritySystemDataModels.Models;
+
+namespace SecuritySystemContracts.BindingModels
+{
+ public class ComponentBindingModel : IComponentModel
+ {
+ public int Id { get; set; }
+ public string ComponentName { get; set; } = string.Empty;
+ public double Cost { get; set; }
+
+ }
+}
diff --git a/SecuritySystemContracts/BindingModels/OrderBindingModel.cs b/SecuritySystemContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..ae51c4c
--- /dev/null
+++ b/SecuritySystemContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,17 @@
+using SecuritySystemDataModels.Models;
+using SecuritySystemDataModels.Enums;
+
+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 string SecureName { get; set; } = string.Empty;
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/SecuritySystemContracts/BindingModels/SecureBindingModel.cs b/SecuritySystemContracts/BindingModels/SecureBindingModel.cs
new file mode 100644
index 0000000..2a24bee
--- /dev/null
+++ b/SecuritySystemContracts/BindingModels/SecureBindingModel.cs
@@ -0,0 +1,17 @@
+
+using SecuritySystemDataModels.Models;
+
+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 SecureComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs b/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs
new file mode 100644
index 0000000..48c12b3
--- /dev/null
+++ b/SecuritySystemContracts/BusinessLogicsContracts/IComponentLogic.cs
@@ -0,0 +1,15 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+
+namespace SecuritySystemContracts.BusinessLogicsContracts
+{
+ public interface IComponentLogic
+ {
+ List? ReadList(ComponentSearchModel? model);
+ ComponentViewModel? ReadElement(ComponentSearchModel model);
+ bool Create(ComponentBindingModel model);
+ bool Update(ComponentBindingModel model);
+ bool Delete(ComponentBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs b/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..d63e239
--- /dev/null
+++ b/SecuritySystemContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,20 @@
+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? ReadList(OrderSearchModel? model);
+ bool CreateOrder(OrderBindingModel model);
+ bool TakeOrderInWork(OrderBindingModel model);
+ bool FinishOrder(OrderBindingModel model);
+ bool DeliveryOrder(OrderBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs b/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs
new file mode 100644
index 0000000..58f0398
--- /dev/null
+++ b/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs
@@ -0,0 +1,21 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.BusinessLogicsContracts
+{
+ public interface ISecureLogic
+ {
+ List? ReadList(SecureSearchModel? model);
+ SecureViewModel? ReadElement(SecureSearchModel model);
+ bool Create(SecureBindingModel model);
+ bool Update(SecureBindingModel model);
+ bool Delete(SecureBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs b/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs
new file mode 100644
index 0000000..a5c4976
--- /dev/null
+++ b/SecuritySystemContracts/SearchModels/ComponentSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.SearchModels
+{
+ public class ComponentSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComponentName { get; set; }
+ }
+}
diff --git a/SecuritySystemContracts/SearchModels/OrderSearchModel.cs b/SecuritySystemContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..f07e85e
--- /dev/null
+++ b/SecuritySystemContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,13 @@
+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; }
+ }
+}
diff --git a/SecuritySystemContracts/SearchModels/SecureSearchModel.cs b/SecuritySystemContracts/SearchModels/SecureSearchModel.cs
new file mode 100644
index 0000000..8547e9f
--- /dev/null
+++ b/SecuritySystemContracts/SearchModels/SecureSearchModel.cs
@@ -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 SecureSearchModel
+ {
+ public int? Id { get; set; }
+ public string? SecureName { get; set; }
+
+ }
+}
diff --git a/SecuritySystemContracts/SecuritySystemContracts.csproj b/SecuritySystemContracts/SecuritySystemContracts.csproj
new file mode 100644
index 0000000..c816b99
--- /dev/null
+++ b/SecuritySystemContracts/SecuritySystemContracts.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SecuritySystemContracts/StorageContracts/IComponentStorage.cs b/SecuritySystemContracts/StorageContracts/IComponentStorage.cs
new file mode 100644
index 0000000..6bfb296
--- /dev/null
+++ b/SecuritySystemContracts/StorageContracts/IComponentStorage.cs
@@ -0,0 +1,21 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.StoragesContracts
+{
+ public interface IComponentStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComponentSearchModel model);
+ ComponentViewModel? GetElement(ComponentSearchModel model);
+ ComponentViewModel? Insert(ComponentBindingModel model);
+ ComponentViewModel? Update(ComponentBindingModel model);
+ ComponentViewModel? Delete(ComponentBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/StorageContracts/IOrderStorage.cs b/SecuritySystemContracts/StorageContracts/IOrderStorage.cs
new file mode 100644
index 0000000..b0ed803
--- /dev/null
+++ b/SecuritySystemContracts/StorageContracts/IOrderStorage.cs
@@ -0,0 +1,21 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.StoragesContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/StorageContracts/ISecureStorage.cs b/SecuritySystemContracts/StorageContracts/ISecureStorage.cs
new file mode 100644
index 0000000..7dc62cc
--- /dev/null
+++ b/SecuritySystemContracts/StorageContracts/ISecureStorage.cs
@@ -0,0 +1,21 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.StoragesContracts
+{
+ public interface ISecureStorage
+ {
+ List GetFullList();
+ List GetFilteredList(SecureSearchModel model);
+ SecureViewModel? GetElement(SecureSearchModel model);
+ SecureViewModel? Insert(SecureBindingModel model);
+ SecureViewModel? Update(SecureBindingModel model);
+ SecureViewModel? Delete(SecureBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/ViewModels/ComponentViewModel.cs b/SecuritySystemContracts/ViewModels/ComponentViewModel.cs
new file mode 100644
index 0000000..08769e5
--- /dev/null
+++ b/SecuritySystemContracts/ViewModels/ComponentViewModel.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using SecuritySystemDataModels.Models;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.ViewModels
+{
+ public class ComponentViewModel : IComponentModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название компонента")]
+ public string ComponentName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Cost { get; set; }
+ }
+}
diff --git a/SecuritySystemContracts/ViewModels/OrderViewModel.cs b/SecuritySystemContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..498fcbf
--- /dev/null
+++ b/SecuritySystemContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using SecuritySystemDataModels.Models;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SecuritySystemDataModels.Enums;
+
+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; }
+
+ OrderStatus IOrderModel.Status => throw new NotImplementedException();
+ }
+}
diff --git a/SecuritySystemContracts/ViewModels/SecureViewModel.cs b/SecuritySystemContracts/ViewModels/SecureViewModel.cs
new file mode 100644
index 0000000..4480475
--- /dev/null
+++ b/SecuritySystemContracts/ViewModels/SecureViewModel.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using SecuritySystemDataModels.Models;
+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 SecureComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/SecuritySystemDataModels/Enums/OrderStatus.cs b/SecuritySystemDataModels/Enums/OrderStatus.cs
new file mode 100644
index 0000000..a52f920
--- /dev/null
+++ b/SecuritySystemDataModels/Enums/OrderStatus.cs
@@ -0,0 +1,17 @@
+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
+ }
+}
diff --git a/SecuritySystemDataModels/IId.cs b/SecuritySystemDataModels/IId.cs
new file mode 100644
index 0000000..2a1f738
--- /dev/null
+++ b/SecuritySystemDataModels/IId.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDataModels
+{
+ public interface IId
+ {
+ int Id { get; }
+ }
+}
diff --git a/SecuritySystemDataModels/Models/IComponentModel.cs b/SecuritySystemDataModels/Models/IComponentModel.cs
new file mode 100644
index 0000000..3b0c950
--- /dev/null
+++ b/SecuritySystemDataModels/Models/IComponentModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDataModels.Models
+{
+ public interface IComponentModel : IId
+ {
+ string ComponentName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/SecuritySystemDataModels/Models/IOrderModel.cs b/SecuritySystemDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..1f705ee
--- /dev/null
+++ b/SecuritySystemDataModels/Models/IOrderModel.cs
@@ -0,0 +1,20 @@
+using SecuritySystemDataModels.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDataModels.Models
+{
+ public interface IOrderModel : IId
+ {
+ int SecureId { get; }
+ int Count { get; }
+ double Sum { get; }
+ OrderStatus Status { get; }
+ DateTime DateCreate { get; }
+ DateTime? DateImplement { get; }
+ }
+}
diff --git a/SecuritySystemDataModels/Models/ISecureModel.cs b/SecuritySystemDataModels/Models/ISecureModel.cs
new file mode 100644
index 0000000..f675b0f
--- /dev/null
+++ b/SecuritySystemDataModels/Models/ISecureModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDataModels.Models
+{
+ public interface ISecureModel : IId
+ {
+ string SecureName { get; }
+ double Price { get; }
+ Dictionary SecureComponents { get; }
+ }
+}
diff --git a/SecuritySystemDataModels/SecuritySystemDataModels.csproj b/SecuritySystemDataModels/SecuritySystemDataModels.csproj
new file mode 100644
index 0000000..17fe669
--- /dev/null
+++ b/SecuritySystemDataModels/SecuritySystemDataModels.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/SecuritySystemListImplement/DataListSingletone.cs b/SecuritySystemListImplement/DataListSingletone.cs
new file mode 100644
index 0000000..7a9a84a
--- /dev/null
+++ b/SecuritySystemListImplement/DataListSingletone.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using SecuritySystemListImplement.Models;
+
+namespace SecuritySystemListImplement
+{
+ public class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Securies { get; set; }
+ private DataListSingleton()
+ {
+ Components = new List();
+ Orders = new List();
+ Securies = new List();
+ }
+ public static DataListSingleton GetInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new DataListSingleton();
+ }
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystemListImplement/Implements/ComponentStorage.cs b/SecuritySystemListImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..4d9bff8
--- /dev/null
+++ b/SecuritySystemListImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,104 @@
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemListImplement.Models;
+
+
+namespace SecuritySystemListImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataListSingleton _source;
+ public ComponentStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var component in _source.Components)
+ {
+ result.Add(component.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ComponentSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return result;
+ }
+ foreach (var component in _source.Components)
+ {
+ if (component.ComponentName.Contains(model.ComponentName))
+ {
+ result.Add(component.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var component in _source.Components)
+ {
+ if ((!string.IsNullOrEmpty(model.ComponentName) &&
+ component.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && component.Id == model.Id))
+ {
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var component in _source.Components)
+ {
+ if (model.Id <= component.Id)
+ {
+ model.Id = component.Id + 1;
+ }
+ }
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ foreach (var component in _source.Components)
+ {
+ if (component.Id == model.Id)
+ {
+ component.Update(model);
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ for (int i = 0; i < _source.Components.Count; ++i)
+ {
+ if (_source.Components[i].Id == model.Id)
+ {
+ var element = _source.Components[i];
+ _source.Components.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/SecuritySystemListImplement/Implements/OrderStorage.cs b/SecuritySystemListImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..a35d05f
--- /dev/null
+++ b/SecuritySystemListImplement/Implements/OrderStorage.cs
@@ -0,0 +1,115 @@
+using SecuritySystemListImplement.Models;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+
+using SecuritySystemListImplement;
+
+namespace SecuritySystemListImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+ public OrderStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var Order in _source.Orders)
+ {
+ result.Add(Order.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (model == null)
+ {
+ return result;
+ }
+ foreach (var Order in _source.Orders)
+ {
+ if (Order.Id == model.Id)
+ {
+ result.Add(Order.GetViewModel);
+ }
+ }
+ 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 Order.GetViewModel;
+ }
+ }
+ return null;
+ }
+ 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 newOrder.GetViewModel;
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var Order in _source.Orders)
+ {
+ if (Order.Id == model.Id)
+ {
+ Order.Update(model);
+ return Order.GetViewModel;
+ }
+ }
+ 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 element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ private OrderViewModel AttachSecureName(OrderViewModel model)
+ {
+ foreach (var secure in _source.Securies)
+ {
+ if (secure.Id == model.SecureId)
+ {
+ model.SecureName = secure.SecureName;
+ return model;
+ }
+ }
+ return model;
+ }
+
+ }
+}
diff --git a/SecuritySystemListImplement/Implements/SecureStorage.cs b/SecuritySystemListImplement/Implements/SecureStorage.cs
new file mode 100644
index 0000000..a01cbf9
--- /dev/null
+++ b/SecuritySystemListImplement/Implements/SecureStorage.cs
@@ -0,0 +1,102 @@
+using SecuritySystemListImplement.Models;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StoragesContracts;
+using SecuritySystemContracts.ViewModels;
+
+
+namespace SecuritySystemListImplement.Implements
+{
+ public class SecureStorage : ISecureStorage
+ {
+ private readonly DataListSingleton _source;
+ public SecureStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var Secure in _source.Securies)
+ {
+ result.Add(Secure.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(SecureSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.SecureName))
+ {
+ return result;
+ }
+ foreach (var Secure in _source.Securies)
+ {
+ if (Secure.SecureName.Contains(model.SecureName))
+ {
+ result.Add(Secure.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public SecureViewModel? GetElement(SecureSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var Secure in _source.Securies)
+ {
+ if ((!string.IsNullOrEmpty(model.SecureName) && Secure.SecureName == model.SecureName) ||
+ (model.Id.HasValue && Secure.Id == model.Id))
+ {
+ return Secure.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public SecureViewModel? Insert(SecureBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var Secure in _source.Securies)
+ {
+ if (model.Id <= Secure.Id)
+ {
+ model.Id = Secure.Id + 1;
+ }
+ }
+ var newSecure = Secure.Create(model);
+ if (newSecure == null)
+ {
+ return null;
+ }
+ _source.Securies.Add(newSecure);
+ return newSecure.GetViewModel;
+ }
+ public SecureViewModel? Update(SecureBindingModel model)
+ {
+ foreach (var Secure in _source.Securies)
+ {
+ if (Secure.Id == model.Id)
+ {
+ Secure.Update(model);
+ return Secure.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public SecureViewModel? Delete(SecureBindingModel model)
+ {
+ for (int i = 0; i < _source.Securies.Count; ++i)
+ {
+ if (_source.Securies[i].Id == model.Id)
+ {
+ var element = _source.Securies[i];
+ _source.Securies.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/SecuritySystemListImplement/Models/Component.cs b/SecuritySystemListImplement/Models/Component.cs
new file mode 100644
index 0000000..4254be1
--- /dev/null
+++ b/SecuritySystemListImplement/Models/Component.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+
+namespace SecuritySystemListImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Component? Create(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystemListImplement/Models/Order.cs b/SecuritySystemListImplement/Models/Order.cs
new file mode 100644
index 0000000..1d073ec
--- /dev/null
+++ b/SecuritySystemListImplement/Models/Order.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Enums;
+using SecuritySystemDataModels.Models;
+
+namespace SecuritySystemListImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+
+ public int SecureId { get; private set; }
+
+ public string SecureName { get; private set; } = string.Empty;
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ SecureId = model.SecureId,
+ SecureName = model.SecureName,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ Status = model.Status;
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ SecureId = SecureId,
+ SecureName = SecureName,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+ }
+}
diff --git a/SecuritySystemListImplement/Models/Secure.cs b/SecuritySystemListImplement/Models/Secure.cs
new file mode 100644
index 0000000..28e0c76
--- /dev/null
+++ b/SecuritySystemListImplement/Models/Secure.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+
+namespace SecuritySystemListImplement.Models
+{
+ public class Secure : ISecureModel
+ {
+ public int Id { get; private set; }
+ public string SecureName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary SecureComponents
+ {
+ get;
+ private set;
+ } = new Dictionary();
+ public static Secure? Create(SecureBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Secure()
+ {
+ Id = model.Id,
+ SecureName = model.SecureName,
+ Price = model.Price,
+ SecureComponents = model.SecureComponents
+ };
+ }
+ public void Update(SecureBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ SecureName = model.SecureName;
+ Price = model.Price;
+ SecureComponents = model.SecureComponents;
+ }
+ public SecureViewModel GetViewModel => new()
+ {
+ Id = Id,
+ SecureName = SecureName,
+ Price = Price,
+ SecureComponents = SecureComponents
+ };
+ }
+}
diff --git a/SecuritySystemListImplement/SecuritySystemListImplement.csproj b/SecuritySystemListImplement/SecuritySystemListImplement.csproj
new file mode 100644
index 0000000..7037095
--- /dev/null
+++ b/SecuritySystemListImplement/SecuritySystemListImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+