From 6ced4523bc46743f24579b5744438a7426d69b62 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 8 May 2023 13:49:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlumbingRepair/PlumbingRepair/FormClients.cs | 10 +- .../PlumbingRepair/FormComponents.cs | 39 +++---- .../PlumbingRepair/FormImplementers.cs | 31 ++---- PlumbingRepair/PlumbingRepair/FormMails.cs | 9 +- .../PlumbingRepair/FormMain.Designer.cs | 27 +++-- PlumbingRepair/PlumbingRepair/FormMain.cs | 103 ++++++++---------- PlumbingRepair/PlumbingRepair/FormWork.cs | 67 +++++------- PlumbingRepair/PlumbingRepair/FormWorks.cs | 37 ++----- PlumbingRepair/PlumbingRepair/Program.cs | 90 +++++++-------- .../DI/UnityDependencyContainer.cs | 38 +++++++ .../PlumbingRepairContracts.csproj | 2 + .../ViewModels/OrderViewModel.cs | 8 +- 12 files changed, 213 insertions(+), 248 deletions(-) create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs diff --git a/PlumbingRepair/PlumbingRepair/FormClients.cs b/PlumbingRepair/PlumbingRepair/FormClients.cs index e1ce341..b733869 100644 --- a/PlumbingRepair/PlumbingRepair/FormClients.cs +++ b/PlumbingRepair/PlumbingRepair/FormClients.cs @@ -22,14 +22,8 @@ namespace PlumbingRepair { 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) { diff --git a/PlumbingRepair/PlumbingRepair/FormComponents.cs b/PlumbingRepair/PlumbingRepair/FormComponents.cs index 685ca8d..b592821 100644 --- a/PlumbingRepair/PlumbingRepair/FormComponents.cs +++ b/PlumbingRepair/PlumbingRepair/FormComponents.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; +using System.Windows.Forms; namespace PlumbingRepair { @@ -23,18 +25,10 @@ namespace PlumbingRepair private void LoadData() { - try + try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка компонентов"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -46,31 +40,24 @@ namespace PlumbingRepair private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var form = DependencyManager.Instance.Resolve(); - 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) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } private void DeleteButton_Click(object sender, EventArgs e) diff --git a/PlumbingRepair/PlumbingRepair/FormImplementers.cs b/PlumbingRepair/PlumbingRepair/FormImplementers.cs index cd29385..b2c47a1 100644 --- a/PlumbingRepair/PlumbingRepair/FormImplementers.cs +++ b/PlumbingRepair/PlumbingRepair/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -26,14 +27,10 @@ namespace PlumbingRepair private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -41,14 +38,11 @@ namespace PlumbingRepair { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } @@ -98,14 +92,7 @@ namespace PlumbingRepair { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } diff --git a/PlumbingRepair/PlumbingRepair/FormMails.cs b/PlumbingRepair/PlumbingRepair/FormMails.cs index cf60ca0..eb9fa9b 100644 --- a/PlumbingRepair/PlumbingRepair/FormMails.cs +++ b/PlumbingRepair/PlumbingRepair/FormMails.cs @@ -20,14 +20,7 @@ namespace PlumbingRepair { 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; - } + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs index ed94cf7..5c1eff6 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -39,11 +39,12 @@ WorkComponentToolStripMenuItem = new ToolStripMenuItem(); OrdersToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem(); + письмаToolStripMenuItem = new ToolStripMenuItem(); + создатьБэкапToolStripMenuItem = new ToolStripMenuItem(); CreateOrderButton = new Button(); IssuedOrderButton = new Button(); UpdateListButton = new Button(); DataGridView = new DataGridView(); - письмаToolStripMenuItem = 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, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem }); + MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem, создатьБэкапToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(7, 3, 0, 3); @@ -129,6 +130,20 @@ запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРабот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.Location = new Point(832, 37); @@ -173,13 +188,6 @@ DataGridView.Size = new Size(825, 561); DataGridView.TabIndex = 1; // - // письмаToolStripMenuItem - // - письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - письмаToolStripMenuItem.Size = new Size(77, 24); - письмаToolStripMenuItem.Text = "Письма"; - письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -220,5 +228,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private DataGridView DataGridView; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs index b29d95d..7d7dd4f 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.cs @@ -1,9 +1,7 @@ using Microsoft.Extensions.Logging; -using PlumbingRepairBusinessLogic.BusinessLogic; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; -using PlumbingRepairDataModels.Enums; -using System.Windows.Forms; +using PlumbingRepairContracts.DI; namespace PlumbingRepair { @@ -14,13 +12,15 @@ namespace PlumbingRepair private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IBackUpLogic backUpLogic, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -34,16 +34,7 @@ namespace PlumbingRepair try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["WorkId"].Visible = false; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["ImplementerId"].Visible = false; - } - + DataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -55,41 +46,26 @@ namespace PlumbingRepair private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); - - if (service is FormWorks form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void CreateOrderButton_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(); + form.ShowDialog(); + LoadData(); } private void IssuedOrderButton_Click(object sender, EventArgs e) @@ -142,44 +118,55 @@ namespace PlumbingRepair private void WorkComponentToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents)); - if (service is FormReportWorkComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) + var form = DependencyManager.Instance.Resolve(); + 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); } } } diff --git a/PlumbingRepair/PlumbingRepair/FormWork.cs b/PlumbingRepair/PlumbingRepair/FormWork.cs index 2d1092c..b0ef724 100644 --- a/PlumbingRepair/PlumbingRepair/FormWork.cs +++ b/PlumbingRepair/PlumbingRepair/FormWork.cs @@ -4,6 +4,7 @@ using PlumbingRepairContracts.SearchModels; using PlumbingRepairDataModels.Models; using Microsoft.Extensions.Logging; using System.Windows.Forms; +using PlumbingRepairContracts.DI; namespace PlumbingRepair { @@ -77,31 +78,27 @@ namespace PlumbingRepair } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); - - if (service is FormWorkComponent form) - { + var form = DependencyManager.Instance.Resolve(); if (form.ShowDialog() == DialogResult.OK) { - if (form.ComponentModel == null) - { - 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(); + if (form.ComponentModel == null) + { + 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(); } } @@ -109,25 +106,21 @@ namespace PlumbingRepair { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); + var form = DependencyManager.Instance.Resolve(); + 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); - form.Id = id; - form.Count = _workComponents[id].Item2; - - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _workComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _workComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/PlumbingRepair/PlumbingRepair/FormWorks.cs b/PlumbingRepair/PlumbingRepair/FormWorks.cs index 5cbebac..7fe3a49 100644 --- a/PlumbingRepair/PlumbingRepair/FormWorks.cs +++ b/PlumbingRepair/PlumbingRepair/FormWorks.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; namespace PlumbingRepair { @@ -25,17 +26,8 @@ namespace PlumbingRepair { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["WorkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["WorkComponents"].Visible = false; - } - - _logger.LogInformation("Загрузка изделий"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -47,30 +39,21 @@ namespace PlumbingRepair private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWork)); - - if (service is FormWork form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWork)); - - if (service is FormWork form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/PlumbingRepair/PlumbingRepair/Program.cs b/PlumbingRepair/PlumbingRepair/Program.cs index 115e323..57338d8 100644 --- a/PlumbingRepair/PlumbingRepair/Program.cs +++ b/PlumbingRepair/PlumbingRepair/Program.cs @@ -1,7 +1,4 @@ using PlumbingRepairContracts.BusinessLogicsContracts; -using PlumbingRepairContracts.StoragesContracts; -using PlumbingRepairDatabaseImplement.Implements; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PlumbingRepairBusinessLogic.BusinessLogic; @@ -9,28 +6,23 @@ using PlumbingRepairBusinessLogic.OfficePackage; using PlumbingRepairBusinessLogic.OfficePackage.Implements; using PlumbingRepairContracts.BindingModels; using PlumbingRepairBusinessLogic.MailWorker; +using PlumbingRepairContracts.DI; namespace PlumbingRepair { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); + try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -45,51 +37,51 @@ namespace PlumbingRepair } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Error"); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => + private static void InitDependency() + { + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs b/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..4928909 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs @@ -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 configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj index efae3c4..703f115 100644 --- a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj +++ b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj @@ -8,6 +8,8 @@ + + diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs index df3236f..7e4b56a 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -15,11 +15,11 @@ namespace PlumbingRepairContracts.ViewModels public string WorkName { get; set; } = string.Empty; [Column(visible: false)] public int ClientId { get; set; } - [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; [Column(visible: false)] public int? ImplementerId { get; set; } - [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } @@ -27,9 +27,9 @@ namespace PlumbingRepairContracts.ViewModels public double Sum { get; set; } [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Column("Дата создания", width: 100)] + [Column("Дата создания", width: 130)] public DateTime DateCreate { get; set; } = DateTime.Now; - [Column("Дата выполнения", width: 100)] + [Column("Дата выполнения", width: 130)] public DateTime? DateImplement { get; set; } } }