without front

This commit is contained in:
10Г Егор Романов 2023-04-23 10:08:28 +04:00
parent 513740d857
commit 91fb395e29
57 changed files with 1466 additions and 425 deletions

94
SecuritySystem/FormClients.Designer.cs generated Normal file
View File

@ -0,0 +1,94 @@
namespace SecuritySystemView
{
partial class FormClients
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(350, 312);
this.dataGridView.TabIndex = 0;
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(368, 12);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(75, 23);
this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(368, 53);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(75, 23);
this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormClients
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(464, 312);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.dataGridView);
this.Name = "FormClients";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Клиенты";
this.Load += new System.EventHandler(this.FormClients_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.Button buttonDel;
private System.Windows.Forms.Button buttonRef;
}
}

View File

@ -0,0 +1,78 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystemView
{
public partial class FormClients : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormClients_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["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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);
try
{
if (!_logic.Delete(new ClientBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
_logger.LogInformation("Удаление клиента");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления клиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -28,107 +28,133 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.labelSecure = new System.Windows.Forms.Label(); labelSecure = new Label();
this.comboBoxSecure = new System.Windows.Forms.ComboBox(); comboBoxSecure = new ComboBox();
this.labelCount = new System.Windows.Forms.Label(); labelCount = new Label();
this.textBoxCount = new System.Windows.Forms.TextBox(); textBoxCount = new TextBox();
this.labelSum = new System.Windows.Forms.Label(); labelSum = new Label();
this.textBoxSum = new System.Windows.Forms.TextBox(); textBoxSum = new TextBox();
this.buttonCancel = new System.Windows.Forms.Button(); buttonCancel = new Button();
this.buttonSave = new System.Windows.Forms.Button(); buttonSave = new Button();
this.SuspendLayout(); labelClient = new Label();
comboBoxClient = new ComboBox();
SuspendLayout();
// //
// labelSecure // labelSecure
// //
this.labelSecure.AutoSize = true; labelSecure.AutoSize = true;
this.labelSecure.Location = new System.Drawing.Point(12, 15); labelSecure.Location = new Point(10, 11);
this.labelSecure.Name = "labelSecure"; labelSecure.Name = "labelSecure";
this.labelSecure.Size = new System.Drawing.Size(75, 20); labelSecure.Size = new Size(59, 15);
this.labelSecure.TabIndex = 0; labelSecure.TabIndex = 0;
this.labelSecure.Text = "Изделие: "; labelSecure.Text = "Изделие: ";
// //
// comboBoxSecure // comboBoxSecure
// //
this.comboBoxSecure.FormattingEnabled = true; comboBoxSecure.FormattingEnabled = true;
this.comboBoxSecure.Location = new System.Drawing.Point(115, 12); comboBoxSecure.Location = new Point(101, 9);
this.comboBoxSecure.Name = "comboBoxSecure"; comboBoxSecure.Margin = new Padding(3, 2, 3, 2);
this.comboBoxSecure.Size = new System.Drawing.Size(358, 28); comboBoxSecure.Name = "comboBoxSecure";
this.comboBoxSecure.TabIndex = 1; comboBoxSecure.Size = new Size(314, 23);
this.comboBoxSecure.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSecure_SelectedIndexChanged); comboBoxSecure.TabIndex = 1;
comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged;
// //
// labelCount // labelCount
// //
this.labelCount.AutoSize = true; labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 49); labelCount.Location = new Point(10, 37);
this.labelCount.Name = "labelCount"; labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(97, 20); labelCount.Size = new Size(78, 15);
this.labelCount.TabIndex = 2; labelCount.TabIndex = 2;
this.labelCount.Text = "Количество: "; labelCount.Text = "Количество: ";
// //
// textBoxCount // textBoxCount
// //
this.textBoxCount.Location = new System.Drawing.Point(115, 46); textBoxCount.Location = new Point(101, 34);
this.textBoxCount.Name = "textBoxCount"; textBoxCount.Margin = new Padding(3, 2, 3, 2);
this.textBoxCount.Size = new System.Drawing.Size(358, 27); textBoxCount.Name = "textBoxCount";
this.textBoxCount.TabIndex = 3; textBoxCount.Size = new Size(314, 23);
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); textBoxCount.TabIndex = 3;
textBoxCount.TextChanged += TextBoxCount_TextChanged;
// //
// labelSum // labelSum
// //
this.labelSum.AutoSize = true; labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(12, 80); labelSum.Location = new Point(10, 63);
this.labelSum.Name = "labelSum"; labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(62, 20); labelSum.Size = new Size(51, 15);
this.labelSum.TabIndex = 4; labelSum.TabIndex = 4;
this.labelSum.Text = "Сумма: "; labelSum.Text = "Сумма: ";
// //
// textBoxSum // textBoxSum
// //
this.textBoxSum.Location = new System.Drawing.Point(115, 80); textBoxSum.Location = new Point(101, 60);
this.textBoxSum.Name = "textBoxSum"; textBoxSum.Margin = new Padding(3, 2, 3, 2);
this.textBoxSum.ReadOnly = true; textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(358, 27); textBoxSum.ReadOnly = true;
this.textBoxSum.TabIndex = 5; textBoxSum.Size = new Size(314, 23);
textBoxSum.TabIndex = 5;
// //
// buttonCancel // buttonCancel
// //
this.buttonCancel.Location = new System.Drawing.Point(337, 113); buttonCancel.Location = new Point(294, 126);
this.buttonCancel.Name = "buttonCancel"; buttonCancel.Margin = new Padding(3, 2, 3, 2);
this.buttonCancel.Size = new System.Drawing.Size(110, 32); buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 6; buttonCancel.Size = new Size(96, 24);
this.buttonCancel.Text = "Отмена"; buttonCancel.TabIndex = 6;
this.buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Text = "Отмена";
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
// //
// buttonSave // buttonSave
// //
this.buttonSave.Location = new System.Drawing.Point(221, 113); buttonSave.Location = new Point(192, 126);
this.buttonSave.Name = "buttonSave"; buttonSave.Margin = new Padding(3, 2, 3, 2);
this.buttonSave.Size = new System.Drawing.Size(110, 32); buttonSave.Name = "buttonSave";
this.buttonSave.TabIndex = 7; buttonSave.Size = new Size(96, 24);
this.buttonSave.Text = "Сохранить"; buttonSave.TabIndex = 7;
this.buttonSave.UseVisualStyleBackColor = true; buttonSave.Text = "Сохранить";
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// labelClient
//
labelClient.AutoSize = true;
labelClient.Location = new Point(10, 91);
labelClient.Name = "labelClient";
labelClient.Size = new Size(49, 15);
labelClient.TabIndex = 8;
labelClient.Text = "Клиент:";
//
// comboBoxClient
//
comboBoxClient.FormattingEnabled = true;
comboBoxClient.Location = new Point(101, 88);
comboBoxClient.Name = "comboBoxClient";
comboBoxClient.Size = new Size(314, 23);
comboBoxClient.TabIndex = 9;
// //
// FormCreateOrder // FormCreateOrder
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(485, 158); ClientSize = new Size(424, 161);
this.Controls.Add(this.buttonSave); Controls.Add(comboBoxClient);
this.Controls.Add(this.buttonCancel); Controls.Add(labelClient);
this.Controls.Add(this.textBoxSum); Controls.Add(buttonSave);
this.Controls.Add(this.labelSum); Controls.Add(buttonCancel);
this.Controls.Add(this.textBoxCount); Controls.Add(textBoxSum);
this.Controls.Add(this.labelCount); Controls.Add(labelSum);
this.Controls.Add(this.comboBoxSecure); Controls.Add(textBoxCount);
this.Controls.Add(this.labelSecure); Controls.Add(labelCount);
this.Name = "FormCreateOrder"; Controls.Add(comboBoxSecure);
this.Text = "Заказ"; Controls.Add(labelSecure);
this.Load += new System.EventHandler(this.FormCreateOrder_Load); Margin = new Padding(3, 2, 3, 2);
this.ResumeLayout(false); Name = "FormCreateOrder";
this.PerformLayout(); Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@ -141,5 +167,7 @@
private TextBox textBoxSum; private TextBox textBoxSum;
private Button buttonCancel; private Button buttonCancel;
private Button buttonSave; private Button buttonSave;
private Label labelClient;
private ComboBox comboBoxClient;
} }
} }

View File

@ -1,9 +1,5 @@
using Microsoft.Extensions.Logging; using System;
using SecuritySystemContracts.BindingModels; using System.Collections;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -13,6 +9,14 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormCreateOrder : Form public partial class FormCreateOrder : Form
@ -20,24 +24,52 @@ namespace SecuritySystemView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISecureLogic _logicM; private readonly ISecureLogic _logicM;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
private readonly IClientLogic _logicC;
private List<SecureViewModel>? _list; private List<SecureViewModel>? _list;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicM, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicM, IOrderLogic logicO, IClientLogic logicC)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logicM = logicM; _logicM = logicM;
_logicO = logicO; _logicO = logicO;
_logicC = logicC;
} }
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
{ {
_list = _logicM.ReadList(null); _logger.LogInformation("Загрузка поездок для заказа");
if (_list != null) try
{ {
comboBoxSecure.DisplayMember = "SecureName"; var list = _logicM.ReadList(null);
comboBoxSecure.ValueMember = "Id"; if (list != null)
comboBoxSecure.DataSource = _list; {
comboBoxSecure.SelectedItem = null; comboBoxSecure.DisplayMember = "SecureName";
_logger.LogInformation("Загрузка изделий для заказа"); comboBoxSecure.ValueMember = "Id";
comboBoxSecure.DataSource = list;
comboBoxSecure.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка поездок");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка списка клиентов");
try
{
var list = _logicC.ReadList(null);
if (list != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = list;
comboBoxClient.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void CalcSum() private void CalcSum()
@ -47,7 +79,7 @@ namespace SecuritySystemView
try try
{ {
int id = Convert.ToInt32(comboBoxSecure.SelectedValue); int id = Convert.ToInt32(comboBoxSecure.SelectedValue);
var Secure = _logicM.ReadElement(new SecureSearchModel { Id = id }); var Secure = _logicM.ReadElement(new SecuresearchModel { Id = id });
int count = Convert.ToInt32(textBoxCount.Text); int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (Secure?.Price ?? 0), 2).ToString(); textBoxSum.Text = Math.Round(count * (Secure?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа"); _logger.LogInformation("Расчет суммы заказа");
@ -79,6 +111,11 @@ namespace SecuritySystemView
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxClient.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа"); _logger.LogInformation("Создание заказа");
try try
{ {
@ -86,6 +123,7 @@ namespace SecuritySystemView
{ {
SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue),
SecureName = comboBoxSecure.Text, SecureName = comboBoxSecure.Text,
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text)
}); });

View File

@ -34,14 +34,15 @@
goodsToolStripMenuItem = new ToolStripMenuItem(); goodsToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem();
componentListToolStripMenuItem = new ToolStripMenuItem(); componentListToolStripMenuItem = new ToolStripMenuItem();
componentsSecureToolStripMenuItem = new ToolStripMenuItem();
orderListToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button(); buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button(); buttonOrderReady = new Button();
buttonIssuedOrder = new Button(); buttonIssuedOrder = new Button();
buttonRef = new Button(); buttonRef = new Button();
componentsSecureToolStripMenuItem = new ToolStripMenuItem(); clientsToolStripMenuItem = new ToolStripMenuItem();
orderListToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -59,7 +60,7 @@
// //
// guideToolStripMenuItem // guideToolStripMenuItem
// //
guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem }); guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem, clientsToolStripMenuItem });
guideToolStripMenuItem.Name = "guideToolStripMenuItem"; guideToolStripMenuItem.Name = "guideToolStripMenuItem";
guideToolStripMenuItem.Size = new Size(87, 20); guideToolStripMenuItem.Size = new Size(87, 20);
guideToolStripMenuItem.Text = "Справочник"; guideToolStripMenuItem.Text = "Справочник";
@ -67,14 +68,14 @@
// componentsToolStripMenuItem // componentsToolStripMenuItem
// //
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Size = new Size(145, 22); componentsToolStripMenuItem.Size = new Size(180, 22);
componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
// //
// goodsToolStripMenuItem // goodsToolStripMenuItem
// //
goodsToolStripMenuItem.Name = "goodsToolStripMenuItem"; goodsToolStripMenuItem.Name = "goodsToolStripMenuItem";
goodsToolStripMenuItem.Size = new Size(145, 22); goodsToolStripMenuItem.Size = new Size(180, 22);
goodsToolStripMenuItem.Text = "Изделия"; goodsToolStripMenuItem.Text = "Изделия";
goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click; goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click;
// //
@ -89,9 +90,23 @@
// //
componentListToolStripMenuItem.Name = "componentListToolStripMenuItem"; componentListToolStripMenuItem.Name = "componentListToolStripMenuItem";
componentListToolStripMenuItem.Size = new Size(218, 22); componentListToolStripMenuItem.Size = new Size(218, 22);
componentListToolStripMenuItem.Text = "Список компонентов"; componentListToolStripMenuItem.Text = "Список коспонентов";
componentListToolStripMenuItem.Click += ComponentListToolStripMenuItem_Click; componentListToolStripMenuItem.Click += ComponentListToolStripMenuItem_Click;
// //
// componentsSecureToolStripMenuItem
//
componentsSecureToolStripMenuItem.Name = "componentsSecureToolStripMenuItem";
componentsSecureToolStripMenuItem.Size = new Size(218, 22);
componentsSecureToolStripMenuItem.Text = "Компоненты по изделиям";
componentsSecureToolStripMenuItem.Click += ComponentSecuresToolStripMenuItem_Click;
//
// orderListToolStripMenuItem
//
orderListToolStripMenuItem.Name = "orderListToolStripMenuItem";
orderListToolStripMenuItem.Size = new Size(218, 22);
orderListToolStripMenuItem.Text = "Список заказов";
orderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click;
//
// dataGridView // dataGridView
// //
dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToAddRows = false;
@ -161,19 +176,12 @@
buttonRef.UseVisualStyleBackColor = true; buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click; buttonRef.Click += ButtonRef_Click;
// //
// componentsSecureToolStripMenuItem // clientsToolStripMenuItem
// //
componentsSecureToolStripMenuItem.Name = "componentsSecureToolStripMenuItem"; clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
componentsSecureToolStripMenuItem.Size = new Size(218, 22); clientsToolStripMenuItem.Size = new Size(180, 22);
componentsSecureToolStripMenuItem.Text = "Компоненты по изделиям"; clientsToolStripMenuItem.Text = "Клиенты";
componentsSecureToolStripMenuItem.Click += ComponentSecuresToolStripMenuItem_Click; clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
//
// orderListToolStripMenuItem
//
orderListToolStripMenuItem.Name = "orderListToolStripMenuItem";
orderListToolStripMenuItem.Size = new Size(218, 22);
orderListToolStripMenuItem.Text = "Список заказов";
orderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click;
// //
// FormMain // FormMain
// //
@ -190,7 +198,7 @@
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Margin = new Padding(3, 2, 3, 2); Margin = new Padding(3, 2, 3, 2);
Name = "FormMain"; Name = "FormMain";
Text = "Система охраны"; Text = "Кузнечная мастерская";
Load += FormMain_Load; Load += FormMain_Load;
menuStrip1.ResumeLayout(false); menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout(); menuStrip1.PerformLayout();
@ -215,5 +223,6 @@
private ToolStripMenuItem componentListToolStripMenuItem; private ToolStripMenuItem componentListToolStripMenuItem;
private ToolStripMenuItem componentsSecureToolStripMenuItem; private ToolStripMenuItem componentsSecureToolStripMenuItem;
private ToolStripMenuItem orderListToolStripMenuItem; private ToolStripMenuItem orderListToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem;
} }
} }

View File

@ -11,8 +11,9 @@ using System.Windows.Forms;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemDataModels.Models;
using SecuritySystemDataModels.Enums;
using SecuritySystemView;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -41,7 +42,8 @@ namespace SecuritySystemView
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["SecureId"].Visible = false; dataGridView.Columns["SecureId"].Visible = false;
dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
@ -61,8 +63,16 @@ namespace SecuritySystemView
} }
private void GoodsToolStripMenuItem_Click(object sender, EventArgs e) private void GoodsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecuries)); var service = Program.ServiceProvider?.GetService(typeof(FormSecures));
if (service is FormSecuries form) if (service is FormSecures form)
{
form.ShowDialog();
}
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{ {
form.ShowDialog(); form.ShowDialog();
} }
@ -86,13 +96,7 @@ namespace SecuritySystemView
{ {
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id
SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -117,15 +121,8 @@ namespace SecuritySystemView
{ {
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id
SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value), });
SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)
});
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -149,14 +146,7 @@ namespace SecuritySystemView
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = id, Id = id
SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -201,10 +191,5 @@ namespace SecuritySystemView
form.ShowDialog(); form.ShowDialog();
} }
} }
private void списокToolStripMenuItem_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@ -37,7 +37,7 @@ namespace SecuritySystemView
_logger.LogInformation("Загрузка изделия"); _logger.LogInformation("Загрузка изделия");
try try
{ {
var view = _logic.ReadElement(new SecureSearchModel { Id = _id.Value }); var view = _logic.ReadElement(new SecuresearchModel { Id = _id.Value });
if (view != null) if (view != null)
{ {
textBoxName.Text = view.SecureName; textBoxName.Text = view.SecureName;
@ -79,8 +79,8 @@ namespace SecuritySystemView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent));
if (service is FormSecuriesComponent form) if (service is FormSecureComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -105,8 +105,8 @@ namespace SecuritySystemView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent));
if (service is FormSecuriesComponent form) if (service is FormSecureComponent form)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;

View File

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

View File

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

View File

@ -1,6 +1,6 @@
namespace SecuritySystemView namespace SecuritySystemView
{ {
partial class FormSecuries partial class FormSecures
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -109,9 +109,9 @@
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.ToolsPanel);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormSecuries"; this.Name = "FormSecures";
this.Text = "Изделия"; this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormSecuries_Load); this.Load += new System.EventHandler(this.FormSecures_Load);
this.ToolsPanel.ResumeLayout(false); this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -14,17 +14,17 @@ using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormSecuries : Form public partial class FormSecures : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISecureLogic _logic; private readonly ISecureLogic _logic;
public FormSecuries(ILogger<FormSecuries> logger, ISecureLogic logic) public FormSecures(ILogger<FormSecures> logger, ISecureLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormSecuries_Load(object sender, EventArgs e) private void FormSecures_Load(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }

View File

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

View File

@ -9,6 +9,10 @@ using SecuritySystemDatabaseImplement.Implements;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StoragesContracts;
using SecureCompanyBusinessLogic.BusinessLogics; using SecureCompanyBusinessLogic.BusinessLogics;
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemView;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -40,10 +44,12 @@ namespace SecuritySystemView
services.AddTransient<IComponentStorage, ComponentStorage>(); services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISecureStorage, SecureStorage>(); services.AddTransient<ISecurestorage, Securestorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISecureLogic, SecureLogic>(); services.AddTransient<ISecureLogic, SecureLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IReportLogic, ReportLogic>(); services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -54,10 +60,11 @@ namespace SecuritySystemView
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>(); services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSecure>(); services.AddTransient<FormSecure>();
services.AddTransient<FormSecuriesComponent>(); services.AddTransient<FormSecureComponent>();
services.AddTransient<FormSecuries>(); services.AddTransient<FormSecures>();
services.AddTransient<FormReportSecureComponents>(); services.AddTransient<FormReportSecureComponents>();
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
} }
} }
} }

View File

@ -5,6 +5,6 @@
Renaming the file extension or editing the content of this file may Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program. cause the file to be unrecognizable by the program.
--> -->
<GenericObjectDataSource DisplayName="ISecureStorage" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource"> <GenericObjectDataSource DisplayName="ISecurestorage" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>SecuritySystemContracts.StoragesContracts.ISecureStorage, SecuritySystemContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo> <TypeInfo>SecuritySystemContracts.StoragesContracts.ISecurestorage, SecuritySystemContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource> </GenericObjectDataSource>

View File

@ -0,0 +1,117 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. ClientFIO:{ClientFIO}. Id:{Id}", model?.ClientFIO, model?.Id);
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientFIO:{ClientFIO}. Id:{Id}", model.ClientFIO, model.Id);
var element = _clientStorage.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(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля учетной записи клиента", nameof(model.ClientFIO));
}
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Email:{Email}. Password:{Password}. Id:{Id}", model.ClientFIO, model.Email, model.Password, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}
}

View File

@ -11,15 +11,15 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
public class ReportLogic : IReportLogic public class ReportLogic : IReportLogic
{ {
private readonly IComponentStorage _componentStorage; private readonly IComponentStorage _componentStorage;
private readonly ISecureStorage _SecureStorage; private readonly ISecurestorage _Securestorage;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf; private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ISecureStorage SecureStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, public ReportLogic(ISecurestorage Securestorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{ {
_SecureStorage = SecureStorage; _Securestorage = Securestorage;
_componentStorage = componentStorage; _componentStorage = componentStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_saveToExcel = saveToExcel; _saveToExcel = saveToExcel;
@ -34,7 +34,7 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
public List<ReportSecureComponentViewModel> GetSecureComponent() public List<ReportSecureComponentViewModel> GetSecureComponent()
{ {
var components = _componentStorage.GetFullList(); var components = _componentStorage.GetFullList();
var Secures = _SecureStorage.GetFullList(); var Secures = _Securestorage.GetFullList();
var list = new List<ReportSecureComponentViewModel>(); var list = new List<ReportSecureComponentViewModel>();
foreach (var Secure in Secures) foreach (var Secure in Secures)
@ -88,7 +88,7 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список компонент", Title = "Список компонент",
Secures = _SecureStorage.GetFullList() Secures = _Securestorage.GetFullList()
}); });
} }

View File

@ -11,18 +11,18 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public class SecureLogic : ISecureLogic public class SecureLogic : ISecureLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISecureStorage _SecureStorage; private readonly ISecurestorage _Securestorage;
public SecureLogic(ILogger<SecureLogic> logger, ISecureStorage SecureStorage) public SecureLogic(ILogger<SecureLogic> logger, ISecurestorage Securestorage)
{ {
_logger = logger; _logger = logger;
_SecureStorage = SecureStorage; _Securestorage = Securestorage;
} }
public List<SecureViewModel>? ReadList(SecureSearchModel? model) public List<SecureViewModel>? ReadList(SecuresearchModel? model)
{ {
_logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{ Id}", model?.SecureName, model?.Id); _logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{ Id}", model?.SecureName, model?.Id);
var list = model == null ? _SecureStorage.GetFullList() : _SecureStorage.GetFilteredList(model); var list = model == null ? _Securestorage.GetFullList() : _Securestorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
@ -32,14 +32,14 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
return list; return list;
} }
public SecureViewModel? ReadElement(SecureSearchModel model) public SecureViewModel? ReadElement(SecuresearchModel model)
{ {
if (model == null) if (model == null)
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation("ReadElement. SecureName:{SecureName}.Id:{ Id}", model.SecureName, model.Id); _logger.LogInformation("ReadElement. SecureName:{SecureName}.Id:{ Id}", model.SecureName, model.Id);
var element = _SecureStorage.GetElement(model); var element = _Securestorage.GetElement(model);
if (element == null) if (element == null)
{ {
_logger.LogWarning("ReadElement element not found"); _logger.LogWarning("ReadElement element not found");
@ -52,7 +52,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public bool Create(SecureBindingModel model) public bool Create(SecureBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_SecureStorage.Insert(model) == null) if (_Securestorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
@ -63,7 +63,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public bool Update(SecureBindingModel model) public bool Update(SecureBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_SecureStorage.Update(model) == null) if (_Securestorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
@ -75,7 +75,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
{ {
CheckModel(model, false); CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id); _logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_SecureStorage.Delete(model) == null) if (_Securestorage.Delete(model) == null)
{ {
_logger.LogWarning("Delete operation failed"); _logger.LogWarning("Delete operation failed");
return false; return false;
@ -102,7 +102,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
throw new ArgumentNullException("Цена камеры должна быть больше 0", nameof(model.Price)); throw new ArgumentNullException("Цена камеры должна быть больше 0", nameof(model.Price));
} }
_logger.LogInformation("Secure. SecureName:{SecureName}.Cost:{ Cost}. Id: { Id}", model.SecureName, model.Price, model.Id); _logger.LogInformation("Secure. SecureName:{SecureName}.Cost:{ Cost}. Id: { Id}", model.SecureName, model.Price, model.Id);
var element = _SecureStorage.GetElement(new SecureSearchModel var element = _Securestorage.GetElement(new SecuresearchModel
{ {
SecureName = model.SecureName SecureName = model.SecureName
}); });

View File

@ -0,0 +1,17 @@
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BindingModels
{
public class ClientBindingModel : IClientModel
{
public int Id { get; set; }
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -7,6 +7,7 @@ namespace SecuritySystemContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public int SecureId { get; set; } public int SecureId { get; set; }
public int ClientId { get; set; }
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public string SecureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;

View File

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

View File

@ -12,8 +12,8 @@ namespace SecuritySystemContracts.BusinessLogicsContracts
{ {
public interface ISecureLogic public interface ISecureLogic
{ {
List<SecureViewModel>? ReadList(SecureSearchModel? model); List<SecureViewModel>? ReadList(SecuresearchModel? model);
SecureViewModel? ReadElement(SecureSearchModel model); SecureViewModel? ReadElement(SecuresearchModel model);
bool Create(SecureBindingModel model); bool Create(SecureBindingModel model);
bool Update(SecureBindingModel model); bool Update(SecureBindingModel model);
bool Delete(SecureBindingModel model); bool Delete(SecureBindingModel model);

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
public string? ClientFIO { get; set; }
public string? Email { get; set;}
public string? Password { get; set;}
}
}

View File

@ -9,6 +9,7 @@ namespace SecuritySystemContracts.SearchModels
public class OrderSearchModel public class OrderSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
} }

View File

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

View File

@ -0,0 +1,23 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.StorageContracts
{
public interface IClientStorage
{
List<ClientViewModel> GetFullList();
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
ClientViewModel? GetElement(ClientSearchModel model);
ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model);
}
}

View File

@ -9,11 +9,11 @@ using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts namespace SecuritySystemContracts.StoragesContracts
{ {
public interface ISecureStorage public interface ISecurestorage
{ {
List<SecureViewModel> GetFullList(); List<SecureViewModel> GetFullList();
List<SecureViewModel> GetFilteredList(SecureSearchModel model); List<SecureViewModel> GetFilteredList(SecuresearchModel model);
SecureViewModel? GetElement(SecureSearchModel model); SecureViewModel? GetElement(SecuresearchModel model);
SecureViewModel? Insert(SecureBindingModel model); SecureViewModel? Insert(SecureBindingModel model);
SecureViewModel? Update(SecureBindingModel model); SecureViewModel? Update(SecureBindingModel model);
SecureViewModel? Delete(SecureBindingModel model); SecureViewModel? Delete(SecureBindingModel model);

View File

@ -0,0 +1,21 @@
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
public int Id { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -17,6 +17,9 @@ namespace SecuritySystemContracts.ViewModels
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string SecureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]
public double Sum { get; set; } public double Sum { get; set; }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models
{
public interface IClientModel : IId
{
string ClientFIO { get; }
string Email { get; }
string Password { get; }
}
}

View File

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

View File

@ -0,0 +1,96 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public List<ClientViewModel> GetFullList()
{
using var context = new SecuritySystemDatabase();
return context.Clients
.Include(x => x.Orders)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (model == null)
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new SecuritySystemDatabase();
return context.Clients
.Include(x => x.Orders)
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
using var context = new SecuritySystemDatabase();
if (model.Id.HasValue)
{
return context.Clients
.FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
return context.Clients
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel;
}
return new();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new SecuritySystemDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new SecuritySystemDatabase();
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new SecuritySystemDatabase();
var element = context.Clients
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,9 +1,10 @@
using SecuritySystemContracts.BindingModels; 
using Microsoft.EntityFrameworkCore;
using SecuritySystemDatabaseImplement.Models;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Microsoft.EntityFrameworkCore;
using SecuritySystemDatabaseImplement.Models;
namespace SecuritySystemDatabaseImplement.Implements namespace SecuritySystemDatabaseImplement.Implements
{ {
@ -15,7 +16,11 @@ namespace SecuritySystemDatabaseImplement.Implements
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
var deletedElement = context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; var deletedElement = context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element); context.Orders.Remove(element);
context.SaveChanges(); context.SaveChanges();
return deletedElement; return deletedElement;
@ -29,29 +34,55 @@ namespace SecuritySystemDatabaseImplement.Implements
return null; return null;
} }
using var context = new SecuritySystemDatabase(); using var context = new SecuritySystemDatabase();
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (model is null)
return new();
using var context = new SecuritySystemDatabase(); using var context = new SecuritySystemDatabase();
if (!model.Id.HasValue) if (model.Id.HasValue)
{ {
return context.Orders return context.Orders
.Include(x => x.Secure) .Include(x => x.Secure)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.DateFrom != null && model.DateTo != null)
{
return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
else if (model.ClientId.HasValue)
return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); {
return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new SecuritySystemDatabase(); using var context = new SecuritySystemDatabase();
return context.Orders.Include(x => x.Secure).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
@ -63,7 +94,11 @@ namespace SecuritySystemDatabaseImplement.Implements
using var context = new SecuritySystemDatabase(); using var context = new SecuritySystemDatabase();
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
@ -75,7 +110,11 @@ namespace SecuritySystemDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders
.Include(x => x.Secure)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
} }
} }
} }

View File

@ -6,14 +6,14 @@ using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace SecuritySystemDatabaseImplement.Implements namespace SecuritySystemDatabaseImplement.Implements
{ {
public class SecureStorage : ISecureStorage public class Securestorage : ISecurestorage
{ {
public List<SecureViewModel> GetFullList() public List<SecureViewModel> GetFullList()
{ {
using var context = new SecuritySystemDatabase(); using var context = new SecuritySystemDatabase();
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList();
} }
public List<SecureViewModel> GetFilteredList(SecureSearchModel model) public List<SecureViewModel> GetFilteredList(SecuresearchModel model)
{ {
if (string.IsNullOrEmpty(model.SecureName)) if (string.IsNullOrEmpty(model.SecureName))
{ {
@ -23,7 +23,7 @@ namespace SecuritySystemDatabaseImplement.Implements
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.SecureName.Contains(model.SecureName)).ToList() return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.SecureName.Contains(model.SecureName)).ToList()
.Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }
public SecureViewModel? GetElement(SecureSearchModel model) public SecureViewModel? GetElement(SecuresearchModel model)
{ {
if (string.IsNullOrEmpty(model.SecureName) && if (string.IsNullOrEmpty(model.SecureName) &&
!model.Id.HasValue) !model.Id.HasValue)

View File

@ -1,171 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SecuritySystemDatabaseImplement;
#nullable disable
namespace SecuritySystemDatabaseImplement.Migrations
{
[DbContext(typeof(SecuritySystemDatabase))]
[Migration("20230404083020_InitialCreate4")]
partial class InitialCreate4
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
b.Property<int>("SecureId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("SecureId");
b.ToTable("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<string>("SecureName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Secures");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("SecureId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("SecureId");
b.ToTable("SecureComponents");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Secure");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
.WithMany("SecureComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Components")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Secure");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Navigation("SecureComponents");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SecuritySystemDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate4 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -12,8 +12,8 @@ using SecuritySystemDatabaseImplement;
namespace SecuritySystemDatabaseImplement.Migrations namespace SecuritySystemDatabaseImplement.Migrations
{ {
[DbContext(typeof(SecuritySystemDatabase))] [DbContext(typeof(SecuritySystemDatabase))]
[Migration("20230404083007_InitialCreate")] [Migration("20230423054524_with client")]
partial class InitialCreate partial class withclient
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -25,6 +25,31 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -53,6 +78,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("integer"); .HasColumnType("integer");
@ -73,6 +101,8 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("SecureId"); b.HasIndex("SecureId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -126,12 +156,20 @@ namespace SecuritySystemDatabaseImplement.Migrations
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure") b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("SecureId") .HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Secure"); b.Navigation("Secure");
}); });
@ -154,6 +192,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.Navigation("Secure"); b.Navigation("Secure");
}); });
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("SecureComponents"); b.Navigation("SecureComponents");

View File

@ -7,11 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SecuritySystemDatabaseImplement.Migrations namespace SecuritySystemDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class withclient : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Components", name: "Components",
columns: table => new columns: table => new
@ -47,6 +62,7 @@ namespace SecuritySystemDatabaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SecureId = table.Column<int>(type: "integer", nullable: false), SecureId = table.Column<int>(type: "integer", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false), Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false), Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false), Status = table.Column<int>(type: "integer", nullable: false),
@ -56,6 +72,12 @@ namespace SecuritySystemDatabaseImplement.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Orders", x => x.Id); table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Secures_SecureId", name: "FK_Orders_Secures_SecureId",
column: x => x.SecureId, column: x => x.SecureId,
@ -91,6 +113,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_SecureId", name: "IX_Orders_SecureId",
table: "Orders", table: "Orders",
@ -116,6 +143,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "SecureComponents"); name: "SecureComponents");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Components"); name: "Components");

View File

@ -22,6 +22,31 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -50,6 +75,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("integer"); .HasColumnType("integer");
@ -70,6 +98,8 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("SecureId"); b.HasIndex("SecureId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -123,12 +153,20 @@ namespace SecuritySystemDatabaseImplement.Migrations
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure") b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("SecureId") .HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Secure"); b.Navigation("Secure");
}); });
@ -151,6 +189,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.Navigation("Secure"); b.Navigation("Secure");
}); });
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("SecureComponents"); b.Navigation("SecureComponents");

View File

@ -0,0 +1,57 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; set; }
[Required]
public string ClientFIO { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -17,6 +17,7 @@ namespace SecuritySystemDatabaseImplement.Models
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int SecureId { get; set; } public int SecureId { get; set; }
public int ClientId { get; set; }
[Required] [Required]
public int Count { get; set; } public int Count { get; set; }
[Required] [Required]
@ -27,6 +28,7 @@ namespace SecuritySystemDatabaseImplement.Models
public DateTime DateCreate { get; set; } public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public virtual Secure Secure { get; set; } public virtual Secure Secure { get; set; }
public virtual Client Client { get; set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@ -37,6 +39,7 @@ namespace SecuritySystemDatabaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
SecureId = model.SecureId, SecureId = model.SecureId,
ClientId = model.ClientId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -59,6 +62,8 @@ namespace SecuritySystemDatabaseImplement.Models
Id = Id, Id = Id,
SecureId = SecureId, SecureId = SecureId,
SecureName = Secure.SecureName, SecureName = Secure.SecureName,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,

View File

@ -17,5 +17,7 @@ namespace SecuritySystemDatabaseImplement
public virtual DbSet<Secure> Secures { set; get; } public virtual DbSet<Secure> Secures { set; get; }
public virtual DbSet<SecureComponent> SecureComponents { set; get; } public virtual DbSet<SecureComponent> SecureComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
} }
} }

View File

@ -15,9 +15,11 @@ namespace SecuritySystemFileImplement
private readonly string ComponentFileName = "Component.xml"; private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string SecureFileName = "Secure.xml"; private readonly string SecureFileName = "Secure.xml";
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; } public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Secure> Secures { get; private set; } public List<Secure> Secures { get; private set; }
public List<Client> Clients { get; private set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
if (instance == null) if (instance == null)
@ -29,11 +31,13 @@ namespace SecuritySystemFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement); public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!; Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
} }
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction) private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{ {

View File

@ -0,0 +1,87 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemFileImplement.Implements
{
public class ClientStorage : IClientStorage
{
private readonly DataFileSingleton source;
public ClientStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ClientViewModel> GetFullList()
{
return source.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (!string.IsNullOrEmpty(model.Email))
{
return source.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (model.Id.HasValue)
{
return source.Clients
.FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
return source.Clients
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel;
}
return new();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
source.Clients.Add(newClient);
source.SaveClients();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
source.SaveClients();
return client.GetViewModel;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client != null)
{
source.Clients.Remove(client);
source.SaveClients();
return client.GetViewModel;
}
return null;
}
}
}

View File

@ -22,10 +22,6 @@ namespace SecuritySystemFileImplement.Implements
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null))
{
return new();
}
if (model.Id.HasValue) if (model.Id.HasValue)
{ {
return source.Orders return source.Orders
@ -33,13 +29,21 @@ namespace SecuritySystemFileImplement.Implements
.Select(x => GetViewModel(x)) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
else else if (model.DateFrom != null && model.DateTo != null)
{ {
return source.Orders return source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
else if (model.ClientId.HasValue)
{
return source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => GetViewModel(x))
.ToList();
}
return new();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {

View File

@ -15,14 +15,14 @@ using SecuritySystemFileImplement;
namespace SecuritySystemFileImplement.Implements namespace SecuritySystemFileImplement.Implements
{ {
public class SecureStorage : ISecureStorage public class Securestorage : ISecurestorage
{ {
private readonly DataFileSingleton source; private readonly DataFileSingleton source;
public SecureStorage() public Securestorage()
{ {
source = DataFileSingleton.GetInstance(); source = DataFileSingleton.GetInstance();
} }
public SecureViewModel? GetElement(SecureSearchModel model) public SecureViewModel? GetElement(SecuresearchModel model)
{ {
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
{ {
@ -30,7 +30,7 @@ namespace SecuritySystemFileImplement.Implements
} }
return source.Secures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return source.Secures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<SecureViewModel> GetFilteredList(SecureSearchModel model) public List<SecureViewModel> GetFilteredList(SecuresearchModel model)
{ {
if (string.IsNullOrEmpty(model.SecureName)) if (string.IsNullOrEmpty(model.SecureName))
{ {

View File

@ -0,0 +1,70 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SecuritySystemFileImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password,
};
}
public static Client? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Client()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ClientFIO = element.Element("ClientFIO")!.Value,
Email = element.Element("Email")!.Value,
Password = element.Element("Password")!.Value
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("ClientFIO", ClientFIO),
new XElement("Email", Email),
new XElement("Password", Password));
}
}

View File

@ -16,6 +16,7 @@ namespace SecuritySystemFileImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public int SecureId { get; private set; } public int SecureId { get; private set; }
public int ClientId { get; private set; }
public string SecureName { get; private set; } = string.Empty; public string SecureName { get; private set; } = string.Empty;
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }

View File

@ -13,12 +13,14 @@ namespace SecuritySystemListImplement
private static DataListSingleton? _instance; private static DataListSingleton? _instance;
public List<Component> Components { get; set; } public List<Component> Components { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Secure> Securies { get; set; } public List<Secure> Secures { get; set; }
public List<Client> Clients { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Securies = new List<Secure>(); Secures = new List<Secure>();
Clients = new List<Client>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@ -0,0 +1,109 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemListImplement.Models;
namespace SecuritySystemListImplement.Implements
{
public class ClientStorage : IClientStorage
{
private readonly DataListSingleton _source;
public ClientStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ClientViewModel> GetFullList()
{
var result = new List<ClientViewModel>();
foreach (var client in _source.Clients)
{
result.Add(client.GetViewModel);
}
return result;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
var result = new List<ClientViewModel>();
if (string.IsNullOrEmpty(model.Email))
{
return result;
}
foreach (var client in _source.Clients)
{
if (client.Email.Contains(model.Email))
{
result.Add(client.GetViewModel);
}
}
return result;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (model.Id.HasValue)
{
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
return client.GetViewModel;
}
}
}
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
foreach (var client in _source.Clients)
{
if (client.Email == model.Email && client.Password == model.Password)
{
return client.GetViewModel;
}
}
}
return null;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
model.Id = 1;
foreach (var client in _source.Clients)
{
if (model.Id <= client.Id)
{
model.Id = client.Id + 1;
}
}
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
_source.Clients.Add(newClient);
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
client.Update(model);
return client.GetViewModel;
}
}
return null;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
for (int i = 0; i < _source.Clients.Count; ++i)
{
if (_source.Clients[i].Id == model.Id)
{
var element = _source.Clients[i];
_source.Clients.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

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

View File

@ -0,0 +1,50 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemListImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password,
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -16,16 +16,13 @@ namespace SecuritySystemListImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public int SecureId { get; private set; } public int SecureId { get; private set; }
public string SecureName { get; private set; } = string.Empty; public string SecureName { get; private set; } = string.Empty;
public int ClientId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)