From bb73ea28b125fb63a4f6146fb66421c78588ffb5 Mon Sep 17 00:00:00 2001 From: dyakonovr Date: Sat, 18 May 2024 21:39:16 +0400 Subject: [PATCH] All done --- .gitignore | 2 + .../DataGridViewExtension.cs | 55 +++ .../SoftwareInstallation/FormClients.cs | 10 +- .../SoftwareInstallation/FormComponents.cs | 35 +- .../SoftwareInstallation/FormImplementers.cs | 38 +- .../SoftwareInstallation/FormMails.cs | 11 +- .../SoftwareInstallation/FormMain.Designer.cs | 431 +++++++++--------- .../SoftwareInstallation/FormMain.cs | 398 ++++++++-------- .../SoftwareInstallation/FormPackage.cs | 96 ++-- .../SoftwareInstallation/FormPackages.cs | 52 +-- .../SoftwareInstallation/Program.cs | 184 ++++---- .../BusinessLogics/BackUpLogic.cs | 100 ++++ .../Controllers/HomeController.cs | 14 +- .../Attributes/ColumnAttribute.cs | 28 ++ .../Attributes/GridViewAutoSize.cs | 20 + .../BindingModels/BackUpSaveBindingModel.cs | 13 + .../BindingModels/ClientBindingModel.cs | 10 +- .../BindingModels/MailInfoBindingModel.cs | 3 +- .../BusinessLogicContracts/IBackUpLogic.cs | 14 + .../DI/DependencyManager.cs | 70 +++ .../DI/IDependencyContainer.cs | 41 ++ .../DI/IImplementationException.cs | 17 + .../DI/ServiceDependencyContainer.cs | 60 +++ .../DI/ServiceProviderLoader.cs | 63 +++ .../DI/UnityDependencyContainer.cs | 44 ++ .../SoftwareInstallationContracts.csproj | 6 + .../StoragesContracts/IBackUpInfo.cs | 14 + .../ViewModels/ClientViewModel.cs | 20 +- .../ViewModels/ComponentViewModel.cs | 18 +- .../ViewModels/ImplementerViewModel.cs | 24 +- .../ViewModels/MessageInfoViewModel.cs | 31 +- .../ViewModels/OrderViewModel.cs | 52 ++- .../ViewModels/PackageViewModel.cs | 24 +- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 28 ++ .../Implements/BackUpInfo.cs | 32 ++ .../Models/Client.cs | 12 +- .../Models/Component.cs | 11 +- .../Models/Implementer.cs | 17 +- .../Models/Message.cs | 23 +- .../Models/Order.cs | 32 +- .../Models/Package.cs | 14 +- ...ftwareInstallationDatabaseImplement.csproj | 4 + .../FileImplementationExtension.cs | 27 ++ .../Implements/BackUpInfo.cs | 37 ++ .../Implements/ClientStorage.cs | 145 +++--- .../Implements/MessageInfoStorage.cs | 80 ++-- .../Models/Client.cs | 10 +- .../Models/Component.cs | 7 +- .../Models/Implementer.cs | 16 +- .../Models/Message.cs | 26 +- .../Models/Order.cs | 4 - .../Models/Package.cs | 12 +- .../SoftwareInstallationFileImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 22 + .../Implements/ImplementerStorage.cs | 38 +- .../ListImplementationExtension.cs | 28 ++ .../Models/Message.cs | 3 +- .../Models/Order.cs | 2 - .../SoftwareInstallationListImplement.csproj | 4 + 60 files changed, 1693 insertions(+), 945 deletions(-) create mode 100644 SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs create mode 100644 SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BindingModels/BackUpSaveBindingModel.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IBackUpLogic.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/DependencyManager.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/IDependencyContainer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/IImplementationException.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/DI/UnityDependencyContainer.cs create mode 100644 SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs create mode 100644 SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs create mode 100644 SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index d813bb2..5af0e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +*.dll + # User-specific files *.rsuser *.suo diff --git a/SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs b/SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs new file mode 100644 index 0000000..eb5ff6d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs @@ -0,0 +1,55 @@ +using SoftwareInstallationContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationView +{ + 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/SoftwareInstallation/FormClients.cs b/SoftwareInstallation/SoftwareInstallation/FormClients.cs index cbc91e5..5070689 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormClients.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormClients.cs @@ -55,14 +55,8 @@ 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; - } - _logger.LogInformation("Загрузка клиентов"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) { diff --git a/SoftwareInstallation/SoftwareInstallation/FormComponents.cs b/SoftwareInstallation/SoftwareInstallation/FormComponents.cs index e6fb7fa..940ba52 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormComponents.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormComponents.cs @@ -2,6 +2,7 @@ using SoftwareInstallation; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -33,14 +34,8 @@ 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; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { @@ -51,28 +46,22 @@ namespace SoftwareInstallationView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs index 16a3f1e..af0f3a4 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs @@ -2,6 +2,7 @@ using SoftwareInstallation; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,14 +28,11 @@ namespace SoftwareInstallationView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } @@ -42,14 +40,12 @@ namespace SoftwareInstallationView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } @@ -99,16 +95,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка исполнителей"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.cs index 57706d1..820746b 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMails.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.cs @@ -29,15 +29,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["MessageId"].Visible = false; - DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка писем"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка писем"); } catch (Exception ex) { diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index e55e9df..aad058e 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -20,219 +20,227 @@ 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() - { - menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - изделияToolStripMenuItem = new ToolStripMenuItem(); - исполнителиToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem = new ToolStripMenuItem(); - списокИзделийToolStripMenuItem = new ToolStripMenuItem(); - компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); - запускРаботToolStripMenuItem = new ToolStripMenuItem(); - элекПисьмаToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRefresh = new Button(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, элекПисьмаToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(7, 3, 0, 3); - menuStrip1.Size = new Size(1077, 30); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, исполнителиToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(117, 24); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(185, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; - // - // изделияToolStripMenuItem - // - изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(185, 26); - изделияToolStripMenuItem.Text = "Изделия"; - изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; - // - // исполнителиToolStripMenuItem - // - исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(185, 26); - исполнителиToolStripMenuItem.Text = "Исполнители"; - исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; - // - // отчётыToolStripMenuItem - // - отчётыToolStripMenuItem.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(276, 26); - списокИзделийToolStripMenuItem.Text = "Список изделий"; - списокИзделийToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; - // - // компонентыПоИзделиямToolStripMenuItem - // - компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - компонентыПоИзделиямToolStripMenuItem.Size = new Size(276, 26); - компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; - компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; - // - // списокЗаказовToolStripMenuItem - // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(276, 26); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; - // - // запускРаботToolStripMenuItem - // - запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - запускРаботToolStripMenuItem.Size = new Size(114, 24); - запускРаботToolStripMenuItem.Text = "Запуск работ"; - запускРаботToolStripMenuItem.Click += ЗапускРаботToolStripMenuItem_Click; - // - // элекПисьмаToolStripMenuItem - // - элекПисьмаToolStripMenuItem.Name = "элекПисьмаToolStripMenuItem"; - элекПисьмаToolStripMenuItem.Size = new Size(172, 24); - элекПисьмаToolStripMenuItem.Text = "Электронные письма"; - элекПисьмаToolStripMenuItem.Click += электронныеПисьмаToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 36); - dataGridView.Margin = new Padding(3, 4, 3, 4); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(879, 432); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(885, 77); - buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(178, 41); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.Location = new Point(885, 127); - buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(178, 39); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.Location = new Point(885, 173); - buttonOrderReady.Margin = new Padding(3, 4, 3, 4); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(178, 36); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.Location = new Point(885, 217); - buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(178, 39); - buttonIssuedOrder.TabIndex = 5; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRefresh.Location = new Point(885, 264); - buttonRefresh.Margin = new Padding(3, 4, 3, 4); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(178, 39); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRef_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1077, 467); - Controls.Add(buttonRefresh); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Margin = new Padding(3, 4, 3, 4); - Name = "FormMain"; - Text = "Установка ПО"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + списокИзделийToolStripMenuItem = new ToolStripMenuItem(); + компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + элекПисьмаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + создатьБэкапToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, элекПисьмаToolStripMenuItem, создатьБэкапToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(7, 3, 0, 3); + menuStrip1.Size = new Size(1077, 30); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, исполнителиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(185, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(185, 26); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem + // + отчётыToolStripMenuItem.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(276, 26); + списокИзделийToolStripMenuItem.Text = "Список изделий"; + списокИзделийToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; + // + // компонентыПоИзделиямToolStripMenuItem + // + компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + компонентыПоИзделиямToolStripMenuItem.Size = new Size(276, 26); + компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; + компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(276, 26); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += ЗапускРаботToolStripMenuItem_Click; + // + // элекПисьмаToolStripMenuItem + // + элекПисьмаToolStripMenuItem.Name = "элекПисьмаToolStripMenuItem"; + элекПисьмаToolStripMenuItem.Size = new Size(172, 24); + элекПисьмаToolStripMenuItem.Text = "Электронные письма"; + элекПисьмаToolStripMenuItem.Click += электронныеПисьмаToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 36); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(879, 432); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(885, 77); + buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(178, 41); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(885, 127); + buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(178, 39); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(885, 173); + buttonOrderReady.Margin = new Padding(3, 4, 3, 4); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(178, 36); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(885, 217); + buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(178, 39); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(885, 264); + buttonRefresh.Margin = new Padding(3, 4, 3, 4); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(178, 39); + 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 += создатьБэкапToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1077, 467); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + Text = "Установка ПО"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; + private MenuStrip menuStrip1; private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; @@ -249,5 +257,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem элекПисьмаToolStripMenuItem; - } + private ToolStripMenuItem создатьБэкапToolStripMenuItem; + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 635e38b..2092cb9 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -3,6 +3,8 @@ using SoftwareInstallation; using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.ViewModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,221 +17,209 @@ using System.Windows.Forms; namespace SoftwareInstallationView { - 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, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _workProcess = workProcess; - _reportLogic = reportLogic; - LoadData(); - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IBackUpLogic _backUpLogic; + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic, IBackUpLogic backUpLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _workProcess = workProcess; + _reportLogic = reportLogic; + _backUpLogic = backUpLogic; + LoadData(); + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["PackageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } - - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void Компоненты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(FormPackages)); - - if (service is FormPackages form) - { - form.ShowDialog(); - } - } - private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs + try + { + List list = _orderLogic.ReadList(null); + dataGridView.FillandConfigGrid(list); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs + e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) - { + { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic - )) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); - } + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } - private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SavePackagesToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SavePackagesToWordFile(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(FormReportPackageComponents)); - if (service is FormReportPackageComponents form) - { - form.ShowDialog(); - } + private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); - } + } - private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) - { - _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 form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + 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(); + } - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } + private void электронныеПисьмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + 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 электронныеПисьмаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs index 45262af..bf2e924 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs @@ -2,7 +2,9 @@ using SoftwareInstallation; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.DI; using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationDatabaseImplement.Models; using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; @@ -82,57 +84,53 @@ namespace SoftwareInstallationView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); - if (service is FormPackageComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - if (_PackageComponents.ContainsKey(form.Id)) - { - _PackageComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _PackageComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_PackageComponents.ContainsKey(form.Id)) + { + _PackageComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _PackageComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + + LoadData(); + } + } private void ButtonUpd_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); - if (service is FormPackageComponent form) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _PackageComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - _PackageComponents[form.Id] = (form.ComponentModel, - form.Count); - LoadData(); - } - } - } - } + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + + form.Id = id; + form.Count = _PackageComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count); + _PackageComponents[id] = (form.ComponentModel, form.Count); + + LoadData(); + } + } + } private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/SoftwareInstallation/FormPackages.cs index 4fdc5d7..3e04fee 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackages.cs @@ -2,6 +2,7 @@ using SoftwareInstallation; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.DI; namespace SoftwareInstallationView { @@ -27,17 +28,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["PackageComponents"].Visible = false; - } - - _logger.LogInformation("Загрузка изделий"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -49,33 +41,27 @@ namespace SoftwareInstallationView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormPackage form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void ButtonUpdate_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); - if (service is FormPackage 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(); - } - } - } - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } private void ButtonDelete_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) diff --git a/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 3d3f812..5df79bb 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -8,106 +8,96 @@ using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationBusinessLogic.OfficePackage.Implements; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicContracts; -using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationDatabaseImplement.Implements; +using SoftwareInstallationContracts.DI; using SoftwareInstallationView; namespace SoftwareInstallation { - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + InitDependency(); + try + { + var mailSender = + DependencyManager.Instance.Resolve(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + // + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, " "); + } + Application.Run(DependencyManager.Instance.Resolve()); + } + private static void InitDependency() + { + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + } - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - - try - { - var mailSender = - _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel - { - MailLogin = - System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? - string.Empty, - MailPassword = - System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? - string.Empty, - SmtpClientHost = - System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? - string.Empty, - SmtpClientPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), - PopHost = - System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, - PopPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) - }); - // создаем таймер - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); - } - catch (Exception ex) - { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Ошибка работы с почтой"); - } - - - Application.Run(_serviceProvider.GetRequiredService()); - - } - - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.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(); - } - - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..0c238b7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicContracts; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace 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/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs index 251e2b7..edf7c1a 100644 --- a/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/SoftwareInstallationClientApp/Controllers/HomeController.cs @@ -36,12 +36,12 @@ namespace SoftwareInstallationClientApp.Controllers { if (APIClient.Client == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + throw new Exception(" ? "); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception("Введите логин, пароль и ФИО"); + throw new Exception(" , "); } APIClient.PostRequest("api/client/updatedata", new ClientBindingModel { @@ -75,13 +75,13 @@ namespace SoftwareInstallationClientApp.Controllers if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { - throw new Exception("Введите логин и пароль"); + throw new Exception(" "); } APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); if (APIClient.Client == null) { - throw new Exception("Неверный логин/пароль"); + throw new Exception(" /"); } Response.Redirect("Index"); } @@ -96,7 +96,7 @@ namespace SoftwareInstallationClientApp.Controllers if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception("Введите логин, пароль и ФИО"); + throw new Exception(" , "); } APIClient.PostRequest("api/client/register", new ClientBindingModel { @@ -118,11 +118,11 @@ namespace SoftwareInstallationClientApp.Controllers { if (APIClient.Client == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + throw new Exception(" ? "); } if (count <= 0) { - throw new Exception("Количество и сумма должны быть больше 0"); + throw new Exception(" 0"); } APIClient.PostRequest("api/main/createorder", new OrderBindingModel { diff --git a/SoftwareInstallation/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs b/SoftwareInstallation/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..2abc5e0 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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; } + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs b/SoftwareInstallation/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..22c1383 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/BackUpSaveBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..b36a600 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ClientBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ClientBindingModel.cs index b15d5a2..fbf9430 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ClientBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ClientBindingModel.cs @@ -9,10 +9,10 @@ namespace SoftwareInstallationContracts.BindingModels { public class ClientBindingModel : IClientModel { - public int Id { get; set; } - public string ClientFIO { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - } + public int Id { get; set; } + public string ClientFIO { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailInfoBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailInfoBindingModel.cs index 499f414..1819f00 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailInfoBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/MailInfoBindingModel.cs @@ -9,7 +9,8 @@ namespace SoftwareInstallationContracts.BindingModels { public class MessageInfoBindingModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } public string SenderName { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty; diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IBackUpLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IBackUpLogic.cs new file mode 100644 index 0000000..addb8cd --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using SoftwareInstallationContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/DI/DependencyManager.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..a1781be --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/DependencyManager.cs @@ -0,0 +1,70 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.DI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/SoftwareInstallation/SoftwareInstallationContracts/DI/IDependencyContainer.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..16aed2b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/IDependencyContainer.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/SoftwareInstallation/SoftwareInstallationContracts/DI/IImplementationException.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/IImplementationException.cs new file mode 100644 index 0000000..f34b7d7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/IImplementationException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..f47a726 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,60 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.DI; + +namespace SofrwareInstallationContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + + return _serviceProvider.GetService()!; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..9a32a20 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.DI +{ + public static partial class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = + Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = + (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = + (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > + source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + private static string TryGetImplementationExtensionsFolder() + { + var directory = new + DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && + !directory.GetDirectories("ImplementationExtensions", + SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } + +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/DI/UnityDependencyContainer.cs b/SoftwareInstallation/SoftwareInstallationContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..3c8272a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Lifetime; +using Unity.Microsoft.Logging; + +namespace SoftwareInstallationContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj b/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj index b59ce13..b0eec1a 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj +++ b/SoftwareInstallation/SoftwareInstallationContracts/SoftwareInstallationContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..ccdaed7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs index 8a295b3..0f1a570 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace SoftwareInstallationContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - } + [Column(visible: false)] + public int Id { get; set; } + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column("Логин (эл. почта)", width: 150)] + public string Email { get; set; } = string.Empty; + [Column("Пароль", width: 150)] + public string Password { get; set; } = string.Empty; + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs index 083b3c3..ba919b4 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs +++ b/SoftwareInstallation/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,13 @@ namespace SoftwareInstallationContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } - } + [Column(visible: false)] + public int Id { get; set; } + + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + + [Column("Цена", width: 80)] + public double Cost { get; set; } + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs index 8e2f9e1..e24eb9b 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace SoftwareInstallationContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column("Пароль", width: 150)] + public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } - } + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Qualification { get; set; } + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs index a879232..dba6c86 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Models; +using SoftwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,22 @@ namespace SoftwareInstallationContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } - [DisplayName("Имя отправителя")] - public string SenderName { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } + [Column("Имя отправителя", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата отправления")] - public DateTime DateDelivery { get; set; } - - [DisplayName("Тема")] - public string Subject { get; set; } = string.Empty; - - [DisplayName("Содержание")] - public string Body { get; set; } = string.Empty; - } + [Column("Дата отправления", width: 100)] + public DateTime DateDelivery { get; set; } + [Column("Тема", width: 150)] + public string Subject { get; set; } = string.Empty; + [Column("Содержание", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index 17d1651..08e30bf 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallation/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,31 @@ namespace SoftwareInstallationContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int PackageId { get; set; } - public int? ImplementerId { get; set; } - public int ClientId { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] - public string PackageName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } - } + [Column(visible: false)] + public int PackageId { get; set; } + + [Column(visible: false)] + public int ClientId { get; set; } + + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string PackageName { get; set; } = string.Empty; + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column("Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column("Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } + } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs index c2b7fd0..a7b89d7 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs +++ b/SoftwareInstallation/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; @@ -10,15 +11,14 @@ namespace SoftwareInstallationContracts.ViewModels { public class PackageViewModel : IPackageModel { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string PackageName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary PackageComponents - { - get; - set; - } = new(); - } + [Column(visible: false)] + public int Id { get; set; } + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PackageName { get; set; } = string.Empty; + [Column("Цена", width: 100)] + public double Price { get; set; } + + [Column(visible: false)] + public Dictionary PackageComponents { get; set; } = new(); + } } diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs index 4770eba..3763df8 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs +++ b/SoftwareInstallation/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/SoftwareInstallation/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..b08f725 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,28 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..167f5ba --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using SoftwareInstallationContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SoftwareInstallationDatabase(); + 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/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Client.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Client.cs index 05b2d13..b06b23b 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Client.cs @@ -6,19 +6,25 @@ 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 { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - [Required] + [DataMember] + [Required] public string ClientFIO { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Component.cs index 577412a..4c8587d 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Component.cs @@ -8,15 +8,20 @@ using System.Text; using System.Threading.Tasks; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ComponentName { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List PackageComponents { get; set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs index 50a5124..3786e32 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs @@ -8,24 +8,31 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { - [Required] + [DataMember] + [Required] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] - [Required] + [Required] public string Password { get; private set; } = string.Empty; + [DataMember] - [Required] + [Required] public int WorkExperience { get; private set; } + [DataMember] - [Required] + [Required] public int Qualification { get; private set; } + [DataMember] - public int Id { get; private set; } + public int Id { get; private set; } [ForeignKey("ImplementerId")] public virtual List Orders { get; private set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Message.cs index e6be313..a2dd654 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Message.cs @@ -5,25 +5,34 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Message : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } [Required] - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; [Required] - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; [Required] - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; [Required] - public string Body { get; private set; } = string.Empty; - public virtual Client? Client { get; set; } + [DataMember] + public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public virtual Client? Client { get; set; } public static Message? Create(MessageInfoBindingModel model) { diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs index fa98529..bc96a32 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs @@ -6,33 +6,39 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } - [Required] + [DataMember] + [Required] public int PackageId { get; private set; } [Required] - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } - - [Required] + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + [Required] public int Count { get; private set; } - - [Required] + [DataMember] + [Required] public double Sum { get; private set; } - - [Required] + [DataMember] + [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public virtual Package Package { get; set; } public virtual Client Client { get; private set; } diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Package.cs index 936b624..f5b1dee 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Package.cs @@ -8,23 +8,27 @@ using System.Text; using System.Threading.Tasks; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; +using System.Runtime.Serialization; namespace SoftwareInstallationDatabaseImplement.Models { + [DataContract] public class Package : IPackageModel { + [DataMember] public int Id { get; set; } - - [Required] + [DataMember] + [Required] public string PackageName { get; set; } = string.Empty; - - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _packageComponents = null; [NotMapped] - public Dictionary PackageComponents + [DataMember] + public Dictionary PackageComponents { get { diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabaseImplement.csproj b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabaseImplement.csproj index cf6f36a..9c6e1a0 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabaseImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabaseImplement.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..adbabc4 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..248cf42 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,37 @@ +using SoftwareInstallationContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var source = DataFileSingleton.GetInstance(); + + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + + return null; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ClientStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ClientStorage.cs index 7fad79b..396b882 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ClientStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ClientStorage.cs @@ -11,75 +11,78 @@ using System.Threading.Tasks; namespace SoftwareInstallationFileImplement.Implements { - public class ClientStorage : IClientStorage - { - private readonly DataFileSingleton source; - public ClientStorage() - { - source = DataFileSingleton.GetInstance(); - } - public List GetFullList() - { - return source.Clients - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(ClientSearchModel - model) - { - if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password)) - { - return new(); - } - return source.Clients - .Where(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO.Contains(model.ClientFIO) && - string.IsNullOrEmpty(model.Email) || x.ClientFIO.Contains(model.Email) && - string.IsNullOrEmpty(model.Password) || x.ClientFIO.Contains(model.Password))) - .Select(x => x.GetViewModel) - .ToList(); - } - public ClientViewModel? GetElement(ClientSearchModel model) - { - return source.Clients - .FirstOrDefault(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) && - (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email) && - (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) - ?.GetViewModel; - } - public ClientViewModel? Insert(ClientBindingModel model) - { - model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => - x.Id) + 1 : 1; - var newClient = Client.Create(model); - if (newClient == null) - { - return null; - } - source.Clients.Add(newClient); - source.SaveClients(); - return newClient.GetViewModel; - } - public ClientViewModel? Update(ClientBindingModel model) - { - var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - client.Update(model); - source.SaveClients(); - return client.GetViewModel; - } - public ClientViewModel? Delete(ClientBindingModel model) - { - var element = source.Clients.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - source.Clients.Remove(element); - source.SaveClients(); - return element.GetViewModel; - } - return null; - } - } + public class ClientStorage : IClientStorage + { + private readonly DataFileSingleton source; + public ClientStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Clients.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.ClientFIO)) + { + return new(); + } + return source.Clients + .Where(x => x.ClientFIO.Contains(model.ClientFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (model.Id.HasValue) + return source.Clients + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + return source.Clients + .FirstOrDefault(x => x.Email + .Equals(model.Email) && x.Password + .Equals(model.Password))? + .GetViewModel; + if (!string.IsNullOrEmpty(model.Email)) + return source.Clients + .FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel; + return null; + } + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1; + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + source.Clients.Add(newClient); + source.SaveClients(); + return newClient.GetViewModel; + } + public ClientViewModel? Update(ClientBindingModel model) + { + var ingredient = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (ingredient == null) + { + return null; + } + ingredient.Update(model); + source.SaveClients(); + return ingredient.GetViewModel; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + var element = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Clients.Remove(element); + source.SaveClients(); + return element.GetViewModel; + } + return null; + } + } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs index e0f634f..13027ce 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/MessageInfoStorage.cs @@ -11,47 +11,47 @@ using System.Threading.Tasks; namespace SoftwareInstallationFileImplement.Implements { - public class MessageInfoStorage : IMessageInfoStorage - { - private readonly DataFileSingleton source; - public MessageInfoStorage() - { - source = DataFileSingleton.GetInstance(); - } - public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) - { - if (model.MessageId == null) - return null; - return source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; - } + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton source; + public MessageInfoStorage() + { + source = DataFileSingleton.GetInstance(); + } + public MessageInfoViewModel GetElement(MessageInfoSearchModel model) + { + if (model.MessageId == null) + return null; + return source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } - public List GetFilteredList(MessageInfoSearchModel model) - { - if (!model.ClientId.HasValue) - return new(); - return source.Messages - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); - } + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + return new(); + return source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } - public List GetFullList() - { - return source.Messages - .Select(x => x.GetViewModel) - .ToList(); - } + public List GetFullList() + { + return source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } - public MessageInfoViewModel? Insert(MessageInfoBindingModel model) - { - var newMessage = Message.Create(model); - if (newMessage == null) - { - return null; - } - source.Messages.Add(newMessage); - source.SaveMessages(); - return newMessage.GetViewModel; - } - } + public MessageInfoViewModel Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + source.Messages.Add(newMessage); + source.SaveMessages(); + return newMessage.GetViewModel; + } + } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs index 36167c0..25346a6 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs @@ -4,17 +4,23 @@ using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; set; } = string.Empty; + [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/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs index 421b1ab..c24f0f7 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs @@ -4,16 +4,21 @@ using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Component : IComponentModel { - public int Id { get; private set; } + [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) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs index c29d877..f5e07f0 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs @@ -4,23 +4,27 @@ using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } - - public int Qualification { get; private set; } - - public int Id { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } + [DataMember] + public int Qualification { get; private set; } + [DataMember] + public int Id { get; private set; } public static Implementer? Create(XElement element) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs index 1700df8..54930b4 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs @@ -4,25 +4,29 @@ using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Message : 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(); + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static Message? Create(MessageInfoBindingModel model) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs index 433fa55..5cad0be 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs @@ -32,7 +32,6 @@ namespace SoftwareInstallationFileImplement.Models { Id = model.Id, PackageId = model.PackageId, - ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,7 +51,6 @@ namespace SoftwareInstallationFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), @@ -82,7 +80,6 @@ namespace SoftwareInstallationFileImplement.Models { Id = Id, PackageId = PackageId, - ClientId = ClientId, Count = Count, ImplementerId = ImplementerId, Sum = Sum, @@ -93,7 +90,6 @@ namespace SoftwareInstallationFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("PackageId", PackageId.ToString()), - new XElement("ClientId", ClientId.ToString()), new XElement("Count", Count.ToString()), new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Sum", Sum.ToString()), diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs index 7ae17ff..4634fd7 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs @@ -4,20 +4,26 @@ using SoftwareInstallationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Package : IPackageModel { + [DataMember] public int Id { get; private set; } - public string PackageName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public string PackageName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _PackageComponents = null; - public Dictionary PackageComponents + [DataMember] + public Dictionary PackageComponents { get { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj b/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj index d544409..ff61787 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..3abc04a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using SoftwareInstallationContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement.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/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs index 3c69863..1d93ef5 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs @@ -2,7 +2,6 @@ using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; -using SoftwareInstallationListImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -93,28 +92,29 @@ namespace SoftwareInstallationListImplement.Implements return result; } - public ImplementerViewModel? Insert(ImplementerBindingModel model) - { - model.Id = 1; + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; - foreach (var implementer in _source.Implementers) - { - if (model.Id <= implementer.Id) - { - model.Id = implementer.Id + 1; - } - } + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } - var res = Implementer.Create(model); + return null; + /*var res = Implementer.Create(model);*/ - if (res != null) - { - _source.Implementers.Add(res); - } - return res?.GetViewModel; - } + /*if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel;*/ + } - public ImplementerViewModel? Update(ImplementerBindingModel model) + public ImplementerViewModel? Update(ImplementerBindingModel model) { foreach (var implementer in _source.Implementers) { diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..97310db --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using SoftwareInstallationContracts.DI; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs index b7b7840..ed1a3e2 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs @@ -22,8 +22,9 @@ namespace SoftwareInstallationListImplement.Models public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); - public static Message? Create(MessageInfoBindingModel model) + public static Message? Create(MessageInfoBindingModel model) { if (model == null) { diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs index 08d5a17..ae568d6 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs @@ -32,7 +32,6 @@ namespace SoftwareInstallationListImplement.Models return new Order { PackageId = model.PackageId, - ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,7 +54,6 @@ namespace SoftwareInstallationListImplement.Models { Id = Id, PackageId = PackageId, - ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj index d544409..ff61787 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj @@ -11,4 +11,8 @@ + + + + -- 2.25.1