not done but

This commit is contained in:
10Г Егор Романов 2023-05-16 01:43:26 +04:00
parent aa49b82389
commit 1f26d40ff0
81 changed files with 1397 additions and 1625 deletions

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.Attributes;
namespace SecuritySystemView
{
public static class DataGridViewExtension
{
public static void FillandConfigGrid<T>(this DataGridView grid, List<T>?
data)
{
if (data == null)
{
return;
}
grid.DataSource = data;
var type = typeof(T);
var properties = type.GetProperties();
foreach (DataGridViewColumn column in grid.Columns)
{
var property = properties.FirstOrDefault(x => x.Name ==
column.Name);
if (property == null)
{
throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем { column.Name }");
}
var attribute =
property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
if (attribute == null)
{
throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства { property.Name }");
}
// ищем нужный нам атрибут
if (attribute is ColumnAttribute columnAttr)
{
column.HeaderText = columnAttr.Title;
column.Visible = columnAttr.Visible;
if (columnAttr.IsUseAutoSize)
{
column.AutoSizeMode =
(DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode)
, columnAttr.GridViewAutoSize.ToString());
}
else
{
column.Width = columnAttr.Width;
}
}
}
}
}
}

View File

@ -1,15 +1,6 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; 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 namespace SecuritySystemView
{ {
@ -31,13 +22,7 @@ namespace SecuritySystemView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов"); _logger.LogInformation("Загрузка клиентов");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -115,5 +115,6 @@
private Label labelCost; private Label labelCost;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private DataGridView dataGridView;
} }
} }

View File

@ -1,16 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -32,16 +22,8 @@ namespace SecuritySystemView
{ {
try try
{ {
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Получение компонента"); _logger.LogInformation("Получение компонента");
var view = _logic.ReadElement(new ComponentSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ComponentName;
textBoxCost.Text = view.Cost.ToString();
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,7 +1,8 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemView; using SecuritySystem;
using SecuritySystemContracts.DI;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -42,28 +43,21 @@ namespace SecuritySystemView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var form = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = LoadData();
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }

View File

@ -1,15 +1,8 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using SecuritySystem;
using System.Collections.Generic; using SecuritySystemContracts.DI;
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 namespace SecuritySystemView
{ {
@ -31,17 +24,8 @@ namespace SecuritySystemView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null) _logger.LogInformation("Загрузка исполнителей");
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -51,30 +35,24 @@ namespace SecuritySystemView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{ }
LoadData(); }
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
{ if (form.ShowDialog() == DialogResult.OK)
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{ }
LoadData(); }
} }
}
}
}
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)

View File

@ -47,6 +47,7 @@ namespace SecuritySystemView
buttonRef = new Button(); buttonRef = new Button();
workToolStripMenuItem = new ToolStripMenuItem(); workToolStripMenuItem = new ToolStripMenuItem();
letterToolStripMenuItem = new ToolStripMenuItem(); letterToolStripMenuItem = new ToolStripMenuItem();
createBackupToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -55,7 +56,7 @@ namespace SecuritySystemView
// //
menuStrip1.ImageScalingSize = new Size(20, 20); menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem, отчетыToolStripMenuItem, workToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem, отчетыToolStripMenuItem, workToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem, отчетыToolStripMenuItem, workToolStripMenuItem, letterToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem, отчетыToolStripMenuItem, workToolStripMenuItem, letterToolStripMenuItem, createBackupToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(5, 2, 0, 2); menuStrip1.Padding = new Padding(5, 2, 0, 2);
@ -82,7 +83,7 @@ namespace SecuritySystemView
goodsToolStripMenuItem.Name = "goodsToolStripMenuItem"; goodsToolStripMenuItem.Name = "goodsToolStripMenuItem";
goodsToolStripMenuItem.Size = new Size(180, 22); goodsToolStripMenuItem.Size = new Size(180, 22);
goodsToolStripMenuItem.Text = "Изделия"; goodsToolStripMenuItem.Text = "Изделия";
goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click; goodsToolStripMenuItem.Click += SecuresToolStripMenuItem_Click;
// //
// clientsToolStripMenuItem // clientsToolStripMenuItem
// //
@ -110,7 +111,7 @@ namespace SecuritySystemView
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 += ComponentSecuresToolStripMenuItem_Click;
// //
// componentsSecureToolStripMenuItem // componentsSecureToolStripMenuItem
// //
@ -186,6 +187,13 @@ namespace SecuritySystemView
letterToolStripMenuItem.Size = new Size(77, 24); letterToolStripMenuItem.Size = new Size(77, 24);
letterToolStripMenuItem.Text = "Почта"; letterToolStripMenuItem.Text = "Почта";
letterToolStripMenuItem.Click += letterToolStripMenuItem_Click; letterToolStripMenuItem.Click += letterToolStripMenuItem_Click;
//
// createBackupToolStripMenuItem
//
createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem";
createBackupToolStripMenuItem.Size = new Size(123, 24);
createBackupToolStripMenuItem.Text = "Создать Бекап";
createBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click;
// //
// FormMain // FormMain
// //
@ -227,5 +235,6 @@ namespace SecuritySystemView
private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem ImplementersToolStripMenuItem;
private ToolStripMenuItem workToolStripMenuItem; private ToolStripMenuItem workToolStripMenuItem;
private ToolStripMenuItem letterToolStripMenuItem; private ToolStripMenuItem letterToolStripMenuItem;
private ToolStripMenuItem createBackupToolStripMenuItem;
} }
} }

View File

@ -1,15 +1,7 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SecuritySystemContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.DI;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -19,13 +11,15 @@ namespace SecuritySystemView
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess; _workProcess = workProcess;
_backUpLogic = backUpLogic;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
{ {
@ -35,79 +29,110 @@ namespace SecuritySystemView
{ {
try try
{ {
var list = _orderLogic.ReadList(null); dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SecureId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки заказов"); _logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
} }
} }
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var form = DependencyManager.Instance.Resolve<FormComponents>();
if (service is FormComponents form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void GoodsToolStripMenuItem_Click(object sender, EventArgs e) private void SecuresToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecures)); var form =
if (service is FormSecures form) DependencyManager.Instance.Resolve<FormSecures>();
{ form.ShowDialog();
form.ShowDialog();
}
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
} }
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
if (service is FormCreateOrder form) form.ShowDialog();
LoadData();
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{ {
form.ShowDialog(); int id =
LoadData(); Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new
OrderBindingModel
{ Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{ Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
} }
private void ButtonIssuedOrder_Click(object sender, EventArgs e) private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id =
_logger.LogInformation("Заказ No {id}. Меняется статус на 'Выдан'", id); Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
id);
try try
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new
{ OrderBindingModel
Id = id { Id = id });
});
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
_logger.LogInformation("Заказ No {id} выдан", id); _logger.LogInformation("Заказ {id} выдан", id);
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка отметки о выдачи заказа"); _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
} }
} }
} }
@ -115,7 +140,8 @@ namespace SecuritySystemView
{ {
LoadData(); LoadData();
} }
private void ComponentListToolStripMenuItem_Click(object sender, EventArgs e)
private void SecureToolStripMenuItem_Click(object sender, EventArgs e)
{ {
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK) if (dialog.ShowDialog() == DialogResult.OK)
@ -126,39 +152,63 @@ namespace SecuritySystemView
} }
private void ComponentSecuresToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentSecuresToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportSecureComponents)); var form = DependencyManager.Instance.Resolve<FormReportSecureComponents>();
if (service is FormReportSecureComponents form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void OrderListToolStripMenuItem_Click(object sender, EventArgs e) private void OrderListToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); var form = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var form = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormImplementers form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void WorkStartToolStripMenuItem_Click(object sender, EventArgs e) private void WorkStartToolStripMenuItem_Click(object sender, EventArgs e)
{ {
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); _workProcess.DoWork((DependencyManager.Instance.Resolve<IImplementerLogic>())!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
}
private void letterToolStripMenuItem_Click(object sender, EventArgs e) private void letterToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMessageInfos)); var form = DependencyManager.Instance.Resolve<FormMessageInfos>();
if (service is FormMessageInfos form) form.ShowDialog();
}
private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{ {
form.ShowDialog(); if (_backUpLogic != null)
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel
{
FolderName = fbd.SelectedPath
});
MessageBox.Show("Бекап создан", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
} }
} }
} }

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemView;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -31,14 +32,7 @@ namespace SecuritySystemView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
_logger.LogInformation("Загрузка писем"); _logger.LogInformation("Загрузка писем");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,18 +1,9 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SecuritySystemView; using SecuritySystemContracts.DI;
using SecuritySystemDataModels.Models;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
@ -23,6 +14,7 @@ namespace SecuritySystemView
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _SecureComponents; private Dictionary<int, (IComponentModel, int)> _SecureComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormSecure(ILogger<FormSecure> logger, ISecureLogic logic) public FormSecure(ILogger<FormSecure> logger, ISecureLogic logic)
{ {
InitializeComponent(); InitializeComponent();
@ -37,21 +29,22 @@ 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;
textBoxPrice.Text = view.Price.ToString(); textBoxPrice.Text = view.Price.ToString();
_SecureComponents = view.SecureComponents ?? new _SecureComponents = view.SecureComponents ?? new Dictionary<int, (IComponentModel, int)>();
Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки изделия"); _logger.LogError(ex, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
} }
@ -63,9 +56,9 @@ namespace SecuritySystemView
if (_SecureComponents != null) if (_SecureComponents != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _SecureComponents) foreach (var element in _SecureComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.ComponentName, element.Value.Item2 });
} }
textBoxPrice.Text = CalcPrice().ToString(); textBoxPrice.Text = CalcPrice().ToString();
} }
@ -73,57 +66,54 @@ namespace SecuritySystemView
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки компонент изделия"); _logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); var form = DependencyManager.Instance.Resolve<FormSecureComponent>();
if (service is FormSecureComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_SecureComponents.ContainsKey(form.Id))
{
_SecureComponents[form.Id] = (form.ComponentModel,
form.Count);
}
else
{
_SecureComponents.Add(form.Id, (form.ComponentModel,
form.Count));
}
LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var form = DependencyManager.Instance.Resolve<FormSecureComponent>();
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _SecureComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
{ {
return; return;
} }
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_SecureComponents.ContainsKey(form.Id)) _SecureComponents[form.Id] = (form.ComponentModel, form.Count);
{
_SecureComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_SecureComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData(); LoadData();
} }
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent));
if (service is FormSecureComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _SecureComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_SecureComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
@ -133,13 +123,13 @@ namespace SecuritySystemView
{ {
try try
{ {
_logger.LogInformation("Удаление компонента: {ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_SecureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _SecureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
LoadData(); LoadData();
} }
@ -153,17 +143,20 @@ namespace SecuritySystemView
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(textBoxPrice.Text)) if (string.IsNullOrEmpty(textBoxPrice.Text))
{ {
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return; return;
} }
if (_SecureComponents == null || _SecureComponents.Count == 0) if (_SecureComponents == null || _SecureComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните компоненты", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение изделия"); _logger.LogInformation("Сохранение изделия");
@ -181,7 +174,8 @@ namespace SecuritySystemView
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }

View File

@ -28,91 +28,77 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.ToolsPanel = new System.Windows.Forms.Panel();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.ToolsPanel.SuspendLayout(); this.ButtonAdd = new System.Windows.Forms.Button();
this.ButtonUpd = new System.Windows.Forms.Button();
this.ButtonDel = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// ToolsPanel
//
this.ToolsPanel.Controls.Add(this.buttonRef);
this.ToolsPanel.Controls.Add(this.buttonDel);
this.ToolsPanel.Controls.Add(this.buttonUpd);
this.ToolsPanel.Controls.Add(this.buttonAdd);
this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
this.ToolsPanel.Name = "ToolsPanel";
this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
this.ToolsPanel.TabIndex = 3;
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(31, 206);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(126, 36);
this.buttonRef.TabIndex = 3;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(31, 142);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(126, 36);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(31, 76);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(126, 36);
this.buttonUpd.TabIndex = 1;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(31, 16);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(126, 36);
this.buttonAdd.TabIndex = 0;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView // dataGridView
// //
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12); this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29; this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(590, 426); this.dataGridView.Size = new System.Drawing.Size(624, 446);
this.dataGridView.TabIndex = 2; this.dataGridView.TabIndex = 0;
// //
// FormSecure // ButtonAdd
//
this.ButtonAdd.Location = new System.Drawing.Point(630, 12);
this.ButtonAdd.Name = "ButtonAdd";
this.ButtonAdd.Size = new System.Drawing.Size(158, 29);
this.ButtonAdd.TabIndex = 1;
this.ButtonAdd.Text = "Добавить";
this.ButtonAdd.UseVisualStyleBackColor = true;
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// ButtonUpd
//
this.ButtonUpd.Location = new System.Drawing.Point(630, 47);
this.ButtonUpd.Name = "ButtonUpd";
this.ButtonUpd.Size = new System.Drawing.Size(158, 29);
this.ButtonUpd.TabIndex = 2;
this.ButtonUpd.Text = "Изменить";
this.ButtonUpd.UseVisualStyleBackColor = true;
this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// ButtonDel
//
this.ButtonDel.Location = new System.Drawing.Point(630, 82);
this.ButtonDel.Name = "ButtonDel";
this.ButtonDel.Size = new System.Drawing.Size(158, 29);
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(630, 117);
this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(158, 29);
this.ButtonRef.TabIndex = 4;
this.ButtonRef.Text = "Обновить";
this.ButtonRef.UseVisualStyleBackColor = true;
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormSecures
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonDel);
this.Controls.Add(this.ButtonUpd);
this.Controls.Add(this.ButtonAdd);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormSecures"; this.Name = "FormSecures";
this.Text = "Изделия"; this.Text = "FormSecures";
this.Load += new System.EventHandler(this.FormSecures_Load); this.Load += new System.EventHandler(this.FormSecures_Load);
this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -120,11 +106,10 @@
#endregion #endregion
private Panel ToolsPanel;
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView; private DataGridView dataGridView;
private Button ButtonAdd;
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
} }
} }

View File

@ -2,15 +2,7 @@
using SecuritySystemView; using SecuritySystemView;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using System; using SecuritySystemContracts.DI;
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 namespace SecuritySystemView
{ {
@ -32,60 +24,52 @@ namespace SecuritySystemView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null) _logger.LogInformation("Загрузка изделий");
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SecureComponents"].Visible = false;
dataGridView.Columns["SecureName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка изделий");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки изделий"); _logger.LogError(ex, "Ошибка загрузки изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
} }
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); var form = DependencyManager.Instance.Resolve <FormSecure>();
if (service is FormSecure form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
}
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); var form = DependencyManager.Instance.Resolve <FormSecure>();
if (service is FormSecure form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
}
} }
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление изделия"); _logger.LogInformation("Удаление изделия");
try try
{ {
if (!_logic.Delete(new SecureBindingModel { Id = id })) if (!_logic.Delete(new SecureBindingModel
{
Id = id
}))
{ {
throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
} }
@ -93,8 +77,9 @@ namespace SecuritySystemView
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления изделия"); _logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -1,38 +1,39 @@
using SecuritySystemView;
using SecuritySystemBusinessLogic.BusinessLogics;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SecuritySystemBusinessLogic.OfficePackage;
using SecuritySystemBusinessLogic.OfficePackage.Implements;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using SecuritySystemDatabaseImplement.Implements;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts;
using SecureCompanyBusinessLogic.BusinessLogics;
using SecuritySystemContracts.StorageContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemView;
using SecuritySystemDatabaseImplement.Implements;
using NLog.Extensions.Logging;
using SecuritySystemBusinessLogic.BusinessLogics;
using System;
using SecuritySystemBusinessLogic.OfficePackage.Implements;
using SecuritySystemBusinessLogic.OfficePackage;
using SecuritySystemBusinessLogic.MailWorker; using SecuritySystemBusinessLogic.MailWorker;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.DI;
using SecureCompanyBusinessLogic.BusinessLogics;
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemBusinessLogic.MailWorker;
using SecuritySystemBusinessLogic.OfficePackage.Implements;
using SecuritySystemBusinessLogic.OfficePackage;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemView;
namespace SecuritySystemView namespace SecuritySystem
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); var services = new ServiceCollection();
ConfigureServices(services); InitDependency();
_serviceProvider = services.BuildServiceProvider();
try try
{ {
var mailSender = var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
_serviceProvider.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel mailSender?.MailConfig(new MailConfigBindingModel
{ {
MailLogin = MailLogin =
@ -50,51 +51,51 @@ namespace SecuritySystemView
} }
catch (Exception ex) catch (Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
} }
Application.Run(_serviceProvider.GetRequiredService<FormMain>()); Application.Run(DependencyManager.Instance.Resolve<FormMain>());
} }
private static void ConfigureServices(ServiceCollection services) private static void InitDependency()
{ {
services.AddLogging(option => DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{ {
option.SetMinimumLevel(LogLevel.Information); option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config"); option.AddNLog("nlog.config");
}); });
services.AddTransient<IComponentStorage, ComponentStorage>(); DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
services.AddTransient<ISecureStorage, SecureStorage>(); DependencyManager.Instance.RegisterType<ISecureLogic, SecureLogic>();
services.AddTransient<IClientStorage, ClientStorage>(); DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
services.AddTransient<IImplementerStorage, ImplementerStorage>(); DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>(); DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IComponentLogic, ComponentLogic>(); DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISecureLogic, SecureLogic>(); DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
services.AddTransient<IClientLogic, ClientLogic>(); DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
services.AddTransient<IReportLogic, ReportLogic>(); DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>(); DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<IWorkProcess, WorkModeling>(); DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>(); DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); DependencyManager.Instance.RegisterType<FormMain>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); DependencyManager.Instance.RegisterType<FormComponent>();
services.AddTransient<FormMain>(); DependencyManager.Instance.RegisterType<FormComponents>();
services.AddTransient<FormComponent>(); DependencyManager.Instance.RegisterType<FormCreateOrder>();
services.AddTransient<FormComponents>(); DependencyManager.Instance.RegisterType<FormSecure>();
services.AddTransient<FormCreateOrder>(); DependencyManager.Instance.RegisterType<FormSecureComponent>();
services.AddTransient<FormSecure>(); DependencyManager.Instance.RegisterType<FormSecures>();
services.AddTransient<FormSecureComponent>(); DependencyManager.Instance.RegisterType<FormReportSecureComponents>();
services.AddTransient<FormSecures>(); DependencyManager.Instance.RegisterType<FormReportOrders>();
services.AddTransient<FormReportSecureComponents>(); DependencyManager.Instance.RegisterType<FormClients>();
services.AddTransient<FormReportOrders>(); DependencyManager.Instance.RegisterType<FormImplementers>();
services.AddTransient<FormClients>(); DependencyManager.Instance.RegisterType<FormImplementer>();
services.AddTransient<FormImplementers>(); DependencyManager.Instance.RegisterType<FormMessageInfos>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormMessageInfos>();
} }
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck(); private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
} }
} }

View File

@ -9,12 +9,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" /> <PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,105 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemDataModels;
namespace SecuritySystemBusinessLogic.BusinessLogics
{
public class BackUpLogic : IBackUpLogic
{
private readonly ILogger _logger;
private readonly IBackUpInfo _backUpInfo;
public BackUpLogic(ILogger<BackUpLogic> logger, IBackUpInfo backUpInfo)
{
_logger = logger;
_backUpInfo = backUpInfo;
}
public void CreateBackUp(BackUpSaveBinidngModel model)
{
if (_backUpInfo == null)
{
return;
}
try
{
_logger.LogDebug("Clear folder");
// зачистка папки и удаление старого архива
var dirInfo = new DirectoryInfo(model.FolderName);
if (dirInfo.Exists)
{
foreach (var file in dirInfo.GetFiles())
{
file.Delete();
}
}
_logger.LogDebug("Delete archive");
string fileName = $"{model.FolderName}.zip";
if (File.Exists(fileName))
{
File.Delete(fileName);
}
// берем метод для сохранения
_logger.LogDebug("Get assembly");
var typeIId = typeof(IId);
var assembly = typeIId.Assembly;
if (assembly == null)
{
throw new ArgumentNullException("Сборка не найдена",
nameof(assembly));
}
var types = assembly.GetTypes();
var method = GetType().GetMethod("SaveToFile",
BindingFlags.NonPublic | BindingFlags.Instance);
_logger.LogDebug("Find {count} types", types.Length);
foreach (var type in types)
{
if (type.IsInterface && type.GetInterface(typeIId.Name) !=
null)
{
var modelType =
_backUpInfo.GetTypeByModelInterface(type.Name);
if (modelType == null)
{
throw new InvalidOperationException($"Не найден класс - модель для { type.Name }");
}
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
// вызываем метод на выполнение
method?.MakeGenericMethod(modelType).Invoke(this, new
object[] { model.FolderName });
}
}
_logger.LogDebug("Create zip and remove folder");
// архивируем
ZipFile.CreateFromDirectory(model.FolderName, fileName);
// удаляем папку
dirInfo.Delete(true);
}
catch (Exception)
{
throw;
}
}
private void SaveToFile<T>(string folderName) where T : class, new()
{
var records = _backUpInfo.GetList<T>();
if (records == null)
{
_logger.LogWarning("{type} type get null list", typeof(T).Name);
return;
}
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
jsonFormatter.WriteObject(fs, records);
}
}
}

View File

@ -1,7 +1,7 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -2,7 +2,7 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -2,22 +2,10 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemBusinessLogic.MailWorker;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels;
using SecuritySystemDataModels.Enums; using SecuritySystemDataModels.Enums;
using SecuritySystemBusinessLogic.MailWorker;
namespace SecuritySystemBusinessLogic.BusinessLogics namespace SecuritySystemBusinessLogic.BusinessLogics
{ {

View File

@ -3,7 +3,7 @@ using SecuritySystemBusinessLogic.OfficePackage;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
namespace SecureCompanyBusinessLogic.BusinessLogics namespace SecureCompanyBusinessLogic.BusinessLogics

View File

@ -2,7 +2,7 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
public ColumnAttribute(string title = "", bool visible = true, int width
= 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool
isUseAutoSize = false)
{
Title = title;
Visible = visible;
Width = width;
GridViewAutoSize = gridViewAutoSize;
IsUseAutoSize = isUseAutoSize;
}
public string Title { get; private set; }
public bool Visible { get; private set; }
public int Width { get; private set; }
public GridViewAutoSize GridViewAutoSize { get; private set; }
public bool IsUseAutoSize { get; private set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.Attributes
{
public enum GridViewAutoSize
{
NotSet = 0,
None = 1,
ColumnHeader = 2,
AllCellsExceptHeader = 4,
AllCells = 6,
DisplayedCellsExceptHeader = 8,
DisplayedCells = 10,
Fill = 16
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BindingModels
{
public class BackUpSaveBinidngModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

@ -19,5 +19,6 @@ namespace SecuritySystemContracts.BindingModels
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public int Id => throw new NotImplementedException();
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
namespace SecuritySystemContracts.BusinessLogicsContracts
{
public interface IBackUpLogic
{
void CreateBackUp(BackUpSaveBinidngModel model);
}
}

View File

@ -1,10 +1,5 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.BusinessLogicsContracts namespace SecuritySystemContracts.BusinessLogicsContracts
{ {

View File

@ -0,0 +1,43 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.DI
{
public class DependencyManager
{
private readonly IDependencyContainer _dependencyManager;
private static DependencyManager? _manager;
private static readonly object _locjObject = new();
private DependencyManager()
{
_dependencyManager = new UnityDependencyContainer();
}
public static DependencyManager Instance
{
get
{
if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } }
return _manager;
}
}
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
ext.RegisterServices();
}
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
public void RegisterType<T, U>(bool isSingle = false) where U :
class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
public T Resolve<T>() => _dependencyManager.Resolve<T>();
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.DI
{
public interface IDependencyContainer
{
void AddLogging(Action<ILoggingBuilder> configure);
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
void RegisterType<T>(bool isSingle) where T : class;
T Resolve<T>();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.DI
{
public interface IImplementationExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -0,0 +1,62 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.DI
{
public class ServiceDependencyContainer : IDependencyContainer
{
private ServiceProvider? _serviceProvider;
private readonly ServiceCollection _serviceCollection;
public ServiceDependencyContainer()
{
_serviceCollection = new ServiceCollection();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
_serviceCollection.AddLogging(configure);
}
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T, U>();
}
else
{
_serviceCollection.AddTransient<T, U>();
}
_serviceProvider = null;
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T>();
}
else
{
_serviceCollection.AddTransient<T>();
}
_serviceProvider = null;
}
public T Resolve<T>()
{
if (_serviceProvider == null)
{
_serviceProvider = _serviceCollection.BuildServiceProvider();
}
return _serviceProvider.GetService<T>()!;
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.DI
{
public static partial class ServiceProviderLoader
{
public static IImplementationExtension? GetImplementationExtensions()
{
IImplementationExtension? source = null;
var files =
Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass &&
typeof(IImplementationExtension).IsAssignableFrom(t))
{
if (source == null)
{
source =
(IImplementationExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource =
(IImplementationExtension)Activator.CreateInstance(t)!;
if (newSource.Priority >
source.Priority)
{
source = newSource;
}
}
}
}
}
return source;
}
private static string TryGetImplementationExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null &&
!directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\ImplementationExtensions";
}
}
}

View File

@ -0,0 +1,55 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Unity.Microsoft.Logging;
namespace SecuritySystemContracts.DI
{
public class UnityDependencyContainer : IDependencyContainer
{
private UnityContainer? _unityContrainer;
public UnityDependencyContainer()
{
_unityContrainer = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
_unityContrainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure)));
}
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
{
if (isSingle)
{
_unityContrainer.RegisterSingleton<T, U>();
}
else
{
_unityContrainer.RegisterType<T, U>();
}
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_unityContrainer.RegisterSingleton<T>();
}
else
{
_unityContrainer.RegisterType<T>();
}
}
public T Resolve<T>()
{
return _unityContrainer.Resolve<T>();
}
}
}

View File

@ -10,6 +10,8 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.StorageContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts namespace SecuritySystemContracts.StorageContracts
{ {
public interface IClientStorage public interface IClientStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts namespace SecuritySystemContracts.StorageContracts
{ {
public interface IComponentStorage public interface IComponentStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts namespace SecuritySystemContracts.StorageContracts
{ {
public interface IOrderStorage public interface IOrderStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts namespace SecuritySystemContracts.StorageContracts
{ {
public interface ISecureStorage public interface ISecureStorage
{ {

View File

@ -5,17 +5,19 @@ using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SecuritySystemContracts.Attributes;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class ClientViewModel : IClientModel public class ClientViewModel : IClientModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("ФИО клиента")] [Column(title: "ФИО клиента", width: 75)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")] [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column(title: "Пароль", width: 75)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }
} }

View File

@ -1,19 +1,16 @@
using System; using SecuritySystemDataModels.Models;
using System.Collections.Generic; using SecuritySystemContracts.Attributes;
using System.ComponentModel;
using SecuritySystemDataModels.Models;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class ComponentViewModel : IComponentModel public class ComponentViewModel : IComponentModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название компонента")] [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width: 75)]
public double Cost { get; set; } public double Cost { get; set; }
} }
} }

View File

@ -1,26 +1,19 @@
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System; using SecuritySystemContracts.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
/// <summary> public class ImplementerViewModel : IImplementerModel
/// Исполнитель, выполняющий заказы {
/// </summary> [Column(visible: false)]
public class ImplementerViewModel : IImplementerModel public int Id { get; set; }
{ [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public int Id { get; set; } public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("ФИО исполнителя")] [Column(title: "Пароль", width: 75)]
public string ImplementerFIO { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column(title: "Стаж работы", width: 75)]
public string Password { get; set; } = string.Empty; public int WorkExperience { get; set; }
[DisplayName("Стаж работы")] [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public int WorkExperience { get; set; } public int Qualification { get; set; }
[DisplayName("Квалификация")] }
public int Qualification { get; set; }
}
} }

View File

@ -1,25 +1,23 @@
using System; using SecuritySystemDataModels.Models;
using System.Collections.Generic; using SecuritySystemContracts.Attributes;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemDataModels.Models;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class MessageInfoViewModel : IMessageInfoModel public class MessageInfoViewModel : IMessageInfoModel
{ {
[Column(visible: false)]
public string MessageId { get; set; } = string.Empty; public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public int? ClientId { get; set; } public int? ClientId { get; set; }
[DisplayName("Отправитель")] [Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата письма")] [Column(title: "Дата письма", width: 150)]
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
[DisplayName("Заголовок")] [Column(title: "Заголовок", width: 150)]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[DisplayName("Текст письма")] [Column(title: "Текст письма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
[Column(visible: false)]
public int Id => throw new NotImplementedException();
} }
} }

View File

@ -1,39 +1,35 @@
using System; using SecuritySystemDataModels.Enums;
using System.Collections.Generic;
using System.ComponentModel;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.Linq; using SecuritySystemContracts.Attributes;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemDataModels.Enums;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
[DisplayName("Номер")] [Column(title: "Номер", width: 75)]
public int Id { get; set; } public int Id { get; set; }
[Column(visible: false)]
public int SecureId { get; set; } public int SecureId { get; set; }
[DisplayName("Изделие")] [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SecureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[Column(visible: false)]
public int ClientId { get; set; } public int ClientId { get; set; }
[DisplayName("Клиент")] [Column(title: "Клиент", width: 200)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Column(visible: false)]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[DisplayName("Исполнитель")] [Column(title: "Исполнитель", width: 200)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Количество")] [Column(title: "Количество", width: 75)]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [Column(title: "Сумма", width: 75)]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [Column(title: "Статус", width: 75)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")] [Column(title: "Дата создания", width: 150)]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")] [Column(title: "Дата выполнения", width: 150)]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
OrderStatus IOrderModel.Status => throw new NotImplementedException();
} }
} }

View File

@ -1,20 +1,17 @@
using System; using SecuritySystemDataModels.Models;
using System.Collections.Generic; using SecuritySystemContracts.Attributes;
using System.ComponentModel;
using SecuritySystemDataModels.Models;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SecuritySystemContracts.ViewModels namespace SecuritySystemContracts.ViewModels
{ {
public class SecureViewModel : ISecureModel public class SecureViewModel : ISecureModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название изделия")] [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SecureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column(title: "Цена", width: 150)]
public double Price { get; set; } public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IComponentModel, int)> SecureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get; get;

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SecuritySystemDataModels.Models namespace SecuritySystemDataModels.Models
{ {
public interface IMessageInfoModel public interface IMessageInfoModel : IId
{ {
string MessageId { get; } string MessageId { get; }
int? ClientId { get; } int? ClientId { get; }

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.DI;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemDatabaseImplement.Implements;
namespace SecuritySystemDatabaseImplement
{
public class DatabaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.StorageContracts;
namespace SecuritySystemDatabaseImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new SecuritySystemDatabase();
return context.Set<T>().ToList();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass &&
type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}

View File

@ -1,6 +1,6 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -1,7 +1,7 @@
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
namespace SecuritySystemDatabaseImplement.Implements namespace SecuritySystemDatabaseImplement.Implements

View File

@ -4,7 +4,6 @@ using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using SecuritySystemContracts.StoragesContracts;
namespace SecuritySystemDatabaseImplement.Implements namespace SecuritySystemDatabaseImplement.Implements
{ {

View File

@ -1,6 +1,6 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -1,298 +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("20230502104117_lab7")]
partial class lab7
{
/// <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.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 =>
{
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.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp with time zone");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("MessageInfos");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
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?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("SecureId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
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.MessageInfo", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("MessageInfos")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SecuritySystemDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Implementer");
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.Client", b =>
{
b.Navigation("MessageInfos");
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Navigation("SecureComponents");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,215 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SecuritySystemDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class lab7 : Migration
{
/// <inheritdoc />
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(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ComponentName = table.Column<string>(type: "text", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Implementers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
WorkExperience = table.Column<int>(type: "integer", nullable: false),
Qualification = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Secures",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SecureName = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Secures", x => x.Id);
});
migrationBuilder.CreateTable(
name: "MessageInfos",
columns: table => new
{
MessageId = table.Column<string>(type: "text", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: true),
SenderName = table.Column<string>(type: "text", nullable: false),
DateDelivery = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Subject = table.Column<string>(type: "text", nullable: false),
Body = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MessageInfos", x => x.MessageId);
table.ForeignKey(
name: "FK_MessageInfos_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SecureId = table.Column<int>(type: "integer", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
ImplementerId = table.Column<int>(type: "integer", nullable: true),
Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
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(
name: "FK_Orders_Implementers_ImplementerId",
column: x => x.ImplementerId,
principalTable: "Implementers",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Orders_Secures_SecureId",
column: x => x.SecureId,
principalTable: "Secures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SecureComponents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SecureId = table.Column<int>(type: "integer", nullable: false),
ComponentId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SecureComponents", x => x.Id);
table.ForeignKey(
name: "FK_SecureComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SecureComponents_Secures_SecureId",
column: x => x.SecureId,
principalTable: "Secures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_MessageInfos_ClientId",
table: "MessageInfos",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
migrationBuilder.CreateIndex(
name: "IX_Orders_SecureId",
table: "Orders",
column: "SecureId");
migrationBuilder.CreateIndex(
name: "IX_SecureComponents_ComponentId",
table: "SecureComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_SecureComponents_SecureId",
table: "SecureComponents",
column: "SecureId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MessageInfos");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "SecureComponents");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Implementers");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Secures");
}
}
}

View File

@ -1,295 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SecuritySystemDatabaseImplement;
#nullable disable
namespace SecuritySystemDatabaseImplement.Migrations
{
[DbContext(typeof(SecuritySystemDatabase))]
partial class SecuritySystemDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
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 =>
{
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.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp with time zone");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("MessageInfos");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
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?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("SecureId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
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.MessageInfo", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("MessageInfos")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SecuritySystemDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Implementer");
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.Client", b =>
{
b.Navigation("MessageInfos");
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Navigation("SecureComponents");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,14 +13,19 @@ using SecuritySystemDatabaseImplement.Models;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")] [ForeignKey("ClientId")]
public virtual List<MessageInfo> MessageInfos { get; set; } = new(); public virtual List<MessageInfo> MessageInfos { get; set; } = new();

View File

@ -3,15 +3,20 @@ using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class Component : IComponentModel public class Component : IComponentModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
[DataMember]
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Cost { get; set; } public double Cost { get; set; }
[ForeignKey("ComponentId")] [ForeignKey("ComponentId")]
public virtual List<SecureComponent> SecureComponents { get; set; } = new(); public virtual List<SecureComponent> SecureComponents { get; set; } = new();

View File

@ -7,20 +7,27 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class Implementer public class Implementer
{ {
public int Id { get; private set; } [DataMember]
public int Id { get; private set; }
[Required] [Required]
public string ImplementerFIO { get; private set; } = string.Empty; [DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
[Required] [Required]
public string Password { get; private set; } = string.Empty; [DataMember]
public string Password { get; private set; } = string.Empty;
[Required] [Required]
public int WorkExperience { get; private set; } [DataMember]
public int WorkExperience { get; private set; }
[Required] [Required]
public int Qualification { get; private set; } [DataMember]
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")] [ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new(); public virtual List<Order> Orders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model) public static Implementer? Create(ImplementerBindingModel model)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
@ -10,19 +11,25 @@ using SecuritySystemDataModels.Models;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class MessageInfo : IMessageInfoModel public class MessageInfo : IMessageInfoModel
{ {
[DataMember]
[Key] [Key]
public string MessageId { get; private set; } = string.Empty; public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; } public int? ClientId { get; private set; }
[Required] [Required]
[DataMember]
public string SenderName { get; private set; } = string.Empty; public string SenderName { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public DateTime DateDelivery { get; private set; } public DateTime DateDelivery { get; private set; }
[Required] [Required]
[DataMember]
public string Subject { get; private set; } = string.Empty; public string Subject { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public virtual Client? Client { get; private set; } public virtual Client? Client { get; private set; }
@ -51,5 +58,6 @@ namespace SecuritySystemDatabaseImplement.Models
Subject = Subject, Subject = Subject,
Body = Body Body = Body
}; };
public int Id => throw new NotImplementedException();
} }
} }

View File

@ -4,27 +4,38 @@ using SecuritySystemDataModels.Enums;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public int SecureId { get; set; } public int SecureId { get; set; }
[Required] [Required]
[DataMember]
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[Required] [Required]
[DataMember]
public int Count { get; set; } public int Count { get; set; }
[Required] [Required]
[DataMember]
public double Sum { get; set; } public double Sum { get; set; }
[Required] [Required]
[DataMember]
public OrderStatus Status { get; set; } public OrderStatus Status { get; set; }
[Required] [Required]
[DataMember]
public DateTime DateCreate { get; set; } public DateTime DateCreate { get; set; }
[DataMember]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
[DataMember]
public virtual Secure Secure { get; set; } public virtual Secure Secure { get; set; }
public virtual Client Client { get; set; } public virtual Client Client { get; set; }

View File

@ -3,17 +3,24 @@ using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SecuritySystemDatabaseImplement.Models namespace SecuritySystemDatabaseImplement.Models
{ {
[DataContract]
public class Secure : ISecureModel public class Secure : ISecureModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string SecureName { get; set; } = string.Empty; public string SecureName { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Price { get; set; } public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _SecureComponents = null; private Dictionary<int, (IComponentModel, int)>? _SecureComponents = null;
[NotMapped] [NotMapped]
[DataMember]
public Dictionary<int, (IComponentModel, int)> SecureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get get

View File

@ -1,6 +1,5 @@
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SecuritySystemDatabaseImplement.Models;
namespace SecuritySystemDatabaseImplement namespace SecuritySystemDatabaseImplement
{ {
@ -10,7 +9,7 @@ namespace SecuritySystemDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=SecuritySystemDatabaseFull7;Username=postgres;Password=1953"); optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=SecuritySystemDatabaseFull8;Username=postgres;Password=1953");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -7,17 +7,16 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" /> <ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" /> <ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.DI;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemFileImplement.Implements;
namespace SecuritySystemFileImplement
{
public class FileImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemFileImplement;
namespace SecuritySystemFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties().FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetProperty("Item").PropertyType == typeof(T)).GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}

View File

@ -1,6 +1,6 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement.Models; using SecuritySystemFileImplement.Models;
using System; using System;

View File

@ -3,10 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement.Models; using SecuritySystemFileImplement.Models;
using SecuritySystemFileImplement; using SecuritySystemFileImplement;

View File

@ -3,10 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement.Models; using SecuritySystemFileImplement.Models;
using SecuritySystemFileImplement; using SecuritySystemFileImplement;

View File

@ -1,24 +1,15 @@
using System; using SecuritySystemContracts.BindingModels;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement.Models; using SecuritySystemFileImplement.Models;
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();
} }

View File

@ -1,22 +1,24 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System; using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
public int Id { get; private set; } [DataMember]
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty; public string Email { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model) [DataMember]
public int Id { get; private set; }
public static Client? Create(ClientBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -27,9 +29,10 @@ namespace SecuritySystemFileImplement.Models
Id = model.Id, Id = model.Id,
ClientFIO = model.ClientFIO, ClientFIO = model.ClientFIO,
Email = model.Email, Email = model.Email,
Password = model.Password, Password = model.Password
}; };
} }
public static Client? Create(XElement element) public static Client? Create(XElement element)
{ {
if (element == null) if (element == null)
@ -44,7 +47,8 @@ namespace SecuritySystemFileImplement.Models
Password = element.Element("Password")!.Value Password = element.Element("Password")!.Value
}; };
} }
public void Update(ClientBindingModel? model)
public void Update(ClientBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -54,6 +58,7 @@ namespace SecuritySystemFileImplement.Models
Email = model.Email; Email = model.Email;
Password = model.Password; Password = model.Password;
} }
public ClientViewModel GetViewModel => new() public ClientViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
@ -61,6 +66,7 @@ namespace SecuritySystemFileImplement.Models
Email = Email, Email = Email,
Password = Password Password = Password
}; };
public XElement GetXElement => new("Client", public XElement GetXElement => new("Client",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("ClientFIO", ClientFIO), new XElement("ClientFIO", ClientFIO),

View File

@ -1,20 +1,19 @@
using System; using SecuritySystemContracts.BindingModels;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq; using System.Xml.Linq;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
[DataContract]
public class Component : IComponentModel public class Component : IComponentModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; } public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {
@ -61,5 +60,6 @@ namespace SecuritySystemFileImplement.Models
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName), new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString())); new XElement("Cost", Cost.ToString()));
} }
} }

View File

@ -1,76 +1,80 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System; using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
public class Implementer : IImplementerModel [DataContract]
{ public class Implementer : IImplementerModel
public int Id { get; private set; } {
public string ImplementerFIO { get; private set; } = string.Empty; [DataMember]
public string Password { get; private set; } = string.Empty; public int Id { get; private set; }
public int WorkExperience { get; private set; } [DataMember]
public int Qualification { get; private set; } public string ImplementerFIO { get; private set; } = string.Empty;
public static Implementer? Create(ImplementerBindingModel? model) [DataMember]
{ public string Password { get; private set; } = string.Empty;
if (model == null) [DataMember]
{ public int WorkExperience { get; private set; }
return null; [DataMember]
} public int Qualification { get; private set; }
return new Implementer()
{ public static Implementer? Create(ImplementerBindingModel model)
Id = model.Id, {
ImplementerFIO = model.ImplementerFIO, if (model == null)
Password = model.Password, {
WorkExperience = model.WorkExperience, return null;
Qualification = model.Qualification, }
}; return new Implementer()
} {
public static Implementer? Create(XElement element) Id = model.Id,
{ ImplementerFIO = model.ImplementerFIO,
if (element == null) Password = model.Password,
{ WorkExperience = model.WorkExperience,
return null; Qualification = model.Qualification,
} };
return new Implementer() }
{ public static Implementer? Create(XElement element)
Id = Convert.ToInt32(element.Attribute("Id")!.Value), {
ImplementerFIO = element.Element("ImplementerFIO")!.Value, if (element == null)
Password = element.Element("Password")!.Value, {
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), return null;
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) }
}; return new Implementer()
} {
public void Update(ImplementerBindingModel? model) Id = Convert.ToInt32(element.Attribute("Id")!.Value),
{ ImplementerFIO = element.Element("ImplementerFIO")!.Value,
if (model == null) Password = element.Element("Password")!.Value,
{ WorkExperience = Convert.ToInt32(element.Attribute("WorkExperience")!.Value),
return; Qualification = Convert.ToInt32(element.Attribute("Qualification")!.Value),
} };
ImplementerFIO = model.ImplementerFIO; }
Password = model.Password; public void Update(ImplementerBindingModel model)
WorkExperience = model.WorkExperience; {
Qualification = model.Qualification; if (model == null)
} {
public ImplementerViewModel GetViewModel => new() return;
{ }
Id = Id, ImplementerFIO = model.ImplementerFIO;
ImplementerFIO = ImplementerFIO, Password = model.Password;
Password = Password, WorkExperience = model.WorkExperience;
WorkExperience = WorkExperience, Qualification = model.Qualification;
Qualification = Qualification }
}; public ImplementerViewModel GetViewModel => new()
public XElement GetXElement => new("Implementer", {
new XAttribute("Id", Id), Id = Id,
new XElement("ImplementerFIO", ImplementerFIO), ImplementerFIO = ImplementerFIO,
new XElement("Password", Password), Password = Password,
new XElement("WorkExperience", WorkExperience), WorkExperience = WorkExperience,
new XElement("Qualification", Qualification)); Qualification = Qualification
} };
public XElement GetXElement => new("Implementer",
new XAttribute("Id", Id),
new XElement("ImplementerFIO", ImplementerFIO),
new XElement("Password", Password),
new XElement("WorkExperience", WorkExperience),
new XElement("Qualification", Qualification));
}
} }

View File

@ -1,78 +1,78 @@
using System; using SecuritySystemContracts.BindingModels;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
public class MessageInfo : IMessageInfoModel [DataContract]
{ public class MessageInfo : IMessageInfoModel
public string MessageId { get; set; } = string.Empty; {
[DataMember]
public string MessageId { get; set; } = string.Empty;
[DataMember]
public int? ClientId { get; set; }
[DataMember]
public string SenderName { get; set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; set; } = DateTime.Now;
[DataMember]
public string Subject { get; set; } = string.Empty;
[DataMember]
public string Body { get; set; } = string.Empty;
public int? ClientId { get; set; } public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new MessageInfo()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
};
}
public static MessageInfo? Create(XElement element)
{
if (element == null)
{
return null;
}
return new MessageInfo()
{
MessageId = element.Element("MessageId")!.Value,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
SenderName = element.Element("MessageId")!.Value,
DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null),
Subject = element.Element("MessageId")!.Value,
Body = element.Element("MessageId")!.Value
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
public string SenderName { get; set; } = string.Empty; public XElement GetXElement =>
new("MessageInfo",
new XAttribute("MessageId", MessageId),
new XElement("ClientId", ClientId),
new XElement("SenderName", SenderName),
new XElement("DateDelivery", DateDelivery),
new XElement("Subject", Subject),
new XElement("Body", Body));
public DateTime DateDelivery { get; set; } = DateTime.Now; public int Id => throw new NotImplementedException();
}
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new MessageInfo()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
};
}
public static MessageInfo? Create(XElement element)
{
if (element == null)
{
return null;
}
return new MessageInfo()
{
MessageId = element.Element("MessageId")!.Value,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
SenderName = element.Element("MessageId")!.Value,
DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null),
Subject = element.Element("MessageId")!.Value,
Body = element.Element("MessageId")!.Value
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
public XElement GetXElement =>
new("MessageInfo",
new XAttribute("MessageId", MessageId),
new XElement("ClientId", ClientId),
new XElement("SenderName", SenderName),
new XElement("DateDelivery", DateDelivery),
new XElement("Subject", Subject),
new XElement("Body", Body));
}
} }

View File

@ -1,40 +1,45 @@
using System; using SecuritySystemContracts.BindingModels;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Enums; using SecuritySystemDataModels.Enums;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; } [DataMember]
public int SecureId { get; private set; } public int SecureId { get; private set; }
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public string SecureName { get; private set; } = string.Empty; [DataMember]
public int? ImplementerId { get; private set; }
[DataMember]
public int Count { get; private set; } public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now; public OrderStatus Status { get; private set; }
[DataMember]
public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
[DataMember]
public int Id { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
return null; return null;
} }
return new Order return new Order()
{ {
Id = model.Id, Id = model.Id,
SecureId = model.SecureId, SecureId = model.SecureId,
SecureName = model.SecureName, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -49,51 +54,65 @@ namespace SecuritySystemFileImplement.Models
{ {
return null; return null;
} }
return new Order() var order = new Order()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
SecureId = Convert.ToInt32(element.Element("SecureId")!.Value), SecureId = Convert.ToInt32(element.Element("SecureId")!.Value),
SecureName = element.Element("SecureName")!.Value, ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value)
}; };
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
order.DateImplement = dateImpl;
if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status))
{
return null;
}
order.Status = status;
return order;
} }
public void Update(OrderBindingModel? model) public void Update(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
return; return;
} }
SecureId = model.SecureId;
ClientId = model.ClientId;
ImplementerId = model.ImplementerId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
SecureId = SecureId, SecureId = SecureId,
SecureName = SecureName, ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement DateImplement = DateImplement
}; };
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("SecureId", SecureId.ToString()),
new XElement("ClientId", ClientId.ToString()),
new XElement("ImplementerId", ClientId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
public XElement GetXElement => new(
"Order",
new XAttribute("Id", Id),
new XElement("SecureId", SecureId.ToString()),
new XElement("SecureName", SecureName.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString())
);
} }
} }

View File

@ -1,24 +1,23 @@
using System; using SecuritySystemDataModels.Models;
using System.Collections.Generic; using System.Runtime.Serialization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using SecuritySystemDataModels.Models;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemFileImplement;
namespace SecuritySystemFileImplement.Models namespace SecuritySystemFileImplement.Models
{ {
[DataContract]
public class Secure : ISecureModel public class Secure : ISecureModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string SecureName { get; private set; } = string.Empty; public string SecureName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _SecureComponents = null; private Dictionary<int, (IComponentModel, int)>? _SecureComponents = null;
[DataMember]
public Dictionary<int, (IComponentModel, int)> SecureComponents public Dictionary<int, (IComponentModel, int)> SecureComponents
{ {
get get
@ -26,8 +25,9 @@ namespace SecuritySystemFileImplement.Models
if (_SecureComponents == null) if (_SecureComponents == null)
{ {
var source = DataFileSingleton.GetInstance(); var source = DataFileSingleton.GetInstance();
_SecureComponents = Components.ToDictionary(x => x.Key, y => _SecureComponents = Components.ToDictionary(x => x.Key,
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
y.Value));
} }
return _SecureComponents; return _SecureComponents;
} }
@ -43,7 +43,8 @@ namespace SecuritySystemFileImplement.Models
Id = model.Id, Id = model.Id,
SecureName = model.SecureName, SecureName = model.SecureName,
Price = model.Price, Price = model.Price,
Components = model.SecureComponents.ToDictionary(x => x.Key, x => x.Value.Item2) Components = model.SecureComponents.ToDictionary(x => x.Key, x
=> x.Value.Item2)
}; };
} }
public static Secure? Create(XElement element) public static Secure? Create(XElement element)
@ -57,11 +58,9 @@ namespace SecuritySystemFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
SecureName = element.Element("SecureName")!.Value, SecureName = element.Element("SecureName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value), Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = Components = element.Element("SecureComponents")!.Elements("SecureComponent")
element.Element("SecureComponents")!.Elements("SecureComponent") .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
.ToDictionary(x => x => Convert.ToInt32(x.Element("Value")?.Value))
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
}; };
} }
public void Update(SecureBindingModel model) public void Update(SecureBindingModel model)
@ -89,7 +88,6 @@ namespace SecuritySystemFileImplement.Models
new XElement("SecureComponents", Components.Select(x => new XElement("SecureComponents", Components.Select(x =>
new XElement("SecureComponent", new XElement("SecureComponent",
new XElement("Key", x.Key), new XElement("Key", x.Key),
new XElement("Value", x.Value))) new XElement("Value", x.Value))).ToArray()));
.ToArray()));
} }
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.StorageContracts;
namespace SecuritySystemListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}

View File

@ -62,5 +62,6 @@ namespace SecuritySystemListImplement.Implements
_source.MessageInfos.Add(newMessage); _source.MessageInfos.Add(newMessage);
return newMessage.GetViewModel; return newMessage.GetViewModel;
} }
} public int Id => throw new NotImplementedException();
}
} }

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SecuritySystemContracts.DI;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemListImplement.Implements;
namespace SecuritySystemListImplement
{
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISecureStorage,SecureStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -3,9 +3,6 @@ using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
namespace SecuritySystemRestApi.Controllers namespace SecuritySystemRestApi.Controllers
{ {

View File

@ -1,17 +1,10 @@
using SecuritySystemBusinessLogic.BusinessLogics; using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.StorageContracts;
using SecuritySystemDatabaseImplement.Implements; using SecuritySystemDatabaseImplement.Implements;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemBusinessLogic.MailWorker; using SecuritySystemBusinessLogic.MailWorker;
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StorageContracts;
using SecuritySystemDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);

View File

@ -8,7 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>