From b2dd3c2e3e4e6ef5b967d979e7147848aba30ac7 Mon Sep 17 00:00:00 2001 From: "leonteva.v" Date: Wed, 19 Jun 2024 23:52:53 +0400 Subject: [PATCH] 888888888 --- .gitignore | 1 + LawFirm/LawFirm/DataGridViewExtension.cs | 55 ++++++++ LawFirm/LawFirm/FormBlanks.cs | 45 +++---- LawFirm/LawFirm/FormDocument.cs | 67 +++++----- LawFirm/LawFirm/FormDocuments.cs | 37 ++---- LawFirm/LawFirm/FormMails.cs | 12 +- LawFirm/LawFirm/FormMain.Designer.cs | 31 +++-- LawFirm/LawFirm/FormMain.cs | 117 ++++++++---------- LawFirm/LawFirm/FormViewClients.cs | 13 +- LawFirm/LawFirm/FormViewImplementers.cs | 40 +++--- LawFirm/LawFirm/LawFirmView.csproj | 17 ++- LawFirm/LawFirm/Program.cs | 105 ++++++++-------- .../BusinessLogics/BackUpLogic.cs | 99 +++++++++++++++ .../Attributes/ColumnAttribute.cs | 28 +++++ .../Attributes/GridViewAutoSize.cs | 20 +++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 ++ .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 +++ .../LawFirmContracts/DI/DependencyManager.cs | 47 +++++++ .../DI/IDependencyContainer.cs | 18 +++ .../DI/IImplementationExtension.cs | 14 +++ .../DI/ServiceDependencyContainer.cs | 56 +++++++++ .../DI/ServiceProviderLoader.cs | 59 +++++++++ .../DI/UnityDependencyContainer.cs | 38 ++++++ .../LawFirmContracts/LawFirmContracts.csproj | 6 + .../StoragesContracts/IBackUpInfo.cs | 14 +++ .../ViewModels/BlankViewModel.cs | 16 +-- .../ViewModels/ClientViewModel.cs | 8 +- .../ViewModels/DocumentViewModel.cs | 17 +-- .../ViewModels/ImplementerViewModel.cs | 24 ++-- .../ViewModels/MessageInfoViewModel.cs | 13 +- .../ViewModels/OrderViewModel.cs | 45 +++---- .../Models/IMessageInfoModel.cs | 3 +- .../DatabaseImplementationExtension.cs | 26 ++++ .../Implements/BackUpInfo.cs | 32 +++++ .../LawFirmDatabase.cs | 2 +- .../LawFirmDatabaseImplement.csproj | 14 ++- ...ner.cs => 20240619192208_lab8.Designer.cs} | 6 +- ...0619095940_r.cs => 20240619192208_lab8.cs} | 2 +- .../LawFirmDatabaseModelSnapshot.cs | 2 +- .../LawFirmDatabaseImplement/Models/Blank.cs | 13 +- .../LawFirmDatabaseImplement/Models/Client.cs | 9 +- .../Models/Document.cs | 16 ++- .../Models/Implementer.cs | 19 ++- .../Models/Message.cs | 4 + .../LawFirmDatabaseImplement/Models/Order.cs | 26 ++-- .../FileImplementationExtension.cs | 26 ++++ .../Implements/BackUpInfo.cs | 34 +++++ .../LawFirmFileImplement.csproj | 6 +- LawFirm/LawFirmFileImplement/Models/Blank.cs | 13 +- LawFirm/LawFirmFileImplement/Models/Client.cs | 6 + .../LawFirmFileImplement/Models/Document.cs | 16 ++- .../Models/Implementer.cs | 19 ++- .../LawFirmFileImplement/Models/Message.cs | 9 ++ LawFirm/LawFirmFileImplement/Models/Order.cs | 25 ++-- .../Implements/BackUpInfo.cs | 21 ++++ .../LawFirmListImplement.csproj | 6 +- .../ListImplementationExtension.cs | 32 +++++ .../LawFirmListImplement/Models/Message.cs | 1 + 59 files changed, 1092 insertions(+), 386 deletions(-) create mode 100644 LawFirm/LawFirm/DataGridViewExtension.cs create mode 100644 LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs create mode 100644 LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs create mode 100644 LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 LawFirm/LawFirmContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 LawFirm/LawFirmContracts/DI/DependencyManager.cs create mode 100644 LawFirm/LawFirmContracts/DI/IDependencyContainer.cs create mode 100644 LawFirm/LawFirmContracts/DI/IImplementationExtension.cs create mode 100644 LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs create mode 100644 LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs create mode 100644 LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs create mode 100644 LawFirm/LawFirmContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 LawFirm/LawFirmDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs rename LawFirm/LawFirmDatabaseImplement/Migrations/{20240619095940_r.Designer.cs => 20240619192208_lab8.Designer.cs} (98%) rename LawFirm/LawFirmDatabaseImplement/Migrations/{20240619095940_r.cs => 20240619192208_lab8.cs} (99%) create mode 100644 LawFirm/LawFirmFileImplement/FileImplementationExtension.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs create mode 100644 LawFirm/LawFirmListImplement/Implements/BackUpInfo.cs create mode 100644 LawFirm/LawFirmListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..ae28e95 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +*.dll # Mono auto generated files mono_crash.* diff --git a/LawFirm/LawFirm/DataGridViewExtension.cs b/LawFirm/LawFirm/DataGridViewExtension.cs new file mode 100644 index 0000000..9eb44b8 --- /dev/null +++ b/LawFirm/LawFirm/DataGridViewExtension.cs @@ -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(this DataGridView grid, List? + 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; + } + } + } + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormBlanks.cs b/LawFirm/LawFirm/FormBlanks.cs index 5e73ed7..8f44ff1 100644 --- a/LawFirm/LawFirm/FormBlanks.cs +++ b/LawFirm/LawFirm/FormBlanks.cs @@ -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(); + 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(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } } private void buttonDelete_Click(object sender, EventArgs e) { diff --git a/LawFirm/LawFirm/FormDocument.cs b/LawFirm/LawFirm/FormDocument.cs index 3cb4683..ebc7ff2 100644 --- a/LawFirm/LawFirm/FormDocument.cs +++ b/LawFirm/LawFirm/FormDocument.cs @@ -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(); + 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(); + 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; } diff --git a/LawFirm/LawFirm/FormDocuments.cs b/LawFirm/LawFirm/FormDocuments.cs index 024f362..f0b9b8c 100644 --- a/LawFirm/LawFirm/FormDocuments.cs +++ b/LawFirm/LawFirm/FormDocuments.cs @@ -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(); + 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(); + 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) diff --git a/LawFirm/LawFirm/FormMails.cs b/LawFirm/LawFirm/FormMails.cs index eb89687..008fa93 100644 --- a/LawFirm/LawFirm/FormMails.cs +++ b/LawFirm/LawFirm/FormMails.cs @@ -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) { diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index ac6709c..c5ec57a 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index b8dd325..c81e046 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -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 logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger 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(); + 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(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(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(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(); + 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(); + 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(); + 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(); + 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(); + 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(), + _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(); + 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(); + 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); } } } diff --git a/LawFirm/LawFirm/FormViewClients.cs b/LawFirm/LawFirm/FormViewClients.cs index f283b45..3551b3c 100644 --- a/LawFirm/LawFirm/FormViewClients.cs +++ b/LawFirm/LawFirm/FormViewClients.cs @@ -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, "Ошибка загрузки клиентов"); diff --git a/LawFirm/LawFirm/FormViewImplementers.cs b/LawFirm/LawFirm/FormViewImplementers.cs index 93a0df7..b64d553 100644 --- a/LawFirm/LawFirm/FormViewImplementers.cs +++ b/LawFirm/LawFirm/FormViewImplementers.cs @@ -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(); + 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(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 2baa520..ca47b64 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -8,6 +8,14 @@ enable + + + + + + + + all @@ -30,13 +38,4 @@ - - - Always - - - Always - - - \ No newline at end of file diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index f54cb09..dee6d67 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -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(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = @@ -56,54 +56,61 @@ namespace LawFirmView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.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.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(); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void MailCheck(object obj) => ServiceProvider? - .GetService()?.MailCheck(); + private static void InitDependency() + { + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + 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(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(); + } + private static void MailCheck(object obj) => + DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..5a43e95 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -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 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(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs b/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..efd8c98 --- /dev/null +++ b/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs @@ -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; } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs b/LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..bb11c53 --- /dev/null +++ b/LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs @@ -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 + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs b/LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..deb7df7 --- /dev/null +++ b/LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -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; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs index a6e0d46..4d9527e 100644 --- a/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs +++ b/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs @@ -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(); } } \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IBackUpLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..3eacee2 --- /dev/null +++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -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); + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/DependencyManager.cs b/LawFirm/LawFirmContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..9078317 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/DependencyManager.cs @@ -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 configure) => + _dependencyManager.AddLogging(configure); + public void RegisterType(bool isSingle = false) where U : + class, T where T : class => _dependencyManager.RegisterType(isSingle); + public void RegisterType(bool isSingle = false) where T : class => + _dependencyManager.RegisterType(isSingle); + public T Resolve() => _dependencyManager.Resolve(); + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..3f2a4d0 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs @@ -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 configure); + void RegisterType(bool isSingle) where U : class, T where T : + class; + void RegisterType(bool isSingle) where T : class; + T Resolve(); + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs b/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..e24d55d --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs @@ -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(); + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..868b261 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs @@ -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 configure) + { + _serviceCollection.AddLogging(configure); + } + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs b/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..14ca28b --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs @@ -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"; + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..16d3747 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs @@ -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 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); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/LawFirmContracts.csproj b/LawFirm/LawFirmContracts/LawFirmContracts.csproj index 46ea406..7b7b461 100644 --- a/LawFirm/LawFirmContracts/LawFirmContracts.csproj +++ b/LawFirm/LawFirmContracts/LawFirmContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IBackUpInfo.cs b/LawFirm/LawFirmContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..c53cd8b --- /dev/null +++ b/LawFirm/LawFirmContracts/StoragesContracts/IBackUpInfo.cs @@ -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? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs index 3c9c200..7d56352 100644 --- a/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs @@ -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; } + } } \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs index 8c307d2..a26089d 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs @@ -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; } } \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs index ef6a1a1..1bd837c 100644 --- a/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs @@ -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 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 DocumentBlanks + { get; set; } = new(); diff --git a/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs index 64bd61e..f276986 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs @@ -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; } } } \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs index e9aa482..29cff59 100644 --- a/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs @@ -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(); } } \ No newline at end of file diff --git a/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs index 7d2b51d..6ccdea5 100644 --- a/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs @@ -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; } + } } \ No newline at end of file diff --git a/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs b/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs index 4cf9be2..e539669 100644 --- a/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs +++ b/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs @@ -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; } diff --git a/LawFirm/LawFirmDatabaseImplement/DatabaseImplementationExtension.cs b/LawFirm/LawFirmDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..b6d8193 --- /dev/null +++ b/LawFirm/LawFirmDatabaseImplement/DatabaseImplementationExtension.cs @@ -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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs b/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5d9c461 --- /dev/null +++ b/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs @@ -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? GetList() where T : class, new() + { + using var context = new LawFirmDatabase(); + return context.Set().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; + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs index 930053f..e0c60c1 100644 --- a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs +++ b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs @@ -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); } diff --git a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj index b14046f..9457751 100644 --- a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj +++ b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,13 +7,13 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -21,4 +21,8 @@ + + + + diff --git a/LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.Designer.cs b/LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.Designer.cs similarity index 98% rename from LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.Designer.cs rename to LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.Designer.cs index 320c646..0db7cf5 100644 --- a/LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.Designer.cs +++ b/LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.Designer.cs @@ -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 { /// 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); diff --git a/LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.cs b/LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.cs similarity index 99% rename from LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.cs rename to LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.cs index e60e8ab..17274a0 100644 --- a/LawFirm/LawFirmDatabaseImplement/Migrations/20240619095940_r.cs +++ b/LawFirm/LawFirmDatabaseImplement/Migrations/20240619192208_lab8.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace LawFirmDatabaseImplement.Migrations { /// - public partial class r : Migration + public partial class lab8 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/LawFirm/LawFirmDatabaseImplement/Migrations/LawFirmDatabaseModelSnapshot.cs b/LawFirm/LawFirmDatabaseImplement/Migrations/LawFirmDatabaseModelSnapshot.cs index 65543e8..8a243d9 100644 --- a/LawFirm/LawFirmDatabaseImplement/Migrations/LawFirmDatabaseModelSnapshot.cs +++ b/LawFirm/LawFirmDatabaseImplement/Migrations/LawFirmDatabaseModelSnapshot.cs @@ -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); diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs b/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs index c87cd66..9909619 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs @@ -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 DocumentBlanks { get; set; } = new(); public static Blank? Create(BlankBindingModel model) diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Client.cs b/LawFirm/LawFirmDatabaseImplement/Models/Client.cs index 35c5cb2..c37ab1d 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Client.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Client.cs @@ -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 Orders { get; set; } = new(); diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Document.cs b/LawFirm/LawFirmDatabaseImplement/Models/Document.cs index 33a62cb..db0916e 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Document.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Document.cs @@ -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? _documentBlanks = null; [NotMapped] - public Dictionary DocumentBlanks + [DataMember] + public Dictionary DocumentBlanks { get { diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs b/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs index 120f867..5abde92 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs @@ -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 Orders { get; private set; } = new(); public static Implementer? Create(ImplementerBindingModel model) diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Message.cs b/LawFirm/LawFirmDatabaseImplement/Models/Message.cs index d4874bd..60704bf 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Message.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Message.cs @@ -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(); } } \ No newline at end of file diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs index 8370033..0f2cef3 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs @@ -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; } diff --git a/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs b/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..4adaf68 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs @@ -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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs b/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5cfcf75 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs @@ -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? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)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; + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 77fe5b1..defa48a 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,8 @@ + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs index c02a5b7..701b450 100644 --- a/LawFirm/LawFirmFileImplement/Models/Blank.cs +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -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) diff --git a/LawFirm/LawFirmFileImplement/Models/Client.cs b/LawFirm/LawFirmFileImplement/Models/Client.cs index 7d36ec9..387d908 100644 --- a/LawFirm/LawFirmFileImplement/Models/Client.cs +++ b/LawFirm/LawFirmFileImplement/Models/Client.cs @@ -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) { diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs index 2647bf9..cc9c2b1 100644 --- a/LawFirm/LawFirmFileImplement/Models/Document.cs +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -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 Blanks { get; private set; } = new(); private Dictionary? _documentBlanks = null; - public Dictionary DocumentBlanks + [DataMember] + public Dictionary DocumentBlanks { get { diff --git a/LawFirm/LawFirmFileImplement/Models/Implementer.cs b/LawFirm/LawFirmFileImplement/Models/Implementer.cs index 2e2da30..3378524 100644 --- a/LawFirm/LawFirmFileImplement/Models/Implementer.cs +++ b/LawFirm/LawFirmFileImplement/Models/Implementer.cs @@ -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) diff --git a/LawFirm/LawFirmFileImplement/Models/Message.cs b/LawFirm/LawFirmFileImplement/Models/Message.cs index b9bd620..0d64b7b 100644 --- a/LawFirm/LawFirmFileImplement/Models/Message.cs +++ b/LawFirm/LawFirmFileImplement/Models/Message.cs @@ -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(); } } \ No newline at end of file diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 5995294..3251baf 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -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) { diff --git a/LawFirm/LawFirmListImplement/Implements/BackUpInfo.cs b/LawFirm/LawFirmListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..658d170 --- /dev/null +++ b/LawFirm/LawFirmListImplement/Implements/BackUpInfo.cs @@ -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? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmListImplement/LawFirmListImplement.csproj b/LawFirm/LawFirmListImplement/LawFirmListImplement.csproj index 77fe5b1..defa48a 100644 --- a/LawFirm/LawFirmListImplement/LawFirmListImplement.csproj +++ b/LawFirm/LawFirmListImplement/LawFirmListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,8 @@ + + + + diff --git a/LawFirm/LawFirmListImplement/ListImplementationExtension.cs b/LawFirm/LawFirmListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..3322b8a --- /dev/null +++ b/LawFirm/LawFirmListImplement/ListImplementationExtension.cs @@ -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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmListImplement/Models/Message.cs b/LawFirm/LawFirmListImplement/Models/Message.cs index eebe2ca..331ce53 100644 --- a/LawFirm/LawFirmListImplement/Models/Message.cs +++ b/LawFirm/LawFirmListImplement/Models/Message.cs @@ -42,5 +42,6 @@ namespace LawFirmListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + public int Id => throw new NotImplementedException(); } } \ No newline at end of file -- 2.25.1