diff --git a/.gitignore b/.gitignore index 9485fc0..23fdc7f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll files +*.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..9770c3e --- /dev/null +++ b/LawFirm/LawFirm/DataGridViewExtension.cs @@ -0,0 +1,50 @@ +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; + } + } + } + } + } +} diff --git a/LawFirm/LawFirm/FormBlanks.cs b/LawFirm/LawFirm/FormBlanks.cs index bc6a9ff..c6d6983 100644 --- a/LawFirm/LawFirm/FormBlanks.cs +++ b/LawFirm/LawFirm/FormBlanks.cs @@ -1,6 +1,8 @@ using LawFirm; +using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,13 +36,7 @@ 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; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка бланков"); } catch (Exception ex) @@ -52,8 +48,8 @@ namespace LawFirmView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormBlank)); - if (service is FormBlank form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { if (form.ShowDialog() == DialogResult.OK) { @@ -65,14 +61,12 @@ namespace LawFirmView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormBlank)); - if (service is FormBlank 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(); - } + } } } diff --git a/LawFirm/LawFirm/FormClients.cs b/LawFirm/LawFirm/FormClients.cs index 1f7c892..3e7bb7d 100644 --- a/LawFirm/LawFirm/FormClients.cs +++ b/LawFirm/LawFirm/FormClients.cs @@ -33,13 +33,7 @@ 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; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/LawFirm/LawFirm/FormDocument.cs b/LawFirm/LawFirm/FormDocument.cs index 0cf42af..305b0c1 100644 --- a/LawFirm/LawFirm/FormDocument.cs +++ b/LawFirm/LawFirm/FormDocument.cs @@ -1,6 +1,7 @@ using LawFirm; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using LawFirmContracts.SearchModels; using LawFirmDataModels.Models; using Microsoft.Extensions.Logging; @@ -99,26 +100,23 @@ namespace LawFirmView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormDocumentBlank)); - if (service is FormDocumentBlank form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.BlankModel == null) { - 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(); + 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(); } } @@ -126,22 +124,21 @@ namespace LawFirmView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormDocumentBlank)); - if (service is FormDocumentBlank form) + 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) { - 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; - } - _logger.LogInformation("Изменение бланка:{ BlankName}- { Count}", form.BlankModel.BlankName, form.Count); - _documentBlanks[form.Id] = (form.BlankModel,form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение бланка:{ BlankName}- { Count}", form.BlankModel.BlankName, form.Count); + _documentBlanks[form.Id] = (form.BlankModel,form.Count); + LoadData(); + } } } diff --git a/LawFirm/LawFirm/FormDocuments.cs b/LawFirm/LawFirm/FormDocuments.cs index 6bedfc7..b4fb4e2 100644 --- a/LawFirm/LawFirm/FormDocuments.cs +++ b/LawFirm/LawFirm/FormDocuments.cs @@ -1,6 +1,7 @@ using LawFirm; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,7 @@ 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; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка документов"); } catch (Exception ex) @@ -52,13 +46,10 @@ 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(); } } @@ -66,14 +57,11 @@ namespace LawFirmView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormDocument)); - if (service is FormDocument 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/LawFirm/LawFirm/FormImplementers.cs b/LawFirm/LawFirm/FormImplementers.cs index c37b690..f7271c7 100644 --- a/LawFirm/LawFirm/FormImplementers.cs +++ b/LawFirm/LawFirm/FormImplementers.cs @@ -1,6 +1,7 @@ using LawFirm; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,32 +34,22 @@ namespace LawFirmView { 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("Загрузка исполнителей"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonCreate_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(); } } @@ -66,14 +57,11 @@ namespace LawFirmView { 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(); } } } diff --git a/LawFirm/LawFirm/FormMails.cs b/LawFirm/LawFirm/FormMails.cs index b3e9263..4b0c499 100644 --- a/LawFirm/LawFirm/FormMails.cs +++ b/LawFirm/LawFirm/FormMails.cs @@ -28,15 +28,8 @@ namespace LawFirmView { 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 56e8283..9074c79 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -1,218 +1,227 @@ namespace LawFirmView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - menuStrip = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - бланкиToolStripMenuItem = new ToolStripMenuItem(); - документыToolStripMenuItem = new ToolStripMenuItem(); - клиентыToolStripMenuItem = new ToolStripMenuItem(); - исполнителиToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); - списокДокументовToolStripMenuItem = new ToolStripMenuItem(); - бланкиПоДокументамToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); - запускРаботToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonSetToFinish = new Button(); - buttonUpdate = new Button(); - письмаToolStripMenuItem = new ToolStripMenuItem(); - menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip - // - menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1139, 28); - menuStrip.TabIndex = 0; - menuStrip.Text = "Справочники"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { бланкиToolStripMenuItem, документыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, письмаToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(117, 24); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // бланкиToolStripMenuItem - // - бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - бланкиToolStripMenuItem.Size = new Size(224, 26); - бланкиToolStripMenuItem.Text = "Бланки"; - бланкиToolStripMenuItem.Click += бланкиToolStripMenuItem_Click; - // - // документыToolStripMenuItem - // - документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - документыToolStripMenuItem.Size = new Size(224, 26); - документыToolStripMenuItem.Text = "Документы"; - документыToolStripMenuItem.Click += документыToolStripMenuItem_Click; - // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(224, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; - // - // исполнителиToolStripMenuItem - // - исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(224, 26); - исполнителиToolStripMenuItem.Text = "Исполнители"; - исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; - // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокДокументовToolStripMenuItem, бланкиПоДокументамToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(73, 24); - отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокДокументовToolStripMenuItem - // - списокДокументовToolStripMenuItem.Name = "списокДокументовToolStripMenuItem"; - списокДокументовToolStripMenuItem.Size = new Size(252, 26); - списокДокументовToolStripMenuItem.Text = "Список документов"; - списокДокументовToolStripMenuItem.Click += списокДокументовToolStripMenuItem_Click; - // - // бланкиПоДокументамToolStripMenuItem - // - бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; - бланкиПоДокументамToolStripMenuItem.Size = new Size(252, 26); - бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; - бланкиПоДокументамToolStripMenuItem.Click += бланкиПоДокументамToolStripMenuItem_Click; - // - // списокЗаказовToolStripMenuItem - // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(252, 26); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; - // - // запускРаботToolStripMenuItem - // - запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - запускРаботToolStripMenuItem.Size = new Size(114, 24); - запускРаботToolStripMenuItem.Text = "Запуск работ"; - запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 31); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(915, 407); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(933, 45); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(194, 29); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += buttonCreateOrder_Click; - // - // buttonSetToFinish - // - buttonSetToFinish.Location = new Point(933, 80); - buttonSetToFinish.Name = "buttonSetToFinish"; - buttonSetToFinish.Size = new Size(194, 29); - buttonSetToFinish.TabIndex = 5; - buttonSetToFinish.Text = "Заказ выдан"; - buttonSetToFinish.UseVisualStyleBackColor = true; - buttonSetToFinish.Click += buttonSetToFinish_Click; - // - // buttonUpdate - // - buttonUpdate.Location = new Point(933, 410); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(194, 29); - buttonUpdate.TabIndex = 6; - buttonUpdate.Text = "Обновить"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += buttonUpdate_Click; - // - // письмаToolStripMenuItem - // - письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - письмаToolStripMenuItem.Size = new Size(224, 26); - письмаToolStripMenuItem.Text = "Письма"; - письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1139, 450); - Controls.Add(buttonUpdate); - Controls.Add(buttonSetToFinish); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Name = "FormMain"; - Text = "Юридическая компания"; - Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + бланкиToolStripMenuItem = new ToolStripMenuItem(); + документыToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); + письмаToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + списокДокументовToolStripMenuItem = new ToolStripMenuItem(); + бланкиПоДокументамToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonSetToFinish = new Button(); + buttonUpdate = new Button(); + создатьБэкапToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, создатьБэкапToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1139, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "Справочники"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { бланкиToolStripMenuItem, документыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, письмаToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // бланкиToolStripMenuItem + // + бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; + бланкиToolStripMenuItem.Size = new Size(185, 26); + бланкиToolStripMenuItem.Text = "Бланки"; + бланкиToolStripMenuItem.Click += бланкиToolStripMenuItem_Click; + // + // документыToolStripMenuItem + // + документыToolStripMenuItem.Name = "документыToolStripMenuItem"; + документыToolStripMenuItem.Size = new Size(185, 26); + документыToolStripMenuItem.Text = "Документы"; + документыToolStripMenuItem.Click += документыToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(185, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // + // письмаToolStripMenuItem + // + письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + письмаToolStripMenuItem.Size = new Size(185, 26); + письмаToolStripMenuItem.Text = "Письма"; + письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокДокументовToolStripMenuItem, бланкиПоДокументамToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокДокументовToolStripMenuItem + // + списокДокументовToolStripMenuItem.Name = "списокДокументовToolStripMenuItem"; + списокДокументовToolStripMenuItem.Size = new Size(252, 26); + списокДокументовToolStripMenuItem.Text = "Список документов"; + списокДокументовToolStripMenuItem.Click += списокДокументовToolStripMenuItem_Click; + // + // бланкиПоДокументамToolStripMenuItem + // + бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; + бланкиПоДокументамToolStripMenuItem.Size = new Size(252, 26); + бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; + бланкиПоДокументамToolStripMenuItem.Click += бланкиПоДокументамToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(252, 26); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(915, 407); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(933, 45); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(194, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonSetToFinish + // + buttonSetToFinish.Location = new Point(933, 80); + buttonSetToFinish.Name = "buttonSetToFinish"; + buttonSetToFinish.Size = new Size(194, 29); + buttonSetToFinish.TabIndex = 5; + buttonSetToFinish.Text = "Заказ выдан"; + buttonSetToFinish.UseVisualStyleBackColor = true; + buttonSetToFinish.Click += buttonSetToFinish_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(933, 410); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(194, 29); + buttonUpdate.TabIndex = 6; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // создатьБэкапToolStripMenuItem + // + создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem"; + создатьБэкапToolStripMenuItem.Size = new Size(122, 24); + создатьБэкапToolStripMenuItem.Text = "Создать бэкап"; + создатьБэкапToolStripMenuItem.Click += создатьБэкапToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1139, 450); + Controls.Add(buttonUpdate); + Controls.Add(buttonSetToFinish); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Юридическая компания"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem бланкиToolStripMenuItem; - private ToolStripMenuItem документыToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonSetToFinish; - private Button buttonUpdate; - private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem списокДокументовToolStripMenuItem; - private ToolStripMenuItem бланкиПоДокументамToolStripMenuItem; - private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem клиентыToolStripMenuItem; - private ToolStripMenuItem исполнителиToolStripMenuItem; - private ToolStripMenuItem запускРаботToolStripMenuItem; - private ToolStripMenuItem письмаToolStripMenuItem; - } + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem бланкиToolStripMenuItem; + private ToolStripMenuItem документыToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonSetToFinish; + private Button buttonUpdate; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокДокументовToolStripMenuItem; + private ToolStripMenuItem бланкиПоДокументамToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; + } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 1e1ad9a..7ad3cd7 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -2,6 +2,7 @@ using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using LawFirmDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -17,171 +18,165 @@ using System.Windows.Forms; namespace LawFirmView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly 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) - { - LoadData(); - } - private void LoadData() - { - _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; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void бланкиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormBlanks)); - if (service is FormBlanks form) - { - form.ShowDialog(); - } - } + private void бланкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void документыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormDocuments)); - if (service is FormDocuments form) - { - form.ShowDialog(); - } - } + private void документыToolStripMenuItem_Click(object sender, EventArgs e) + { + 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(); - } - } + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void бланкиПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks)); - if (service is FormReportDocumentBlanks form) - { - form.ShowDialog(); - } - } + private void бланкиПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrder)); - if (service is FormReportOrder form) - { - form.ShowDialog(); - } - } + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void списокДокументовToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveDocumentsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + private void списокДокументовToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveDocumentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } - } + } - private void buttonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } - private void buttonSetToFinish_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void buttonSetToFinish_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void buttonUpdate_Click(object sender, EventArgs e) - { - LoadData(); - } + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } - private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _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(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + private void письмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + 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/Program.cs b/LawFirm/LawFirm/Program.cs index d6c4074..439c111 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -4,6 +4,7 @@ using LawFirmBusinessLogic.OfficePackage; using LawFirmBusinessLogic.OfficePackage.Implements; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.DI; using LawFirmContracts.StorageContracts; using LawFirmDatabaseImplement.Implements; using LawFirmView; @@ -16,8 +17,6 @@ namespace LawFirm { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -28,14 +27,12 @@ namespace LawFirm // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); - try + try { - var mailSender = _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel + var mailSender = DependencyManager.Instance.Resolve(); + mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, @@ -49,57 +46,54 @@ namespace LawFirm } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, " "); + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + 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(); + 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(isSingle: true); - 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..c1766b2 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,100 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.StorageContracts; +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); + } + } + +} diff --git a/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs b/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..7515016 --- /dev/null +++ b/LawFirm/LawFirmContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,27 @@ +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; } + } + +} diff --git a/LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs b/LawFirm/LawFirmContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..3eee58e --- /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 + } +} diff --git a/LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs b/LawFirm/LawFirmContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..582c06d --- /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; + } +} diff --git a/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs index e0cb256..c1b29f0 100644 --- a/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs +++ b/LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace LawFirmContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IBackUpLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IBackUpLogic.cs new file mode 100644 index 0000000..ada7fa0 --- /dev/null +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IBackUpLogic.cs @@ -0,0 +1,15 @@ +using LawFirmContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.BusinessLogicContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } + +} diff --git a/LawFirm/LawFirmContracts/DI/DependencyManager.cs b/LawFirm/LawFirmContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..7402eaf --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +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 UnityDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action 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(); + } +} diff --git a/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..63f0e3b --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +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(); + } +} diff --git a/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs b/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..24a5ec5 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +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(); + } +} diff --git a/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..b76e995 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 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()!; + } + } +} diff --git a/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs b/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..3f37f23 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,52 @@ +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 + { + /// Загрузка всех классов-реализаций IImplementationExtension + 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"; + } + } +} diff --git a/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs b/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..81bf738 --- /dev/null +++ b/LawFirm/LawFirmContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Lifetime; +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); + } + } +} diff --git a/LawFirm/LawFirmContracts/LawFirmContracts.csproj b/LawFirm/LawFirmContracts/LawFirmContracts.csproj index 89ab575..fb5cb24 100644 --- a/LawFirm/LawFirmContracts/LawFirmContracts.csproj +++ b/LawFirm/LawFirmContracts/LawFirmContracts.csproj @@ -8,6 +8,8 @@ + + diff --git a/LawFirm/LawFirmContracts/StorageContracts/IBackUpInfo.cs b/LawFirm/LawFirmContracts/StorageContracts/IBackUpInfo.cs new file mode 100644 index 0000000..92b58a2 --- /dev/null +++ b/LawFirm/LawFirmContracts/StorageContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.StorageContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs index b5f1d5c..41feaba 100644 --- a/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/BlankViewModel.cs @@ -1,4 +1,5 @@ -using LawFirmDataModels.Models; +using LawFirmContracts.Attributes; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace LawFirmContracts.ViewModels { public class BlankViewModel : IBlankModel { - [DisplayName("Название бланка")] + [Column("Название бланка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string BlankName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Cost { get; set; } + [Column(visible: false)] public int Id { get; set; } } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs index 0175f67..c5b8e90 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using LawFirmDataModels.Models; +using LawFirmContracts.Attributes; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,16 @@ namespace LawFirmContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + + [Column(title:"ФИО клиента", width: 150 )] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (почта)")] + + [Column(title:"Логин (эл.почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs index 5771904..c474129 100644 --- a/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/DocumentViewModel.cs @@ -1,4 +1,5 @@ -using LawFirmDataModels.Models; +using LawFirmContracts.Attributes; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,16 @@ namespace LawFirmContracts.ViewModels { public class DocumentViewModel : IDocumentModel { - [DisplayName("Название документа")] + [Column("Название документа", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string DocumentName {get; set;} = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] public Dictionary DocumentBlanks { get; set; } = new(); + [Column(visible: false)] public int Id { get; set; } } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs index a27d009..1130c00 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using LawFirmDataModels.Models; +using LawFirmContracts.Attributes; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace LawFirmContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО")] + [Column("ФИО", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 200)] public string Password { get; set; } = string.Empty; - [DisplayName("Трудовой стаж")] + [Column("Трудовой стаж", width: 200)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", width: 200)] public int Qualification { get; set; } } } diff --git a/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs index c5283b5..e60ea87 100644 --- a/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using LawFirmDataModels.Models; +using LawFirmContracts.Attributes; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,16 +11,25 @@ namespace LawFirmContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } + [Column(visible: false)] + public int? ClientId { get; set; } + + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; + + [Column("Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } + + [Column("Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; + + [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/OrderViewModel.cs index a2f76c6..9c7270a 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; using System.Collections.Generic; @@ -11,33 +12,40 @@ namespace LawFirmContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + + [Column(visible: false)] public int DocumentId { get; set; } - [DisplayName("Документ")] + [Column("Документ", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string DocumentName { get; set; } = string.Empty; + + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("ФИО клиента")] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; + + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("ФИО исполнителя")] + + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } diff --git a/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs b/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs index 91ba52c..213f92a 100644 --- a/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs +++ b/LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace LawFirmDataModels.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..6e73d88 --- /dev/null +++ b/LawFirm/LawFirmDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using LawFirmContracts.DI; +using LawFirmContracts.StorageContracts; +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(); + } + } +} diff --git a/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs b/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..2d12386 --- /dev/null +++ b/LawFirm/LawFirmDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,31 @@ +using LawFirmContracts.StorageContracts; +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; + } + } +} diff --git a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj index 1590021..806d212 100644 --- a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj +++ b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs b/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs index a7db4b2..b9b775e 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs @@ -6,18 +6,23 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LawFirmDatabaseImplement.Models { + [DataContract] public class Blank : IBlankModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string BlankName { get; private set; } = String.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("BlankId")] diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Client.cs b/LawFirm/LawFirmDatabaseImplement/Models/Client.cs index e6f2a28..629205f 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Client.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Client.cs @@ -8,20 +8,26 @@ using System.ComponentModel.DataAnnotations; 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; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Document.cs b/LawFirm/LawFirmDatabaseImplement/Models/Document.cs index 1046285..3869ff9 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Document.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Document.cs @@ -6,22 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LawFirmDatabaseImplement.Models { + [DataContract] public class Document : IDocumentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string DocumentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Price { get; private set; } private Dictionary? _documentBlanks = null; [NotMapped] + [DataMember] public Dictionary DocumentBlanks { get diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs b/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs index d22c02d..809c81e 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs @@ -5,21 +5,24 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LawFirmDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [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")] diff --git a/LawFirm/LawFirmDatabaseImplement/Models/MessageInfo.cs b/LawFirm/LawFirmDatabaseImplement/Models/MessageInfo.cs index f5ceea7..ef13306 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/MessageInfo.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/MessageInfo.cs @@ -5,25 +5,28 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LawFirmDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [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.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; private set; } @@ -54,5 +57,6 @@ namespace LawFirmDatabaseImplement.Models DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs index a2f63bf..5413a8f 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs @@ -6,28 +6,38 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LawFirmDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int DocumentId { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; - + [DataMember] public DateTime? DateImplement { get; private set; } public virtual Document Document { get; set; } public virtual Client Client { get; set; } diff --git a/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs b/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..3b09ab1 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using LawFirmContracts.DI; +using LawFirmContracts.StorageContracts; +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(); + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs b/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..cf7eb09 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,33 @@ +using LawFirmContracts.StorageContracts; +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() + { + 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; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 77fe5b1..eff5599 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs index 2e7bbfd..3257682 100644 --- a/LawFirm/LawFirmFileImplement/Models/Blank.cs +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -5,18 +5,21 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { + [DataContract] public class Blank : IBlankModel { + [DataMember] public string BlankName { get; private set; } = String.Empty; - + [DataMember] public double Cost { get; set; } - + [DataMember] public int Id { get; private set; } public static Blank? Create(BlankBindingModel? model) diff --git a/LawFirm/LawFirmFileImplement/Models/Client.cs b/LawFirm/LawFirmFileImplement/Models/Client.cs index 9019f87..2cfab4b 100644 --- a/LawFirm/LawFirmFileImplement/Models/Client.cs +++ b/LawFirm/LawFirmFileImplement/Models/Client.cs @@ -4,20 +4,23 @@ using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - + [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; public static Client? Create(ClientBindingModel model) diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs index 6484a59..ad7cad4 100644 --- a/LawFirm/LawFirmFileImplement/Models/Document.cs +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -4,23 +4,27 @@ using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { + [DataContract] public class Document : IDocumentModel { + [DataMember] public string DocumentName { get; private set; } = string.Empty; - + [DataMember] public double Price { get; private set; } - + [DataMember] public int Id { get; private set; } public Dictionary Blanks { get; private set; } = new(); private Dictionary? _documentBlanks = null; + [DataMember] public Dictionary DocumentBlanks { get diff --git a/LawFirm/LawFirmFileImplement/Models/Implementer.cs b/LawFirm/LawFirmFileImplement/Models/Implementer.cs index a0bdb9a..bb69a78 100644 --- a/LawFirm/LawFirmFileImplement/Models/Implementer.cs +++ b/LawFirm/LawFirmFileImplement/Models/Implementer.cs @@ -4,22 +4,25 @@ using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [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) diff --git a/LawFirm/LawFirmFileImplement/Models/MessageInfo.cs b/LawFirm/LawFirmFileImplement/Models/MessageInfo.cs index e218081..819f19d 100644 --- a/LawFirm/LawFirmFileImplement/Models/MessageInfo.cs +++ b/LawFirm/LawFirmFileImplement/Models/MessageInfo.cs @@ -4,25 +4,28 @@ using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [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.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -76,5 +79,7 @@ namespace LawFirmFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 2a43e65..1755b9d 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -5,29 +5,35 @@ using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace LawFirmFileImplement.Models { + [DataContract] public class Order : IOrderModel { - public int DocumentId { get; private set; } - 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.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - + [DataMember] public int Id { get; private set; } + [DataMember] + public int DocumentId { get; private set; } + [DataMember] + public int ClientId { get; set; } + [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.Now; + [DataMember] + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) { diff --git a/LawFirm/LawFirmListImplements/Implements/BackUpInfo.cs b/LawFirm/LawFirmListImplements/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5c9a84d --- /dev/null +++ b/LawFirm/LawFirmListImplements/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using LawFirmContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmListImplements.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/LawFirm/LawFirmListImplements/LawFirmListImplements.csproj b/LawFirm/LawFirmListImplements/LawFirmListImplements.csproj index 3480974..55c291d 100644 --- a/LawFirm/LawFirmListImplements/LawFirmListImplements.csproj +++ b/LawFirm/LawFirmListImplements/LawFirmListImplements.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/LawFirm/LawFirmListImplements/ListImplementationExtension.cs b/LawFirm/LawFirmListImplements/ListImplementationExtension.cs new file mode 100644 index 0000000..438c025 --- /dev/null +++ b/LawFirm/LawFirmListImplements/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using LawFirmContracts.DI; +using LawFirmContracts.StorageContracts; +using LawFirmListImplements.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmListImplements +{ + 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(); + } + } +} diff --git a/LawFirm/LawFirmListImplements/Models/MessageInfo.cs b/LawFirm/LawFirmListImplements/Models/MessageInfo.cs index 4e051b7..c45c3fe 100644 --- a/LawFirm/LawFirmListImplements/Models/MessageInfo.cs +++ b/LawFirm/LawFirmListImplements/Models/MessageInfo.cs @@ -50,5 +50,6 @@ namespace LawFirmListImplements.Models DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } }