готово

This commit is contained in:
ityurner02@mail.ru 2023-05-08 13:49:23 +04:00
parent 40f0df46c4
commit 6ced4523bc
12 changed files with 213 additions and 248 deletions

View File

@ -22,14 +22,8 @@ namespace PlumbingRepair
{ {
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["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
using System.Windows.Forms;
namespace PlumbingRepair namespace PlumbingRepair
{ {
@ -23,18 +25,10 @@ namespace PlumbingRepair
private void LoadData() private void LoadData()
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка компонентов");
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
@ -46,31 +40,24 @@ namespace PlumbingRepair
private void AddButton_Click(object sender, EventArgs e) private void AddButton_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 ChangeButton_Click(object sender, EventArgs e) private void ChangeButton_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>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (service is FormComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }
private void DeleteButton_Click(object sender, EventArgs e) private void DeleteButton_Click(object sender, EventArgs e)

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -26,14 +27,10 @@ namespace PlumbingRepair
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var form = DependencyManager.Instance.Resolve<FormImplementer>();
if (form.ShowDialog() == DialogResult.OK)
if (service is FormImplementer form)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
@ -41,14 +38,11 @@ namespace PlumbingRepair
{ {
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); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }
@ -98,14 +92,7 @@ namespace PlumbingRepair
{ {
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["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей"); _logger.LogInformation("Загрузка исполнителей");
} }

View File

@ -20,14 +20,7 @@ namespace PlumbingRepair
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_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("Загрузка писем"); _logger.LogInformation("Загрузка писем");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -39,11 +39,12 @@
WorkComponentToolStripMenuItem = new ToolStripMenuItem(); WorkComponentToolStripMenuItem = new ToolStripMenuItem();
OrdersToolStripMenuItem = new ToolStripMenuItem(); OrdersToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem();
письмаToolStripMenuItem = new ToolStripMenuItem();
создатьБэкапToolStripMenuItem = new ToolStripMenuItem();
CreateOrderButton = new Button(); CreateOrderButton = new Button();
IssuedOrderButton = new Button(); IssuedOrderButton = new Button();
UpdateListButton = new Button(); UpdateListButton = new Button();
DataGridView = new DataGridView(); DataGridView = new DataGridView();
письмаToolStripMenuItem = new ToolStripMenuItem();
MenuStrip.SuspendLayout(); MenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -51,7 +52,7 @@
// MenuStrip // MenuStrip
// //
MenuStrip.ImageScalingSize = new Size(20, 20); MenuStrip.ImageScalingSize = new Size(20, 20);
MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem }); MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem, создатьБэкапToolStripMenuItem });
MenuStrip.Location = new Point(0, 0); MenuStrip.Location = new Point(0, 0);
MenuStrip.Name = "MenuStrip"; MenuStrip.Name = "MenuStrip";
MenuStrip.Padding = new Padding(7, 3, 0, 3); MenuStrip.Padding = new Padding(7, 3, 0, 3);
@ -129,6 +130,20 @@
запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Text = "Запуск работ";
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
// //
// письмаToolStripMenuItem
//
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
письмаToolStripMenuItem.Size = new Size(77, 24);
письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
//
// создатьБэкапToolStripMenuItem
//
создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem";
создатьБэкапToolStripMenuItem.Size = new Size(122, 24);
создатьБэкапToolStripMenuItem.Text = "Создать бэкап";
создатьБэкапToolStripMenuItem.Click += создатьБэкапToolStripMenuItem_Click;
//
// CreateOrderButton // CreateOrderButton
// //
CreateOrderButton.Location = new Point(832, 37); CreateOrderButton.Location = new Point(832, 37);
@ -173,13 +188,6 @@
DataGridView.Size = new Size(825, 561); DataGridView.Size = new Size(825, 561);
DataGridView.TabIndex = 1; DataGridView.TabIndex = 1;
// //
// письмаToolStripMenuItem
//
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
письмаToolStripMenuItem.Size = new Size(77, 24);
письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
@ -220,5 +228,6 @@
private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem;
private DataGridView DataGridView; private DataGridView DataGridView;
private ToolStripMenuItem письмаToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem;
private ToolStripMenuItem создатьБэкапToolStripMenuItem;
} }
} }

View File

@ -1,9 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairBusinessLogic.BusinessLogic;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairDataModels.Enums; using PlumbingRepairContracts.DI;
using System.Windows.Forms;
namespace PlumbingRepair namespace PlumbingRepair
{ {
@ -14,13 +12,15 @@ namespace PlumbingRepair
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> logger, IBackUpLogic backUpLogic, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic)
{ {
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)
@ -34,16 +34,7 @@ namespace PlumbingRepair
try try
{ {
var list = _orderLogic.ReadList(null); DataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["WorkId"].Visible = false;
DataGridView.Columns["ClientId"].Visible = false;
DataGridView.Columns["ImplementerId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
catch (Exception ex) catch (Exception ex)
@ -55,41 +46,26 @@ namespace PlumbingRepair
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var form = DependencyManager.Instance.Resolve<FormComponents>();
form.ShowDialog();
if (service is FormComponents form)
{
form.ShowDialog();
}
} }
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); var form = DependencyManager.Instance.Resolve<FormWorks>();
form.ShowDialog();
if (service is FormWorks form)
{
form.ShowDialog();
}
} }
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormClients)); var form = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void CreateOrderButton_Click(object sender, EventArgs e) private void CreateOrderButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
form.ShowDialog();
if (service is FormCreateOrder form) LoadData();
{
form.ShowDialog();
LoadData();
}
} }
private void IssuedOrderButton_Click(object sender, EventArgs e) private void IssuedOrderButton_Click(object sender, EventArgs e)
@ -142,44 +118,55 @@ namespace PlumbingRepair
private void WorkComponentToolStripMenuItem_Click(object sender, EventArgs e) private void WorkComponentToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents)); var form = DependencyManager.Instance.Resolve<FormReportWorkComponents>();
if (service is FormReportWorkComponents form) form.ShowDialog();
{
form.ShowDialog();
}
} }
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) private void OrdersToolStripMenuItem_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 запускРаботToolStripMenuItem_Click(object sender, EventArgs e) private void запускРаботToolStripMenuItem_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 исполнителиToolStripMenuItem_Click(object sender, EventArgs e) private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
if (service is FormImplementers form)
{
form.ShowDialog();
}
} }
private void письмаToolStripMenuItem_Click(object sender, EventArgs e) private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMails)); var form = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form) form.ShowDialog();
}
private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{ {
form.ShowDialog(); if (_backUpLogic != null)
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel
{
FolderName = fbd.SelectedPath
});
MessageBox.Show("Бекап создан", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }

View File

@ -4,6 +4,7 @@ using PlumbingRepairContracts.SearchModels;
using PlumbingRepairDataModels.Models; using PlumbingRepairDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Windows.Forms; using System.Windows.Forms;
using PlumbingRepairContracts.DI;
namespace PlumbingRepair namespace PlumbingRepair
{ {
@ -77,31 +78,27 @@ namespace PlumbingRepair
} }
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); var form = DependencyManager.Instance.Resolve<FormWorkComponent>();
if (service is FormWorkComponent form)
{
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);
if (_workComponents.ContainsKey(form.Id))
{
_workComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_workComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
} }
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_workComponents.ContainsKey(form.Id))
{
_workComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_workComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
} }
} }
@ -109,25 +106,21 @@ namespace PlumbingRepair
{ {
if (DataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); var form = DependencyManager.Instance.Resolve<FormWorkComponent>();
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _workComponents[id].Item2;
if (service is FormWorkComponent form) if (form.ShowDialog() == DialogResult.OK)
{ {
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); if (form.ComponentModel == null)
form.Id = id;
form.Count = _workComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) return;
{
return;
}
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_workComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
} }
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_workComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
} }
} }
} }

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.DI;
namespace PlumbingRepair namespace PlumbingRepair
{ {
@ -25,17 +26,8 @@ namespace PlumbingRepair
{ {
try try
{ {
var list = _logic.ReadList(null); DataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка изделий");
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["WorkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["WorkComponents"].Visible = false;
}
_logger.LogInformation("Загрузка изделий");
} }
catch (Exception ex) catch (Exception ex)
@ -47,30 +39,21 @@ namespace PlumbingRepair
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWork)); var form = DependencyManager.Instance.Resolve<FormWork>();
if (form.ShowDialog() == DialogResult.OK)
if (service is FormWork form)
{ {
if (form.ShowDialog() == DialogResult.OK) LoadData();
{
LoadData();
}
} }
} }
private void ChangeButton_Click(object sender, EventArgs e) private void ChangeButton_Click(object sender, EventArgs e)
{ {
if (DataGridView.SelectedRows.Count == 1) if (DataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormWork)); var form = DependencyManager.Instance.Resolve<FormWork>();
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (service is FormWork form) if (form.ShowDialog() == DialogResult.OK)
{ {
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
} }
} }
} }

View File

@ -1,7 +1,4 @@
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairDatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using PlumbingRepairBusinessLogic.BusinessLogic; using PlumbingRepairBusinessLogic.BusinessLogic;
@ -9,28 +6,23 @@ using PlumbingRepairBusinessLogic.OfficePackage;
using PlumbingRepairBusinessLogic.OfficePackage.Implements; using PlumbingRepairBusinessLogic.OfficePackage.Implements;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairBusinessLogic.MailWorker; using PlumbingRepairBusinessLogic.MailWorker;
using PlumbingRepairContracts.DI;
namespace PlumbingRepair namespace PlumbingRepair
{ {
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()
{ {
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); InitDependency();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
try try
{ {
var mailSender = _serviceProvider.GetService<AbstractMailWorker>(); var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel mailSender?.MailConfig(new MailConfigBindingModel
{ {
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@ -45,51 +37,51 @@ namespace PlumbingRepair
} }
catch (Exception ex) catch (Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Error"); logger?.LogError(ex, "Error");
} }
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>();
services.AddTransient<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
services.AddTransient<IWorkStorage, WorkStorage>(); DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
services.AddTransient<IClientStorage, ClientStorage>(); DependencyManager.Instance.RegisterType<IWorkLogic, WorkLogic>();
services.AddTransient<IImplementerStorage, ImplementerStorage>(); DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>(); DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
services.AddTransient<IComponentLogic, ComponentLogic>(); DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IWorkLogic, WorkLogic>(); DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
services.AddTransient<IClientLogic, ClientLogic>(); DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>(); DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IWorkProcess, WorkModeling>(); DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>(); DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); DependencyManager.Instance.RegisterType<FormMain>();
services.AddTransient<FormMain>(); DependencyManager.Instance.RegisterType<FormComponent>();
services.AddTransient<FormComponent>(); DependencyManager.Instance.RegisterType<FormComponents>();
services.AddTransient<FormComponents>(); DependencyManager.Instance.RegisterType<FormCreateOrder>();
services.AddTransient<FormCreateOrder>(); DependencyManager.Instance.RegisterType<FormWork>();
services.AddTransient<FormWork>(); DependencyManager.Instance.RegisterType<FormWorkComponent>();
services.AddTransient<FormWorkComponent>(); DependencyManager.Instance.RegisterType<FormWorks>();
services.AddTransient<FormWorks>(); DependencyManager.Instance.RegisterType<FormReportWorkComponents>();
services.AddTransient<FormReportWorkComponents>(); DependencyManager.Instance.RegisterType<FormReportOrders>();
services.AddTransient<FormReportOrders>(); DependencyManager.Instance.RegisterType<FormClients>();
services.AddTransient<FormClients>(); DependencyManager.Instance.RegisterType<FormImplementers>();
services.AddTransient<FormImplementer>(); DependencyManager.Instance.RegisterType<FormImplementer>();
services.AddTransient<FormImplementers>(); DependencyManager.Instance.RegisterType<FormMails>();
services.AddTransient<FormMails>();
} }
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck(); private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
} }
} }

View File

@ -0,0 +1,38 @@
using Microsoft.Extensions.Logging;
using Unity.Microsoft.Logging;
using Unity;
namespace PlumbingRepairContracts.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

@ -8,6 +8,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> <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>
<ItemGroup> <ItemGroup>

View File

@ -15,11 +15,11 @@ namespace PlumbingRepairContracts.ViewModels
public string WorkName { get; set; } = string.Empty; public string WorkName { get; set; } = string.Empty;
[Column(visible: false)] [Column(visible: false)]
public int ClientId { get; set; } public int ClientId { get; set; }
[Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Column(visible: false)] [Column(visible: false)]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Count { get; set; } public int Count { get; set; }
@ -27,9 +27,9 @@ namespace PlumbingRepairContracts.ViewModels
public double Sum { get; set; } public double Sum { get; set; }
[Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Column("Дата создания", width: 100)] [Column("Дата создания", width: 130)]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[Column("Дата выполнения", width: 100)] [Column("Дата выполнения", width: 130)]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
} }
} }