PIbd-23. Leonteva V.A. Lab work 08 #9

Closed
leonteva.v wants to merge 1 commits from Lab_8 into Lab_7
59 changed files with 1092 additions and 386 deletions
Showing only changes of commit b2dd3c2e3e - Show all commits

1
.gitignore vendored
View File

@ -14,6 +14,7 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
*.dll
# Mono auto generated files
mono_crash.*

View File

@ -0,0 +1,55 @@
using LawFirmContracts.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmView
{
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,6 +1,7 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -22,15 +23,9 @@ namespace LawFirmView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["BlankName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка бланков");
}
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка бланков");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки бланков");
@ -40,29 +35,23 @@ namespace LawFirmView
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBlank));
if (service is FormBlank form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormBlank>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBlank));
if (service is FormBlank form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormBlank>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{

View File

@ -3,6 +3,7 @@ using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.SearchModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -72,45 +73,41 @@ namespace LawFirmView
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormDocumentBlank));
if (service is FormDocumentBlank form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
{
return;
}
_logger.LogInformation("Добавление нового бланка:{BlankName} - { Count}",
form.BlankModel.BlankName, form.Count);
if (_documentBlanks.ContainsKey(form.Id))
{
_documentBlanks[form.Id] = (form.BlankModel,
form.Count);
}
else
{
_documentBlanks.Add(form.Id, (form.BlankModel,
form.Count));
}
LoadData();
}
}
}
var form = DependencyManager.Instance.Resolve<FormDocumentBlank>();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
{
return;
}
_logger.LogInformation("Добавление нового бланка:{BlankName} - { Count}",
form.BlankModel.BlankName, form.Count);
if (_documentBlanks.ContainsKey(form.Id))
{
_documentBlanks[form.Id] = (form.BlankModel,
form.Count);
}
else
{
_documentBlanks.Add(form.Id, (form.BlankModel,
form.Count));
}
LoadData();
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocumentBlank));
if (service is FormDocumentBlank form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _documentBlanks[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
var form = DependencyManager.Instance.Resolve<FormDocumentBlank>();
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _documentBlanks[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
{
if (form.BlankModel == null)
{
return;
}

View File

@ -1,6 +1,7 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -22,16 +23,9 @@ namespace LawFirmView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["DocumentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["DocumentBlanks"].Visible = false;
}
_logger.LogInformation("Загрузка документов");
}
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка документов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки документов");
@ -41,28 +35,19 @@ namespace LawFirmView
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocument));
if (service is FormDocument form)
var form = DependencyManager.Instance.Resolve<FormDocument>();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
var form = DependencyManager.Instance.Resolve<FormDocument>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocument));
if (service is FormDocument form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
LoadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)

View File

@ -22,20 +22,12 @@ namespace LawFirmView
_logger = logger;
_logic = logic;
}
private void FormMails_Load(object sender, EventArgs e)
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка писем");
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка списка писем");
}
catch (Exception ex)
{

View File

@ -34,6 +34,7 @@
DocumentsToolStripMenuItem = new ToolStripMenuItem();
ClientsToolStripMenuItem = new ToolStripMenuItem();
ImplementersToolStripMenuItem = new ToolStripMenuItem();
MailToolStripMenuItem = new ToolStripMenuItem();
ReportsToolStripMenuItem = new ToolStripMenuItem();
ListOfDocumentsToolStripMenuItem = new ToolStripMenuItem();
FormsForDocumentsToolStripMenuItem = new ToolStripMenuItem();
@ -43,7 +44,7 @@
buttonCreateOrder = new Button();
buttonIssuedOrder = new Button();
buttonUpdate = new Button();
MailToolStripMenuItem = new ToolStripMenuItem();
createBackupToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -51,7 +52,7 @@
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, ReportsToolStripMenuItem, StartWorksToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, ReportsToolStripMenuItem, StartWorksToolStripMenuItem, createBackupToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(929, 28);
@ -68,31 +69,38 @@
// BlanksToolStripMenuItem
//
BlanksToolStripMenuItem.Name = "BlanksToolStripMenuItem";
BlanksToolStripMenuItem.Size = new Size(224, 26);
BlanksToolStripMenuItem.Size = new Size(185, 26);
BlanksToolStripMenuItem.Text = "Бланки";
BlanksToolStripMenuItem.Click += BlanksToolStripMenuItem_Click;
//
// DocumentsToolStripMenuItem
//
DocumentsToolStripMenuItem.Name = "DocumentsToolStripMenuItem";
DocumentsToolStripMenuItem.Size = new Size(224, 26);
DocumentsToolStripMenuItem.Size = new Size(185, 26);
DocumentsToolStripMenuItem.Text = "Документы";
DocumentsToolStripMenuItem.Click += DocumentsToolStripMenuItem_Click;
//
// ClientsToolStripMenuItem
//
ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem";
ClientsToolStripMenuItem.Size = new Size(224, 26);
ClientsToolStripMenuItem.Size = new Size(185, 26);
ClientsToolStripMenuItem.Text = "Клиенты";
ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
//
// ImplementersToolStripMenuItem
//
ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem";
ImplementersToolStripMenuItem.Size = new Size(224, 26);
ImplementersToolStripMenuItem.Size = new Size(185, 26);
ImplementersToolStripMenuItem.Text = "Исполнители";
ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click;
//
// MailToolStripMenuItem
//
MailToolStripMenuItem.Name = "MailToolStripMenuItem";
MailToolStripMenuItem.Size = new Size(185, 26);
MailToolStripMenuItem.Text = "Письма";
MailToolStripMenuItem.Click += MailToolStripMenuItem_Click;
//
// ReportsToolStripMenuItem
//
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ListOfDocumentsToolStripMenuItem, FormsForDocumentsToolStripMenuItem, OrderListToolStripMenuItem });
@ -173,12 +181,12 @@
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// MailToolStripMenuItem
// createBackupToolStripMenuItem
//
MailToolStripMenuItem.Name = "MailToolStripMenuItem";
MailToolStripMenuItem.Size = new Size(224, 26);
MailToolStripMenuItem.Text = "Письма";
MailToolStripMenuItem.Click += MailToolStripMenuItem_Click;
createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem";
createBackupToolStripMenuItem.Size = new Size(122, 24);
createBackupToolStripMenuItem.Text = "Создать бэкап";
createBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click;
//
// FormMain
//
@ -219,5 +227,6 @@
private ToolStripMenuItem StartWorksToolStripMenuItem;
private ToolStripMenuItem ImplementersToolStripMenuItem;
private ToolStripMenuItem MailToolStripMenuItem;
private ToolStripMenuItem createBackupToolStripMenuItem;
}
}

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using LawFirmBusinessLogic.BusinessLogics;
using System.Windows.Forms;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -14,13 +15,15 @@ namespace LawFirmView
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
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();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
_backUpLogic = backUpLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
@ -31,14 +34,7 @@ namespace LawFirmView
_logger.LogInformation("Загрузка заказов");
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["DocumentId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
}
dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Загрузка прошла успешно");
}
catch (Exception ex)
@ -49,12 +45,9 @@ namespace LawFirmView
}
private void buttonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
form.ShowDialog();
LoadData();
}
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
{
@ -66,12 +59,7 @@ namespace LawFirmView
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id,
DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
Id = id
});
if (!operationResult)
{
@ -97,12 +85,7 @@ namespace LawFirmView
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
Id = id
});
if (!operationResult)
{
@ -129,12 +112,7 @@ namespace LawFirmView
var operationResult = _orderLogic.DeliveryOrder(new
OrderBindingModel
{
Id = id,
DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
Id = id
});
if (!operationResult)
{
@ -157,19 +135,13 @@ namespace LawFirmView
}
private void BlanksToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBlanks));
if (service is FormBlanks form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormBlanks>();
form.ShowDialog();
}
private void DocumentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocuments));
if (service is FormDocuments form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormDocuments>();
form.ShowDialog();
}
private void ListOfDocumentsToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -185,48 +157,59 @@ namespace LawFirmView
}
private void FormsForDocumentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks));
if (service is FormReportDocumentBlanks form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormReportDocumentBlanks>();
form.ShowDialog();
}
private void OrderListToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrder));
if (service is FormReportOrder form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormReportOrder>();
form.ShowDialog();
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormViewClients));
if (service is FormViewClients form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormViewClients>();
form.ShowDialog();
}
private void StartWorksToolStripMenuItem_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);
}
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers));
if (service is FormViewImplementers form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormViewImplementers>();
form.ShowDialog();
}
private void MailToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
if (service is FormMails form)
var form = DependencyManager.Instance.Resolve<FormMails>();
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

@ -1,6 +1,7 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -22,15 +23,9 @@ namespace LawFirmView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов");
}
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки клиентов");

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -31,14 +32,9 @@ namespace LawFirmView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
}
_logger.LogInformation("Загрузка исполнителей");
}
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки исполнителей");
@ -48,28 +44,22 @@ namespace LawFirmView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
var form = DependencyManager.Instance.Resolve<FormImplementer>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)

View File

@ -8,6 +8,14 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
@ -30,13 +38,4 @@
<ProjectReference Include="..\LawFirmListImplement\LawFirmListImplement.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using LawFirmBusinessLogic.MailWorker;
using LawFirmContracts.BindingModels;
using LawFirmContracts.DI;
namespace LawFirmView
{
@ -27,11 +28,10 @@ namespace LawFirmView
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
InitDependency();
try
{
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin =
@ -56,54 +56,61 @@ namespace LawFirmView
}
catch (Exception ex)
{
var logger = _serviceProvider.GetService<ILogger>();
var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IBlankStorage, BlankStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDocumentStorage, DocumentStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IBlankLogic, BlankLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDocumentLogic, DocumentLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<FormMain>();
services.AddTransient<FormBlank>();
services.AddTransient<FormBlanks>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormDocument>();
services.AddTransient<FormDocumentBlank>();
services.AddTransient<FormDocuments>();
services.AddTransient<FormReportDocumentBlanks>();
services.AddTransient<FormReportOrder>();
services.AddTransient<FormViewClients>();
services.AddTransient<FormViewImplementers>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormMails>();
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
}
private static void MailCheck(object obj) => ServiceProvider?
.GetService<AbstractMailWorker>()?.MailCheck();
private static void InitDependency()
{
DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
DependencyManager.Instance.RegisterType<IBlankLogic,
BlankLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic,
OrderLogic>();
DependencyManager.Instance.RegisterType<IDocumentLogic,
DocumentLogic>();
DependencyManager.Instance.RegisterType<IReportLogic,
ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic,
ClientLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic,
ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic,
MessageInfoLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel,
SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord,
SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf,
SaveToPdf>();
DependencyManager.Instance.RegisterType<IWorkProcess,
WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker,
MailKitWorker>(true);
DependencyManager.Instance.RegisterType<IBackUpLogic,
BackUpLogic>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormBlank>();
DependencyManager.Instance.RegisterType<FormBlanks>();
DependencyManager.Instance.RegisterType<FormDocuments>();
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormDocument>();
DependencyManager.Instance.RegisterType<FormDocumentBlank>();
DependencyManager.Instance.RegisterType<FormDocuments>();
DependencyManager.Instance.RegisterType<FormReportDocumentBlanks>();
DependencyManager.Instance.RegisterType<FormReportOrder>();
DependencyManager.Instance.RegisterType<FormViewClients>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormViewImplementers>();
DependencyManager.Instance.RegisterType<FormMails>();
}
private static void MailCheck(object obj) =>
DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
}
}

View File

@ -0,0 +1,99 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicsContracts;
using LawFirmContracts.StoragesContracts;
using LawFirmDataModels;
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;
namespace LawFirmBusinessLogic.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

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.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 LawFirmContracts.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,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class BackUpSaveBinidngModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

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

View File

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

View File

@ -0,0 +1,47 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.DI
{
public class DependencyManager
{
private readonly IDependencyContainer _dependencyManager;
private static DependencyManager? _manager;
private static readonly object _locjObject = new();
private DependencyManager()
{
_dependencyManager = new ServiceDependencyContainer();
}
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,18 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.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 LawFirmContracts.DI
{
public interface IImplementationExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -0,0 +1,56 @@
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 LawFirmContracts.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,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.DI
{
public 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,38 @@
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 LawFirmContracts.DI
{
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}
}

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>

View File

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

View File

@ -1,14 +1,16 @@
using LawFirmDataModels.Models;
using LawFirmContracts.Attributes;
using LawFirmDataModels.Models;
using System.ComponentModel;
namespace LawFirmContracts.ViewModels
{
public class BlankViewModel : IBlankModel
{
public int Id { get; set; }
[DisplayName("Название бланка")]
public string BlankName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
}
[Column(visible: false)]
public int Id { get; set; }
[Column("Название бланка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string BlankName { get; set; } = string.Empty;
[Column("Цена", width: 80)]
public double Price { get; set; }
}
}

View File

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

View File

@ -1,17 +1,20 @@
using LawFirmDataModels.Models;
using System.ComponentModel;
using LawFirmContracts.Attributes;
namespace LawFirmContracts.ViewModels
{
public class DocumentViewModel : IDocumentModel
{
public int Id { get; set; }
[DisplayName("Название документа")]
public string DocumentName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
[Column(visible: false)]
public int Id { get; set; }
[Column("Название документа", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string DocumentName { get; set; } = string.Empty;
[Column("Цена", width: 100)]
public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get;
set;
} = new();

View File

@ -5,23 +5,21 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LawFirmContracts.Attributes;
namespace LawFirmContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
public int Id { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
[DisplayName("Стаж работы")]
public int WorkExperience { get; set; }
[DisplayName("Квалификация")]
public int Qualification { get; set; }
[Column(visible: false)]
public int Id { get; set; }
[Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
[Column("Пароль", width: 150)]
public string Password { get; set; } = string.Empty;
[Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int WorkExperience { get; set; }
[Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Qualification { get; set; }
}
}

View File

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

View File

@ -1,4 +1,5 @@
using LawFirmDataModels.Enums;
using LawFirmContracts.Attributes;
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System.ComponentModel;
@ -6,27 +7,29 @@ namespace LawFirmContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
public int DocumentId { get; set; }
public int? ImplementerId { get; set; }
[DisplayName("Документ")]
[Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Id { get; set; }
[Column(visible: false)]
public int DocumentId { get; set; }
[Column(visible: false)]
public int? ImplementerId { get; set; }
[Column(visible: false)]
public int ClientId { get; set; }
[DisplayName("Данные клиента")]
[Column("Данные клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Фамилия исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Документ")]
[Column("Данные исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
[Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string DocumentName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
[Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Count { get; set; }
[Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public double Sum { get; set; }
[Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Column("Дата создания", width: 100)]
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
[Column("Дата выполнения", width: 100)]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -3,10 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LawFirmDataModels;
namespace LawFirmDataModel.Models
{
public interface IMessageInfoModel
public interface IMessageInfoModel : IId
{
string MessageId { get; }
int? ClientId { get; }

View File

@ -0,0 +1,26 @@
using LawFirmContracts.DI;
using LawFirmContracts.StoragesContracts;
using LawFirmDatabaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement
{
public class DatabaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IBlankStorage, BlankStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IDocumentStorage, DocumentStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,32 @@
using LawFirmContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new LawFirmDatabase();
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

@ -9,7 +9,7 @@ namespace LawFirmDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS; Initial Catalog=LawFirm7;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS; Initial Catalog=LawFirmdbbd8;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -7,13 +7,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>
<ItemGroup>
@ -21,4 +21,8 @@
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -12,15 +12,15 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20240619095940_r")]
partial class r
[Migration("20240619192208_lab8")]
partial class lab8
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class r : Migration
public partial class lab8 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)

View File

@ -17,7 +17,7 @@ namespace LawFirmDatabaseImplement.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

View File

@ -3,16 +3,21 @@ using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace LawFirmDatabaseImplement.Models
{
public class Blank : IBlankModel
[DataContract]
public class Blank : IBlankModel
{
public int Id { get; private set; }
[DataMember]
public int Id { get; private set; }
[Required]
public string BlankName { get; private set; } = string.Empty;
[DataMember]
public string BlankName { get; private set; } = string.Empty;
[Required]
public double Price { get; set; }
[DataMember]
public double Price { get; set; }
[ForeignKey("BlankId")]
public virtual List<DocumentBlank> DocumentBlanks { get; set; } = new();
public static Blank? Create(BlankBindingModel model)

View File

@ -8,20 +8,23 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace LawFirmDatabaseImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string ClientFIO { get; set; } = string.Empty;
[Required]
[DataMember]
public string Email { get; set; } = string.Empty;
[Required]
[DataMember]
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();

View File

@ -3,19 +3,25 @@ using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace LawFirmDatabaseImplement.Models
{
public class Document : IDocumentModel
[DataContract]
public class Document : IDocumentModel
{
public int Id { get; set; }
[DataMember]
public int Id { get; set; }
[Required]
public string DocumentName { get; set; } = string.Empty;
[DataMember]
public string DocumentName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[DataMember]
public double Price { get; set; }
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
[NotMapped]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
[DataMember]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{

View File

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

View File

@ -7,12 +7,15 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace LawFirmDatabaseImplement.Models
{
[DataContract]
public class Message : IMessageInfoModel
{
[Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
@ -45,5 +48,6 @@ namespace LawFirmDatabaseImplement.Models
SenderName = SenderName,
DateDelivery = DateDelivery,
};
public int Id => throw new NotImplementedException();
}
}

View File

@ -4,25 +4,35 @@ using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace LawFirmDatabaseImplement.Models
{
public class Order : IOrderModel
[DataContract]
public class Order : IOrderModel
{
[Required]
public int DocumentId { get; set; }
[DataMember]
public int DocumentId { get; set; }
[Required]
[DataMember]
public int ClientId { get; private set; }
[Required]
public int Count { get; set; }
[DataMember]
public int Count { get; set; }
[Required]
public double Sum { get; set; }
[DataMember]
public double Sum { get; set; }
[Required]
public OrderStatus Status { get; set; }
[DataMember]
public OrderStatus Status { get; set; }
[Required]
public DateTime DateCreate { get; set; }
public int? ImplementerId { get; private set; }
public DateTime? DateImplement { get; set; }
[DataMember]
public DateTime DateCreate { get; set; }
[DataMember]
public int? ImplementerId { get; private set; }
[DataMember]
public DateTime? DateImplement { get; set; }
public virtual Document Document { get; set; }
public virtual Client Client { get; set; }
public virtual Implementer? Implementer { get; private set; }

View File

@ -0,0 +1,26 @@
using LawFirmContracts.DI;
using LawFirmContracts.StoragesContracts;
using LawFirmFileImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement
{
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IBlankStorage, BlankStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IDocumentStorage, DocumentStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,34 @@
using LawFirmContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
// Получаем значения из singleton-объекта универсального свойства содержащее тип T
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties()
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == 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,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -11,4 +11,8 @@
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -2,14 +2,19 @@
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
public class Blank : IBlankModel
[DataContract]
public class Blank : IBlankModel
{
public int Id { get; private set; }
public string BlankName { get; private set; } = string.Empty;
public double Price { get; set; }
[DataMember]
public int Id { get; private set; }
[DataMember]
public string BlankName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; set; }
public static Blank? Create(BlankBindingModel model)
{
if (model == null)

View File

@ -7,14 +7,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
[DataMember]
public int Id { get; private set; }
public static Client? Create(ClientBindingModel model)
{

View File

@ -2,17 +2,23 @@
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
public class Document : IDocumentModel
[DataContract]
public class Document : IDocumentModel
{
public int Id { get; private set; }
public string DocumentName { get; private set; } = string.Empty;
public double Price { get; private set; }
[DataMember]
public int Id { get; private set; }
[DataMember]
public string DocumentName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
public Dictionary<int, int> Blanks { get; private set; } = new();
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
[DataMember]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{

View File

@ -7,16 +7,23 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
public class Implementer : IImplementerModel
[DataContract]
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(XElement element)
{
if (element == null)

View File

@ -7,16 +7,24 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
[DataContract]
public class Message : IMessageInfoModel
{
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
[DataMember]
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
public static Message? Create(MessageInfoBindingModel model)
{
@ -67,5 +75,6 @@ namespace LawFirmFileImplement.Models
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery)
);
public int Id => throw new NotImplementedException();
}
}

View File

@ -3,19 +3,30 @@ using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
public class Order : IOrderModel
[DataContract]
public class Order : IOrderModel
{
public int Id { get; private set; }
public int DocumentId { get; private set; }
[DataMember]
public int Id { get; private set; }
[DataMember]
public int DocumentId { get; private set; }
[DataMember]
public int ClientId { get; set; }
public int? ImplementerId { get; set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[DataMember]
public int? ImplementerId { get; set; }
[DataMember]
public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; }
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
[DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{

View File

@ -0,0 +1,21 @@
using LawFirmContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement.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

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -11,4 +11,8 @@
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -0,0 +1,32 @@
using LawFirmContracts.DI;
using LawFirmContracts.StoragesContracts;
using LawFirmListImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmListImplement
{
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage,
ClientStorage>();
DependencyManager.Instance.RegisterType<IBlankStorage,
BlankStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage,
ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage,
MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage,
OrderStorage>();
DependencyManager.Instance.RegisterType<IDocumentStorage,
DocumentStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -42,5 +42,6 @@ namespace LawFirmListImplement.Models
SenderName = SenderName,
DateDelivery = DateDelivery,
};
public int Id => throw new NotImplementedException();
}
}