From ed3e400b30ee5af46e234232177c34590aec600e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=9A=D1=83=D0=BA?= =?UTF-8?q?=D0=BB=D0=B5=D0=B2?= Date: Mon, 17 Jun 2024 19:27:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SoftwareInstallation/DataGridViewExtension.cs | 50 ++ SoftwareInstallation/FormClients.cs | 14 +- SoftwareInstallation/FormComponents.cs | 19 +- SoftwareInstallation/FormMain.Designer.cs | 491 +++++++++--------- SoftwareInstallation/FormMain.cs | 463 +++++++++-------- SoftwareInstallation/FormMain.resx | 21 +- SoftwareInstallation/FormPackage.cs | 5 +- SoftwareInstallation/FormPackages.cs | 18 +- SoftwareInstallation/FormViewMail.cs | 19 +- SoftwareInstallation/ImplementersForm.cs | 23 +- SoftwareInstallation/Program.cs | 81 ++- .../BusinessLogics/BackUpLogic.cs | 96 ++++ .../Attributes/ColumnAttribute.cs | 21 + .../Attributes/GridViewAutoSize.cs | 14 + .../BindingModels/BackUpSaveBinidngModel.cs | 8 + .../BindingModels/MessageInfoBindingModel.cs | 4 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 9 + .../DI/DependencyManager.cs | 41 ++ .../DI/IDependencyContainer.cs | 13 + .../DI/IImplementationExtension.cs | 9 + .../DI/ServiceDependencyContainer.cs | 57 ++ .../DI/ServiceProviderLoader.cs | 54 ++ .../StoragesContracts/IBackUpInfo.cs | 8 + .../ViewModels/ClientViewModel.cs | 11 +- .../ViewModels/ComponentViewModel.cs | 8 +- .../ViewModels/ImplementerViewModel.cs | 28 +- .../ViewModels/MessageInfoViewModel.cs | 38 +- .../ViewModels/OrderViewModel.cs | 32 +- .../ViewModels/PackageViewModel.cs | 15 +- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 27 + .../Implements/BackUpInfo.cs | 28 + .../Models/Client.cs | 120 ++--- .../Models/Component.cs | 8 +- .../Models/MessageInfo.cs | 92 ++-- .../Models/Order.cs | 53 +- .../Models/Package.cs | 10 +- .../FileImplementationExtension.cs | 27 + .../Implements/BackUpInfo .cs | 38 ++ .../Models/Client.cs | 5 + .../Models/Component.cs | 7 +- .../Models/Implementer.cs | 27 +- .../Models/MessageInfo.cs | 75 +++ .../Models/Order.cs | 35 +- .../Implements/BackUpInfo.cs | 17 + .../Implements/MessageInfoStorage.cs | 61 +++ .../ListImplementationExtension.cs | 28 + .../Models/MessageInfo.cs | 49 ++ 48 files changed, 1559 insertions(+), 820 deletions(-) create mode 100644 SoftwareInstallation/DataGridViewExtension.cs create mode 100644 SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 SoftwareInstallationContracts/Attributes/ColumnAttribute.cs create mode 100644 SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs create mode 100644 SoftwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 SoftwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 SoftwareInstallationContracts/DI/DependencyManager.cs create mode 100644 SoftwareInstallationContracts/DI/IDependencyContainer.cs create mode 100644 SoftwareInstallationContracts/DI/IImplementationExtension.cs create mode 100644 SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs create mode 100644 SoftwareInstallationContracts/DI/ServiceProviderLoader.cs create mode 100644 SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 SoftwareInstallationFileImplement/FileImplementationExtension.cs create mode 100644 SoftwareInstallationFileImplement/Implements/BackUpInfo .cs create mode 100644 SoftwareInstallationFileImplement/Models/MessageInfo.cs create mode 100644 SoftwareInstallationListImplement/Implements/BackUpInfo.cs create mode 100644 SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs create mode 100644 SoftwareInstallationListImplement/ListImplementationExtension.cs create mode 100644 SoftwareInstallationListImplement/Models/MessageInfo.cs diff --git a/SoftwareInstallation/DataGridViewExtension.cs b/SoftwareInstallation/DataGridViewExtension.cs new file mode 100644 index 0000000..0d3d2fc --- /dev/null +++ b/SoftwareInstallation/DataGridViewExtension.cs @@ -0,0 +1,50 @@ +using SoftwareInstallationContracts.Attributes; + +namespace SoftwareInstallation +{ + 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/SoftwareInstallation/FormClients.cs b/SoftwareInstallation/FormClients.cs index 133477f..3bd2049 100644 --- a/SoftwareInstallation/FormClients.cs +++ b/SoftwareInstallation/FormClients.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using SoftwareInstallation; namespace SoftwareInstallationView { @@ -28,18 +29,7 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Email"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/SoftwareInstallation/FormComponents.cs b/SoftwareInstallation/FormComponents.cs index c5b0764..f7089f0 100644 --- a/SoftwareInstallation/FormComponents.cs +++ b/SoftwareInstallation/FormComponents.cs @@ -1,7 +1,10 @@ using Microsoft.Extensions.Logging; +using SoftwareInstallation; using SoftwareInstallation.Forms; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.DI + using System; using System.Collections.Generic; using System.ComponentModel; @@ -32,14 +35,7 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -51,7 +47,7 @@ namespace SoftwareInstallationView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -64,11 +60,10 @@ namespace SoftwareInstallationView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); diff --git a/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/FormMain.Designer.cs index 825a64e..e4a6464 100644 --- a/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/FormMain.Designer.cs @@ -1,249 +1,256 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallation { - 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() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); - toolStrip1 = new ToolStrip(); - toolStripDropDownButton1 = new ToolStripDropDownButton(); - компоненты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(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - dataGridView = new DataGridView(); - почтаToolStripMenuItem = new ToolStripMenuItem(); - toolStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // toolStrip1 - // - toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem }); - toolStrip1.Location = new Point(0, 0); - toolStrip1.Name = "toolStrip1"; - toolStrip1.Size = new Size(969, 25); - toolStrip1.TabIndex = 0; - toolStrip1.Text = "toolStrip1"; - // - // toolStripDropDownButton1 - // - toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, ПутёвкиToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); - toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); - toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; - toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - toolStripDropDownButton1.Size = new Size(88, 22); - toolStripDropDownButton1.Text = "Справочник"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(180, 22); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; - // - // ПутёвкиToolStripMenuItem - // - ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; - ПутёвкиToolStripMenuItem.Size = new Size(180, 22); - ПутёвкиToolStripMenuItem.Text = "Туристич. путёвки"; - ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; - // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(180, 22); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; - // - // исполнителиToolStripMenuItem - // - исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(180, 22); - исполнителиToolStripMenuItem.Text = "Исполнители"; - исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; - // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоПутёвкамToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 25); - отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокКомпонентовToolStripMenuItem - // - списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - списокКомпонентовToolStripMenuItem.Size = new Size(216, 22); - списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; - списокКомпонентовToolStripMenuItem.Click += списокКомпонентовToolStripMenuItem_Click; - // - // компонентыПоПутёвкамToolStripMenuItem - // - компонентыПоПутёвкамToolStripMenuItem.Name = "компонентыПоПутёвкамToolStripMenuItem"; - компонентыПоПутёвкамToolStripMenuItem.Size = new Size(216, 22); - компонентыПоПутёвкамToolStripMenuItem.Text = "Компоненты по путёвкам"; - компонентыПоПутёвкамToolStripMenuItem.Click += компонентыПоПутёвкамToolStripMenuItem_Click; - // - // списокЗаказовToolStripMenuItem - // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(216, 22); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; - // - // запускРаботToolStripMenuItem - // - запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - запускРаботToolStripMenuItem.Size = new Size(92, 25); - запускРаботToolStripMenuItem.Text = "Запуск работ"; - запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(800, 56); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(141, 24); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += buttonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(800, 100); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(141, 24); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(800, 142); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(141, 24); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += buttonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(800, 181); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(141, 24); - buttonIssuedOrder.TabIndex = 4; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += buttonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(800, 222); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(141, 24); - buttonRef.TabIndex = 5; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += buttonRef_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 26); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(763, 435); - dataGridView.TabIndex = 6; - // - // почтаToolStripMenuItem - // - почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - почтаToolStripMenuItem.Size = new Size(53, 25); - почтаToolStripMenuItem.Text = "Почта"; - почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(969, 461); - Controls.Add(dataGridView); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(toolStrip1); - Name = "FormMain"; - Text = "Туристическая фирма"; - Load += FormMain_Load; - toolStrip1.ResumeLayout(false); - toolStrip1.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(); + запускРаботToolStripMenuItem1 = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = 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, запускРаботToolStripMenuItem1, почтаToolStripMenuItem, создатьБэкапToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1542, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "Меню справочников"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компоненты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 += ComponentsToolStripMenuItem_Click; + // + // ремонтToolStripMenuItem + // + ремонтToolStripMenuItem.Name = "ремонтToolStripMenuItem"; + ремонтToolStripMenuItem.Size = new Size(185, 26); + ремонтToolStripMenuItem.Text = "Ремонт"; + ремонтToolStripMenuItem.Click += RepairToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(185, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_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(267, 26); + списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; + списокКомпонентовToolStripMenuItem.Click += ListComponentToolStripMenuItem_Click; + // + // компонентыПоРемонтуToolStripMenuItem + // + компонентыПоРемонтуToolStripMenuItem.Name = "компонентыПоРемонтуToolStripMenuItem"; + компонентыПоРемонтуToolStripMenuItem.Size = new Size(267, 26); + компонентыПоРемонтуToolStripMenuItem.Text = "Компоненты по ремонту"; + компонентыПоРемонтуToolStripMenuItem.Click += RepairComponentToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(267, 26); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += ListOrderToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem1 + // + запускРаботToolStripMenuItem1.Name = "запускРаботToolStripMenuItem1"; + запускРаботToolStripMenuItem1.Size = new Size(114, 24); + запускРаботToolStripMenuItem1.Text = "Запуск работ"; + запускРаботToolStripMenuItem1.Click += StartingWorkToolStripMenuItem_Click; + // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(65, 24); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += MailToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(1272, 368); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1299, 68); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(212, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(1299, 125); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(212, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(1299, 189); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(212, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1299, 254); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(212, 29); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(1299, 322); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(212, 29); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // создатьБэкапToolStripMenuItem + // + создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem"; + создатьБэкапToolStripMenuItem.Size = new Size(122, 24); + создатьБэкапToolStripMenuItem.Text = "Создать бэкап"; + создатьБэкапToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1542, 403); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Автомастерская"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ToolStrip toolStrip1; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private DataGridView dataGridView; - private ToolStripDropDownButton toolStripDropDownButton1; - 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; - private ToolStripMenuItem почтаToolStripMenuItem; - } + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ремонтToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem списокКомпонентовToolStripMenuItem; + private ToolStripMenuItem компонентыПоРемонтуToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem1; + private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; + } } \ No newline at end of file diff --git a/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/FormMain.cs index 7a8cb12..9fc4a38 100644 --- a/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/FormMain.cs @@ -1,236 +1,249 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.DI; +using SoftwareInstallationDataModels.Enums; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using SoftwareInstallationBusinessLogic.BusinessLogic; using SoftwareInstallationView; +using SoftwareInstallation.Forms; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallation { - 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; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); + 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 + { + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + DependencyManager.Instance.Resolve(); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void RepairToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormPackages form) + { + form.ShowDialog(); + } + } + private void ListComponentToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SoftwareId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["SoftwareName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + } + private void RepairComponentToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportPackageComponents form) + { + form.ShowDialog(); + } + } + private void ListOrderToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } + private void StartingWorkToolStripMenuItem_Click(object sender, EventArgs e) + { - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - } - } - private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void консервыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSoftwares)); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); - if (service is FormSoftwares form) - { - form.ShowDialog(); - } - } - 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 buttonTakeOrderInWork_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.TakeOrderInWork(new OrderBindingModel - { - Id = id, - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonOrderReady_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("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonIssuedOrder_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.DeliveryOrder(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 buttonRef_Click(object sender, EventArgs e) - { - LoadData(); - } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value), + ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].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()), + }; + } + private void ButtonTakeOrderInWork_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.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_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(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_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.DeliveryOrder(CreateBindingModel(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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void MailToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormViewMail form) + { + form.ShowDialog(); + } + } + private void CreateBackUpToolStripMenuItem_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); + } - private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveSoftwaresToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - } - - private void компонентыПоПутёвкамToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = -Program.ServiceProvider?.GetService(typeof(FormReportSoftwareComponents)); - if (service is FormReportSoftwareComponents form) - { - form.ShowDialog(); - } - } - - private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = -Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - 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) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic -)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = -Program.ServiceProvider?.GetService(typeof(ImplementersForm)); - if (service is ImplementersForm form) - { - form.ShowDialog(); - } - } - - private void почтаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = -Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) - { - form.ShowDialog(); - } - - } - } + } + } } diff --git a/SoftwareInstallation/FormMain.resx b/SoftwareInstallation/FormMain.resx index e226a59..6c82d08 100644 --- a/SoftwareInstallation/FormMain.resx +++ b/SoftwareInstallation/FormMain.resx @@ -117,26 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - 56 - \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/FormPackage.cs index 969bf1d..5265e7b 100644 --- a/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/FormPackage.cs @@ -4,6 +4,7 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -82,7 +83,7 @@ namespace SoftwareInstallationView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPackageComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -110,7 +111,7 @@ namespace SoftwareInstallationView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormPackageComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/FormPackages.cs index fc2dd7c..313611e 100644 --- a/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/FormPackages.cs @@ -3,6 +3,7 @@ using SoftwareInstallation.Forms; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using System; +using SoftwareInstallationContracts.DI; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -11,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using SoftwareInstallation; namespace SoftwareInstallationView { @@ -32,16 +34,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["SoftwareComponents"].Visible = false; - dataGridView.Columns["SoftwareName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка изделий"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка ремонтов"); } catch (Exception ex) { @@ -51,7 +45,7 @@ namespace SoftwareInstallationView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSoftware)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSoftware form) { if (form.ShowDialog() == DialogResult.OK) @@ -64,7 +58,7 @@ namespace SoftwareInstallationView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSoftware)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSoftware form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SoftwareInstallation/FormViewMail.cs b/SoftwareInstallation/FormViewMail.cs index 84cc280..5553ccd 100644 --- a/SoftwareInstallation/FormViewMail.cs +++ b/SoftwareInstallation/FormViewMail.cs @@ -25,19 +25,12 @@ namespace SoftwareInstallation.Forms private void ViewMailForm_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("Загрузка списка писем"); - } - catch (Exception ex) + try + { + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); + } + catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки писем"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, diff --git a/SoftwareInstallation/ImplementersForm.cs b/SoftwareInstallation/ImplementersForm.cs index b774070..ba26d8b 100644 --- a/SoftwareInstallation/ImplementersForm.cs +++ b/SoftwareInstallation/ImplementersForm.cs @@ -2,6 +2,8 @@ using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.DI; +using System.Windows.Forms; using System; using System.Collections.Generic; using System.ComponentModel; @@ -35,20 +37,7 @@ namespace SoftwareInstallation.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView1.DataSource = list; - dataGridView1.Columns["Id"].Visible = false; - dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Qualification"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["WorkExperience"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView1.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -60,8 +49,7 @@ namespace SoftwareInstallation.Forms } private void CreateButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); - if (service is ImplementerForm form) + var service = DependencyManager.Instance.Resolve(); if (service is ImplementerForm form) { if (form.ShowDialog() == DialogResult.OK) { @@ -74,8 +62,7 @@ namespace SoftwareInstallation.Forms { if (dataGridView1.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + var service = DependencyManager.Instance.Resolve(); if (service is ImplementerForm form) { form.Id = diff --git a/SoftwareInstallation/Program.cs b/SoftwareInstallation/Program.cs index 49b9279..76ee28c 100644 --- a/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/Program.cs @@ -10,13 +10,12 @@ using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationBusinessLogic.MailWorker; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationView; +using SoftwareInstallationContracts.DI; namespace SoftwareInstallation.Forms { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -26,13 +25,12 @@ namespace SoftwareInstallation.Forms // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); + 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 = @@ -57,55 +55,48 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - 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(); - - 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(); - + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } private static void MailCheck(object obj) => -ServiceProvider?.GetService()?.MailCheck(); + DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..0d076d2 --- /dev/null +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,96 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + + +namespace SoftwareInstallationBusinessLogic.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/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs b/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..04908bd --- /dev/null +++ b/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,21 @@ +namespace SoftwareInstallationContracts.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/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs b/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..ed7bdb9 --- /dev/null +++ b/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace SoftwareInstallationContracts.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/SoftwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs b/SoftwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..64e03fd --- /dev/null +++ b/SoftwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,8 @@ +namespace SoftwareInstallationContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } + +} diff --git a/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs index b9f6582..e2ac6c3 100644 --- a/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SoftwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace SoftwareInstallationContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..48f936f --- /dev/null +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using SoftwareInstallationContracts.BindingModels; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/SoftwareInstallationContracts/DI/DependencyManager.cs b/SoftwareInstallationContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..9624577 --- /dev/null +++ b/SoftwareInstallationContracts/DI/DependencyManager.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationContracts.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(); + } +} diff --git a/SoftwareInstallationContracts/DI/IDependencyContainer.cs b/SoftwareInstallationContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..c791f9b --- /dev/null +++ b/SoftwareInstallationContracts/DI/IDependencyContainer.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationContracts.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/SoftwareInstallationContracts/DI/IImplementationExtension.cs b/SoftwareInstallationContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..e588248 --- /dev/null +++ b/SoftwareInstallationContracts/DI/IImplementationExtension.cs @@ -0,0 +1,9 @@ +namespace SoftwareInstallationContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + + } +} diff --git a/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs b/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..c20a11a --- /dev/null +++ b/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationContracts.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 T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where U : class, T 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/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs b/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..7d0e714 --- /dev/null +++ b/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,54 @@ +using System.Reflection; + +namespace SoftwareInstallationContracts.DI +{ + public static partial 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"; + } + } +} diff --git a/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs b/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..f88a496 --- /dev/null +++ b/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs b/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs index e657510..d594b2b 100644 --- a/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,19 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; + namespace SoftwareInstallationContracts.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: "Email клиента", 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/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs b/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs index 083b3c3..1e7592c 100644 --- a/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace SoftwareInstallationContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 80)] public double Cost { get; set; } } } diff --git a/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs index a27982d..5e62cd6 100644 --- a/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,16 +9,17 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.ViewModels { - public class ImplementerViewModel : IImplementerModel - { - public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] - public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - } + public class ImplementerViewModel : IImplementerModel + { + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int WorkExperience { get; set; } = 0; + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Qualification { get; set; } = 0; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; + } } diff --git a/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs index 9481530..ca8bfc6 100644 --- a/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,24 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SoftwareInstallationContracts.ViewModels { - public class MessageInfoViewModel : IMessageInfoModel - { - 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; - } + public class MessageInfoViewModel : IMessageInfoModel + { + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } + [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; + [Column(title: "Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, 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/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index c6207bb..be0f505 100644 --- a/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; @@ -11,26 +12,29 @@ namespace SoftwareInstallationContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + [Column(visible: false)] + public int RepairId { get; set; } + [Column(title: "Ремонт", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string RepairName { get; set; } = string.Empty; + [Column(visible: false)] public int ClientId { get; set; } - public int? ImplementerId { get; set; } = null; - [DisplayName("Клиент")] + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - public int SoftwareId { get; set; } - [DisplayName("Изделие")] - public string SoftwareName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(visible: false)] + public int? ImplementerId { get; set; } = null; + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } } diff --git a/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs b/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs index bdec610..528ad10 100644 --- a/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,13 +9,15 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.ViewModels { - public class PackageViewModel : IPackageModel + public class RepairViewModel : IRepairModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] - public string SoftwareName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Название ремонта", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string RepairName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] public double Price { get; set; } - public Dictionary SoftwareComponents { get; set; } = new(); + [Column(visible: false)] + public Dictionary RepairComponents { get; set; } = new(); } } diff --git a/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs index 53858e4..7264ec6 100644 --- a/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs +++ b/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace SoftwareInstallationDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs b/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..040d391 --- /dev/null +++ b/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDatabaseImplement.Implements; + +namespace SoftwareInstallationDatabaseImplement +{ + 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/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs b/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..214654b --- /dev/null +++ b/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,28 @@ +using SoftwareInstallationContracts.StoragesContracts; + +namespace SoftwareInstallationDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new RepairsShopDatabase(); + 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/SoftwareInstallationDatabaseImplement/Models/Client.cs b/SoftwareInstallationDatabaseImplement/Models/Client.cs index 81810ee..f9ecbe7 100644 --- a/SoftwareInstallationDatabaseImplement/Models/Client.cs +++ b/SoftwareInstallationDatabaseImplement/Models/Client.cs @@ -6,68 +6,70 @@ 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 SoftwareInstallationDatabaseImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } - - [Required] - public string ClientFIO { get; set; } = string.Empty; - [Required] - public string Email { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; - - [ForeignKey("ClientId")] - public virtual List Orders { get; set; } = new(); - - public static Client? Create(ClientBindingModel model) - { - if (model == null) - { - return null; - } - return new Client() - { - Id = model.Id, - ClientFIO = model.ClientFIO, - Email = model.Email, - Password = model.Password - }; - } - - public static Client Create(ClientViewModel model) - { - return new Client - { - Id = model.Id, - ClientFIO = model.ClientFIO, - Email = model.Email, - Password = model.Password - }; - } - - public void Update(ClientBindingModel model) - { - if (model == null) - { - return; - } - ClientFIO = model.ClientFIO; - Email = model.Email; - Password = model.Password; - } - - public ClientViewModel GetViewModel => new() - { - Id = Id, - ClientFIO = ClientFIO, - Email = Email, - Password = Password - }; - } + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Email { get; set; } = string.Empty; + [DataMember] + [Required] + public string Password { get; set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List MessageInfos { get; set; } = new(); + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public static Client Create(ClientViewModel model) + { + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + } } diff --git a/SoftwareInstallationDatabaseImplement/Models/Component.cs b/SoftwareInstallationDatabaseImplement/Models/Component.cs index 295f7e3..1ce4d1b 100644 --- a/SoftwareInstallationDatabaseImplement/Models/Component.cs +++ b/SoftwareInstallationDatabaseImplement/Models/Component.cs @@ -8,19 +8,23 @@ using System.Threading.Tasks; using SoftwareInstallationDataModels.Models; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ComponentName { get; private set; } = string.Empty; + [DataMember] [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] - public virtual List SoftwareComponents { get; set; } = - new(); + public virtual List RepairComponents { get; set; } = new(); public static Component? Create(ComponentBindingModel model) { if (model == null) diff --git a/SoftwareInstallationDatabaseImplement/Models/MessageInfo.cs b/SoftwareInstallationDatabaseImplement/Models/MessageInfo.cs index 8370339..87e6b60 100644 --- a/SoftwareInstallationDatabaseImplement/Models/MessageInfo.cs +++ b/SoftwareInstallationDatabaseImplement/Models/MessageInfo.cs @@ -2,52 +2,56 @@ using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel - { - [Key] - public string MessageId { get; private set; } = string.Empty; + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [NotMapped] + public int Id { get; private set; } + [DataMember] + [Key] + 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 Client? Client { get; private set; } + public static MessageInfo? Create(RepairsShopDatabase context, MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = context.Clients.FirstOrDefault(x => x.Email == model.SenderName).Id, + Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName), + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } - 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; - - public Client? Client { get; private set; } - - public static MessageInfo? Create(SoftwareInstallationDataBase context, MessageInfoBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Body = model.Body, - Subject = model.Subject, - ClientId = context.Clients.FirstOrDefault(x => x.Email == model.SenderName).Id, - Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName), - MessageId = model.MessageId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - }; - } - - public MessageInfoViewModel GetViewModel => new() - { - Body = Body, - Subject = Subject, - ClientId = ClientId, - MessageId = MessageId, - SenderName = SenderName, - DateDelivery = DateDelivery, - }; - } + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } } diff --git a/SoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallationDatabaseImplement/Models/Order.cs index 72e1434..1ad7305 100644 --- a/SoftwareInstallationDatabaseImplement/Models/Order.cs +++ b/SoftwareInstallationDatabaseImplement/Models/Order.cs @@ -5,35 +5,43 @@ using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; using System.Diagnostics; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public int Count { get; private set; } + [DataMember] [Required] public double Sum { get; private set; } + [DataMember] [Required] public OrderStatus Status { get; private set; } + [DataMember] [Required] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } + [DataMember] [Required] - public int SoftwareId { get; private set; } - public virtual Software Software { get; private set; } + public int RepairId { get; private set; } + public virtual Repair? Repair { get; private set; } + [DataMember] [Required] public int ClientId { get; private set; } - public virtual Client Client { get; private set; } - public int? ImplementerId { get; private set; } = null; - public virtual Implementer? Implementer { get; private set; } - public static Order? Create(SoftwareInstallationDataBase context, OrderBindingModel model) + public virtual Client? Client { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } = null; + public virtual Implementer? Implementer { get; private set; } + + public static Order? Create(OrderBindingModel model) { - if (model == null) - { - return null; - } return new Order() { Id = model.Id, @@ -42,14 +50,10 @@ namespace SoftwareInstallationDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - SoftwareId = model.SoftwareId, - Software = context.Softwares.FirstOrDefault(x => x.Id == model.SoftwareId), + RepairId = model.RepairId, ClientId = model.ClientId, - Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId), - ImplementerId = model.ImplementerId, - Implementer = (model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId) - : null), - }; + ImplementerId = model.ImplementerId, + }; } public void Update(OrderBindingModel? model) @@ -60,23 +64,24 @@ namespace SoftwareInstallationDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; - } + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { - SoftwareId = SoftwareId, + RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, + RepairName = Repair?.RepairName ?? string.Empty, + ClientFIO = Client?.ClientFIO ?? string.Empty, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - SoftwareName = Software.SoftwareName, Id = Id, - ClientFIO = Client.ClientFIO, - ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty) - }; + ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty) + }; } } diff --git a/SoftwareInstallationDatabaseImplement/Models/Package.cs b/SoftwareInstallationDatabaseImplement/Models/Package.cs index 99da96c..14ce8dc 100644 --- a/SoftwareInstallationDatabaseImplement/Models/Package.cs +++ b/SoftwareInstallationDatabaseImplement/Models/Package.cs @@ -9,18 +9,22 @@ using System.Text; using System.Threading.Tasks; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { public class Software : IPackageModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] - public string SoftwareName { get; set; } = string.Empty; + public string RepairName { get; set; } = string.Empty; + [DataMember] [Required] public double Price { get; set; } - private Dictionary? _SoftwareComponents = - null; + private Dictionary? _repairComponents = null; + [DataMember] [NotMapped] public Dictionary SoftwareComponents { diff --git a/SoftwareInstallationFileImplement/FileImplementationExtension.cs b/SoftwareInstallationFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..32f4273 --- /dev/null +++ b/SoftwareInstallationFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationFileImplement.Implements; + +namespace SoftwareInstallationFileImplement +{ + public class FileImplementationExtension : 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/SoftwareInstallationFileImplement/Implements/BackUpInfo .cs b/SoftwareInstallationFileImplement/Implements/BackUpInfo .cs new file mode 100644 index 0000000..4e7b711 --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/BackUpInfo .cs @@ -0,0 +1,38 @@ +using SoftwareInstallationContracts.StoragesContracts; +using System.Reflection; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + 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; + } + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.GetValue(source); + } + + } +} diff --git a/SoftwareInstallationFileImplement/Models/Client.cs b/SoftwareInstallationFileImplement/Models/Client.cs index 5a84646..11abcf5 100644 --- a/SoftwareInstallationFileImplement/Models/Client.cs +++ b/SoftwareInstallationFileImplement/Models/Client.cs @@ -9,14 +9,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace SoftwareInstallationFileImplement.Models { 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; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallationFileImplement/Models/Component.cs index a95f574..2f67dda 100644 --- a/SoftwareInstallationFileImplement/Models/Component.cs +++ b/SoftwareInstallationFileImplement/Models/Component.cs @@ -1,16 +1,21 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } - public static Component? Create(ComponentBindingModel? model) + public static Component? Create(ComponentBindingModel model) { if (model == null) { diff --git a/SoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallationFileImplement/Models/Implementer.cs index 20a54c2..a902912 100644 --- a/SoftwareInstallationFileImplement/Models/Implementer.cs +++ b/SoftwareInstallationFileImplement/Models/Implementer.cs @@ -4,22 +4,29 @@ using SoftwareInstallationDataModels; 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 SoftwareInstallationFileImplement.Models { - public class Implementer : IImplementerModel - { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int Qualification { get; set; } = 0; - public int WorkExperience { get; set; } = 0; - public static Implementer? Create(ImplementerBindingModel model) - { - if (model == null) + [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; set; } = string.Empty; + [DataMember] + public int Qualification { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) { return null; } diff --git a/SoftwareInstallationFileImplement/Models/MessageInfo.cs b/SoftwareInstallationFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..8f5e61b --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/MessageInfo.cs @@ -0,0 +1,75 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System.Runtime.Serialization; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + [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 int Id => throw new NotImplementedException(); + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + SenderName = element.Attribute("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } +} diff --git a/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallationFileImplement/Models/Order.cs index ec0363d..c4a9062 100644 --- a/SoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallationFileImplement/Models/Order.cs @@ -1,4 +1,5 @@  +using System.Runtime.Serialization; using System.Xml.Linq; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; @@ -7,25 +8,29 @@ using SoftwareInstallationDataModels.Models; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Order : IOrderModel { - public int SoftwareId { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public int RepairId { get; private set; } + [DataMember] public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } = null; - - public int Count { get; private set; } - + [DataMember] + public int? ImplementerId { get; private set; } = null; + [DataMember] + public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } - + [DataMember] public OrderStatus Status { get; private set; } - + [DataMember] public DateTime DateCreate { get; private set; } - + [DataMember] public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } - - public static Order? Create(OrderBindingModel? model) + public static Order? Create(OrderBindingModel model) { if (model == null) { @@ -34,15 +39,15 @@ namespace SoftwareInstallationFileImplement.Models return new Order() { Id = model.Id, - SoftwareId = model.SoftwareId, + RepairId = model.RepairId, ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - ImplementerId = model.ImplementerId, - }; + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId + }; } public static Order? Create(XElement element) diff --git a/SoftwareInstallationListImplement/Implements/BackUpInfo.cs b/SoftwareInstallationListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..dc51ab0 --- /dev/null +++ b/SoftwareInstallationListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using CarRepairShopContracts.StoragesContracts; + +namespace CarRepairShopListImplement.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/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..3fd1913 --- /dev/null +++ b/SoftwareInstallationListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,61 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var message in _source.Messages) + { + if (model.MessageId != null && model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + List result = new(); + foreach (var item in _source.Messages) + { + if (item.ClientId.HasValue && item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + List result = new(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SoftwareInstallationListImplement/ListImplementationExtension.cs b/SoftwareInstallationListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..78a566e --- /dev/null +++ b/SoftwareInstallationListImplement/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationListImplement.Implements; + +namespace SoftwareInstallationListImplement +{ + 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/SoftwareInstallationListImplement/Models/MessageInfo.cs b/SoftwareInstallationListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..61339a0 --- /dev/null +++ b/SoftwareInstallationListImplement/Models/MessageInfo.cs @@ -0,0 +1,49 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; + +namespace SoftwareInstallationListImplement.Models +{ + 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; + public int Id => throw new NotImplementedException(); + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } +}