From 10cd57978420f539d8f098a84a7508f30eb29b0e Mon Sep 17 00:00:00 2001 From: Kristina Date: Sun, 2 Jun 2024 16:49:08 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=B7=D0=B0=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + .../BackUpInfo.cs | 41 ++ .../FileImplementationExtension.cs | 32 ++ .../DataGridViewExtension.cs | 50 ++ .../BlacksmithWorkshop/FormComponents.cs | 6 +- .../BlacksmithWorkshop/FormMain.Designer.cs | 429 ++++++++-------- .../BlacksmithWorkshop/FormMain.cs | 465 ++++++++++-------- .../BlacksmithWorkshop/FormManufacture.cs | 5 +- .../BlacksmithWorkshop/FormManufactures.cs | 5 +- .../BlacksmithWorkshop/ImplementersForm.cs | 7 +- .../BlacksmithWorkshop/Program.cs | 156 +++--- .../BusinessLogics/BackUpLogic.cs | 98 ++++ .../Attributes/ColumnAttribute.cs | 28 ++ .../Attributes/GridViewAutoSize.cs | 20 + .../BindingModels/BackUpSaveBinidngModel.cs | 13 + .../BlacksmithWorkshopContracts.csproj | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 + .../DI/DependencyManager.cs | 50 ++ .../DI/IDependencyContainer.cs | 17 + .../DI/IImplementationExtension.cs | 14 + .../DI/ServiceDependencyContainer.cs | 61 +++ .../DI/ServiceProviderLoader.cs | 54 ++ .../StoragesContracts/IBackUpInfo.cs | 14 + .../BackUpInfo.cs | 32 ++ .../BlacksmithWorkshopDataBase.cs | 2 +- .../DatabaseImplementationExtension.cs | 32 ++ .../BackUpInfo.cs | 22 + .../BlacksmithWorkshopListImplement.csproj | 4 + .../ListImplementationExtension.cs | 33 ++ 29 files changed, 1184 insertions(+), 523 deletions(-) create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/FileImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/BackUpInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..af019b6 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,8 @@ ScaffoldingReadMe.txt # StyleCop StyleCopReport.xml +/BlacksmithWorkshop/ImplementationExtensions + # Files built by Visual Studio *_i.c *_p.c diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BackUpInfo.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BackUpInfo.cs new file mode 100644 index 0000000..b6c49bd --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BackUpInfo.cs @@ -0,0 +1,41 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && + x.PropertyType.GetGenericArguments()[0] == requredType)?.GetValue(source); + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/FileImplementationExtension.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..1425e14 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/FileImplementationExtension.cs @@ -0,0 +1,32 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 0; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs new file mode 100644 index 0000000..2a88a28 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs @@ -0,0 +1,50 @@ +using BlacksmithWorkshopContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshop +{ + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs index 6cb054c..8ee68ac 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -51,7 +52,7 @@ namespace BlacksmithWorkshop } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -64,8 +65,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { form.Id = diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 857aa72..011e3a6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -20,218 +20,226 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - menuStrip = new MenuStrip(); - GuidesToolStripMenuItem = new ToolStripMenuItem(); - ComponentsToolStripMenuItem = new ToolStripMenuItem(); - ManufacturesToolStripMenuItem = new ToolStripMenuItem(); - ClientsToolStripMenuItem = new ToolStripMenuItem(); - ImplementersToolStripMenuItem = new ToolStripMenuItem(); - StartWorkingToolStripMenuItem = new ToolStripMenuItem(); - ReportsToolStripMenuItem = new ToolStripMenuItem(); - ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); - ManufacturesComponentsListToolStripMenuItem = new ToolStripMenuItem(); - OrdersListToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonRefresh = new Button(); - buttonIssued = new Button(); - buttonReady = new Button(); - buttonTakeInWork = new Button(); - MailToolStripMenuItem = new ToolStripMenuItem(); - menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip - // - menuStrip.ImageScalingSize = new Size(24, 24); - menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(9, 3, 0, 3); - menuStrip.Size = new Size(1810, 35); - menuStrip.TabIndex = 0; - menuStrip.Text = "Меню"; - // - // GuidesToolStripMenuItem - // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem, StartWorkingToolStripMenuItem, MailToolStripMenuItem }); - GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; - GuidesToolStripMenuItem.Size = new Size(139, 29); - GuidesToolStripMenuItem.Text = "Справочники"; - // - // ComponentsToolStripMenuItem - // - ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(272, 34); - ComponentsToolStripMenuItem.Text = "Компоненты"; - ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; - // - // ManufacturesToolStripMenuItem - // - ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(272, 34); - ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; - ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; - // - // ClientsToolStripMenuItem - // - ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(272, 34); - ClientsToolStripMenuItem.Text = "Клиенты"; - ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // ImplementersToolStripMenuItem - // - ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; - ImplementersToolStripMenuItem.Size = new Size(272, 34); - ImplementersToolStripMenuItem.Text = "Исполнители"; - ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; - // - // StartWorkingToolStripMenuItem - // - StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; - StartWorkingToolStripMenuItem.Size = new Size(272, 34); - StartWorkingToolStripMenuItem.Text = "Старт работ"; - StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; - // - // ReportsToolStripMenuItem - // - ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); - ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; - ReportsToolStripMenuItem.Size = new Size(88, 29); - ReportsToolStripMenuItem.Text = "Отчёты"; - // - // ManufacturesListToolStripMenuItem - // - ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem"; - ManufacturesListToolStripMenuItem.Size = new Size(335, 34); - ManufacturesListToolStripMenuItem.Text = "Список кузнечных изделий"; - ManufacturesListToolStripMenuItem.Click += ManufacturesListToolStripMenuItem_Click; - // - // ManufacturesComponentsListToolStripMenuItem - // - ManufacturesComponentsListToolStripMenuItem.Name = "ManufacturesComponentsListToolStripMenuItem"; - ManufacturesComponentsListToolStripMenuItem.Size = new Size(335, 34); - ManufacturesComponentsListToolStripMenuItem.Text = "Компоненты по изделиям"; - ManufacturesComponentsListToolStripMenuItem.Click += ManufacturesComponentsListToolStripMenuItem_Click; - // - // OrdersListToolStripMenuItem - // - OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem"; - OrdersListToolStripMenuItem.Size = new Size(335, 34); - OrdersListToolStripMenuItem.Text = "Список заказов"; - OrdersListToolStripMenuItem.Click += OrdersListToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 38); - dataGridView.Margin = new Padding(4, 5, 4, 5); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 62; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(1573, 712); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(1581, 45); - buttonCreateOrder.Margin = new Padding(4, 5, 4, 5); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(211, 52); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += CreateOrderButton_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(1581, 292); - buttonRefresh.Margin = new Padding(4, 5, 4, 5); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(211, 52); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += RefreshButton_Click; - // - // buttonIssued - // - buttonIssued.Location = new Point(1581, 230); - buttonIssued.Margin = new Padding(4, 5, 4, 5); - buttonIssued.Name = "buttonIssued"; - buttonIssued.Size = new Size(211, 52); - buttonIssued.TabIndex = 4; - buttonIssued.Text = "Заказ выдан"; - buttonIssued.UseVisualStyleBackColor = true; - buttonIssued.Click += IssuedButton_Click; - // - // buttonReady - // - buttonReady.Location = new Point(1581, 168); - buttonReady.Margin = new Padding(4, 5, 4, 5); - buttonReady.Name = "buttonReady"; - buttonReady.Size = new Size(211, 52); - buttonReady.TabIndex = 5; - buttonReady.Text = "Заказ готов"; - buttonReady.UseVisualStyleBackColor = true; - buttonReady.Click += ReadyButton_Click; - // - // buttonTakeInWork - // - buttonTakeInWork.Location = new Point(1581, 107); - buttonTakeInWork.Margin = new Padding(4, 5, 4, 5); - buttonTakeInWork.Name = "buttonTakeInWork"; - buttonTakeInWork.Size = new Size(211, 52); - buttonTakeInWork.TabIndex = 6; - buttonTakeInWork.Text = "Отдать на выполнение"; - buttonTakeInWork.UseVisualStyleBackColor = true; - buttonTakeInWork.Click += TakeInWorkButton_Click; - // - // MailToolStripMenuItem - // - MailToolStripMenuItem.Name = "MailToolStripMenuItem"; - MailToolStripMenuItem.Size = new Size(272, 34); - MailToolStripMenuItem.Text = "Почта"; - MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(10F, 25F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1810, 750); - Controls.Add(buttonTakeInWork); - Controls.Add(buttonReady); - Controls.Add(buttonIssued); - Controls.Add(buttonRefresh); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Margin = new Padding(4, 5, 4, 5); - Name = "FormMain"; - StartPosition = FormStartPosition.CenterParent; - Text = "Кузница"; - Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + GuidesToolStripMenuItem = new ToolStripMenuItem(); + ComponentsToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + StartWorkingToolStripMenuItem = new ToolStripMenuItem(); + MailToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesComponentsListToolStripMenuItem = new ToolStripMenuItem(); + OrdersListToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonRefresh = new Button(); + buttonIssued = new Button(); + buttonReady = new Button(); + buttonTakeInWork = new Button(); + BackupToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(24, 24); + menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(9, 3, 0, 3); + menuStrip.Size = new Size(1810, 35); + menuStrip.TabIndex = 0; + menuStrip.Text = "Меню"; + // + // GuidesToolStripMenuItem + // + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem, StartWorkingToolStripMenuItem, MailToolStripMenuItem, BackupToolStripMenuItem }); + GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; + GuidesToolStripMenuItem.Size = new Size(139, 29); + GuidesToolStripMenuItem.Text = "Справочники"; + // + // ComponentsToolStripMenuItem + // + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(272, 34); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; + // + // ManufacturesToolStripMenuItem + // + ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; + ManufacturesToolStripMenuItem.Size = new Size(272, 34); + ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; + ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; + // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(272, 34); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(272, 34); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // StartWorkingToolStripMenuItem + // + StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; + StartWorkingToolStripMenuItem.Size = new Size(272, 34); + StartWorkingToolStripMenuItem.Text = "Старт работ"; + StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; + // + // MailToolStripMenuItem + // + MailToolStripMenuItem.Name = "MailToolStripMenuItem"; + MailToolStripMenuItem.Size = new Size(272, 34); + MailToolStripMenuItem.Text = "Почта"; + MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(88, 29); + ReportsToolStripMenuItem.Text = "Отчёты"; + // + // ManufacturesListToolStripMenuItem + // + ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem"; + ManufacturesListToolStripMenuItem.Size = new Size(335, 34); + ManufacturesListToolStripMenuItem.Text = "Список кузнечных изделий"; + ManufacturesListToolStripMenuItem.Click += ManufacturesListToolStripMenuItem_Click; + // + // ManufacturesComponentsListToolStripMenuItem + // + ManufacturesComponentsListToolStripMenuItem.Name = "ManufacturesComponentsListToolStripMenuItem"; + ManufacturesComponentsListToolStripMenuItem.Size = new Size(335, 34); + ManufacturesComponentsListToolStripMenuItem.Text = "Компоненты по изделиям"; + ManufacturesComponentsListToolStripMenuItem.Click += ManufacturesComponentsListToolStripMenuItem_Click; + // + // OrdersListToolStripMenuItem + // + OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem"; + OrdersListToolStripMenuItem.Size = new Size(335, 34); + OrdersListToolStripMenuItem.Text = "Список заказов"; + OrdersListToolStripMenuItem.Click += OrdersListToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 38); + dataGridView.Margin = new Padding(4, 5, 4, 5); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(1573, 712); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1581, 45); + buttonCreateOrder.Margin = new Padding(4, 5, 4, 5); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(211, 52); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += CreateOrderButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(1581, 292); + buttonRefresh.Margin = new Padding(4, 5, 4, 5); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(211, 52); + buttonRefresh.TabIndex = 3; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonIssued + // + buttonIssued.Location = new Point(1581, 230); + buttonIssued.Margin = new Padding(4, 5, 4, 5); + buttonIssued.Name = "buttonIssued"; + buttonIssued.Size = new Size(211, 52); + buttonIssued.TabIndex = 4; + buttonIssued.Text = "Заказ выдан"; + buttonIssued.UseVisualStyleBackColor = true; + buttonIssued.Click += IssuedButton_Click; + // + // buttonReady + // + buttonReady.Location = new Point(1581, 168); + buttonReady.Margin = new Padding(4, 5, 4, 5); + buttonReady.Name = "buttonReady"; + buttonReady.Size = new Size(211, 52); + buttonReady.TabIndex = 5; + buttonReady.Text = "Заказ готов"; + buttonReady.UseVisualStyleBackColor = true; + buttonReady.Click += ReadyButton_Click; + // + // buttonTakeInWork + // + buttonTakeInWork.Location = new Point(1581, 107); + buttonTakeInWork.Margin = new Padding(4, 5, 4, 5); + buttonTakeInWork.Name = "buttonTakeInWork"; + buttonTakeInWork.Size = new Size(211, 52); + buttonTakeInWork.TabIndex = 6; + buttonTakeInWork.Text = "Отдать на выполнение"; + buttonTakeInWork.UseVisualStyleBackColor = true; + buttonTakeInWork.Click += TakeInWorkButton_Click; + // + // BackupToolStripMenuItem + // + BackupToolStripMenuItem.Name = "BackupToolStripMenuItem"; + BackupToolStripMenuItem.Size = new Size(272, 34); + BackupToolStripMenuItem.Text = "Создать бэкап"; + BackupToolStripMenuItem.Click += BackupToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1810, 750); + Controls.Add(buttonTakeInWork); + Controls.Add(buttonReady); + Controls.Add(buttonIssued); + Controls.Add(buttonRefresh); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(4, 5, 4, 5); + Name = "FormMain"; + StartPosition = FormStartPosition.CenterParent; + Text = "Кузница"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip; + private MenuStrip menuStrip; private ToolStripMenuItem GuidesToolStripMenuItem; private ToolStripMenuItem ComponentsToolStripMenuItem; private ToolStripMenuItem ManufacturesToolStripMenuItem; @@ -249,5 +257,6 @@ private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem StartWorkingToolStripMenuItem; private ToolStripMenuItem MailToolStripMenuItem; - } + private ToolStripMenuItem BackupToolStripMenuItem; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 68bee36..3790c55 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -1,5 +1,7 @@ -using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -14,222 +16,249 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, - IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } - private void ComponentsStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - 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["ManufactureId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); - if (service is FormManufactures form) - { - form.ShowDialog(); - } - } - private void CreateOrderButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private OrderBindingModel CreateBindingModel(int id, bool isDone = false) - { - return new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? String.Empty), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? String.Empty), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? String.Empty), - }; - } - private void TakeInWorkButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ReadyButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void IssuedButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); - try - { - var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ManufacturesListToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveManufacturesToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - } - private void ManufacturesComponentsListToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportManufacturesComponents)); - if (service is FormReportManufacturesComponents form) - { - form.ShowDialog(); - } - } - private void OrdersListToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } - private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(ClientsForm)); - if (service is ClientsForm form) - { - form.ShowDialog(); - } - } - private void StartWorkingToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm)); - if (service is ImplementersForm form) - { - form.ShowDialog(); - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, + IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + _backUpLogic = backUpLogic; + } + private void ComponentsStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + 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["ManufactureId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormManufactures form) + { + form.ShowDialog(); + } + } + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? String.Empty), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? String.Empty), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? String.Empty), + }; + } + private void TakeInWorkButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ReadyButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void IssuedButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ManufacturesListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveManufacturesToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + private void ManufacturesComponentsListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportManufacturesComponents form) + { + form.ShowDialog(); + } + } + private void OrdersListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is ClientsForm form) + { + form.ShowDialog(); + } + } + private void StartWorkingToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } - private void MailToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(ViewMailForm)); - if (service is ViewMailForm form) - { - form.ShowDialog(); - } - } - } + private void MailToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = DependencyManager.Instance.Resolve(); + if (service is ViewMailForm form) + { + form.ShowDialog(); + } + } + + private void BackupToolStripMenuItem_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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index 44f15f2..0eddd49 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopDataModels.Models; using Microsoft.Extensions.Logging; @@ -79,7 +80,7 @@ namespace BlacksmithWorkshop } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormManufactureComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -105,7 +106,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormManufactureComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index 98c512c..27c951a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -49,7 +50,7 @@ namespace BlacksmithWorkshop } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + var service = DependencyManager.Instance.Resolve(); if (service is FormManufacture form) { if (form.ShowDialog() == DialogResult.OK) @@ -62,7 +63,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + var service = DependencyManager.Instance.Resolve(); if (service is FormManufacture form) { var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs index 7a6934e..13e8c21 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -51,7 +52,7 @@ namespace BlacksmithWorkshop } private void CreateButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + var service = DependencyManager.Instance.Resolve(); if (service is ImplementerForm form) { if (form.ShowDialog() == DialogResult.OK) @@ -60,12 +61,12 @@ namespace BlacksmithWorkshop } } } + private void ChangeButton_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + var service = DependencyManager.Instance.Resolve(); if (service is ImplementerForm form) { form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index eba0787..6a505a2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -10,90 +10,78 @@ using NLog.Extensions.Logging; using System; using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopBusinessLogic.MailWorker; +using BlacksmithWorkshopContracts.DI; namespace BlacksmithWorkshop { - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - 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.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } - private static void MailCheck(object obj) => ServiceProvider? - .GetService()?.MailCheck(); - } -} \ No newline at end of file + internal static class Program + { + [STAThread] + static void Main() + { + 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(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => + DependencyManager.Instance.Resolve()?.MailCheck(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..42c5358 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,98 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..43c76aa --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..80ba930 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..39e5294 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index d05c6b0..ee0ccff 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -8,6 +8,7 @@ + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..1ad8778 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using BlacksmithWorkshopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..85a0b93 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..a03f310 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..15cd767 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..9c9b8f3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..db7a44b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + public static partial class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", + SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", + SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..9a11a70 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BackUpInfo.cs new file mode 100644 index 0000000..e58965a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BackUpInfo.cs @@ -0,0 +1,32 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new BlacksmithWorkshopDataBase(); + 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/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs index 4c58466..9a37306 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -15,7 +15,7 @@ namespace BlacksmithWorkshopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBaselabahelp;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBaselaba8;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DatabaseImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..7e3724d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,32 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement +{ + 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/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BackUpInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BackUpInfo.cs new file mode 100644 index 0000000..06e51ae --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BackUpInfo.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement +{ + 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/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj index 3edb6b9..2ef4d53 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..d0be183 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/ListImplementationExtension.cs @@ -0,0 +1,33 @@ +using BlacksmithWorkshopContracts.DI; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement +{ + 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(); + } + } +} -- 2.25.1 From 30232a2301ff832afa7bee859c9a3c53b88e8a4a Mon Sep 17 00:00:00 2001 From: Kristina Date: Sun, 2 Jun 2024 17:34:46 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=B7=D0=B0=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=80=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopFileImplement.csproj | 5 + .../BlacksmithWorkshopDataBase.cs | 2 +- ...BlacksmithWorkshopDatabaseImplement.csproj | 5 + .../20240602125215_InitCreate.Designer.cs | 298 ++++++++++++++++++ .../Migrations/20240602125215_InitCreate.cs | 213 +++++++++++++ 5 files changed, 522 insertions(+), 1 deletion(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.cs diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj index 1a754b4..4c0569c 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs index 9a37306..4c58466 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -15,7 +15,7 @@ namespace BlacksmithWorkshopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBaselaba8;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BlacksmithWorkshopDataBaselabahelp;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj index b6867cf..c2b0431 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj @@ -21,4 +21,9 @@ + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.Designer.cs new file mode 100644 index 0000000..36d48f5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.Designer.cs @@ -0,0 +1,298 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + [Migration("20240602125215_InitCreate")] + partial class InitCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("MessageInfos"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.cs new file mode 100644 index 0000000..78741ab --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240602125215_InitCreate.cs @@ -0,0 +1,213 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// + public partial class InitCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Manufactures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Manufactures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "ManufactureComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ManufactureId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ManufactureComponents", x => x.Id); + table.ForeignKey( + name: "FK_ManufactureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ManufactureComponents_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + ManufactureId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_Manufactures_ManufactureId", + column: x => x.ManufactureId, + principalTable: "Manufactures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ComponentId", + table: "ManufactureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ManufactureComponents_ManufactureId", + table: "ManufactureComponents", + column: "ManufactureId"); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ManufactureId", + table: "Orders", + column: "ManufactureId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ManufactureComponents"); + + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropTable( + name: "Manufactures"); + } + } +} -- 2.25.1 From 2a801a8f1392d4d191a49c6d0eada7d780fc920e Mon Sep 17 00:00:00 2001 From: Kristina Date: Sun, 2 Jun 2024 18:27:18 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20viewmodels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ClientViewModel.cs | 10 ++-- .../ViewModels/ComponentViewModel.cs | 8 +-- .../ViewModels/ImplementerViewModel.cs | 28 +++++++--- .../ViewModels/ManufactureViewModel.cs | 25 ++++++--- .../ViewModels/MessageInfoViewModel.cs | 25 +++++++-- .../ViewModels/OrderViewModel.cs | 54 ++++++++++++++----- 6 files changed, 109 insertions(+), 41 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs index bfdc6d1..5abe725 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "Client's FIO", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Login (Email)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Password", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs index 616ef51..dc09cfc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Component's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Cost", width: 100)] public double Cost { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs index 58ee191..2882272 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,27 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + //public int Id { get; set; } + //[DisplayName("ФИО исполнителя")] + //public string ImplementerFIO { get; set; } = string.Empty; + //[DisplayName("Стаж работы")] + //public int WorkExperience { get; set; } = 0; + //[DisplayName("Квалификация")] + //public int Qualification { get; set; } = 0; + //[DisplayName("Пароль")] + //public string Password { get; set; } = string.Empty; + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] - public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] + + [Column("Password", width: 150)] public string Password { get; set; } = string.Empty; + + [Column("Work expirience", width: 150)] + public int WorkExperience { get; set; } + + [Column("Qualification", width: 150)] + public int Qualification { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index 64ac3a9..447483d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,23 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ManufactureViewModel : IManufactureModel { + //public int Id { get; set; } + //[DisplayName("Название кузнечного изделия")] + //public string ManufactureName { get; set; } = string.Empty; + //[DisplayName("Цена")] + //public double Price { get; set; } + //public Dictionary ManufactureComponents + //{ + // get; + // set; + //} = new(); + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название кузнечного изделия")] + [Column("Wood's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ManufactureName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Price", width: 100)] public double Price { get; set; } - public Dictionary ManufactureComponents - { - get; - set; - } = new(); + [Column(visible: false)] + public Dictionary ManufactureComponents { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 9093103..b9989fb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,29 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + //public string MessageId { get; set; } = string.Empty; + //public int? ClientId { get; set; } + //[DisplayName("Отправитель")] + //public string SenderName { get; set; } = string.Empty; + //[DisplayName("Дата письма")] + //public DateTime DateDelivery { get; set; } + //[DisplayName("Заголовок")] + //public string Subject { get; set; } = string.Empty; + //[DisplayName("Текст")] + //public string Body { get; set; } = string.Empty; + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column("Sender", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column("Delivery Date", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column("Subject", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column("Body", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 0cd267f..efada83 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopContracts.Attributes; +using BlacksmithWorkshopDataModels.Enums; using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; @@ -11,26 +12,51 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + //[DisplayName("Номер")] + //public int Id { get; set; } + //public int? ImplementerId { get; set; } = null; + //public int ClientId { get; set; } + //[DisplayName("Клиент")] + //public string ClientFIO { get; set; } = string.Empty; + //public int ManufactureId { get; set; } + //[DisplayName("Кузнечное изделие")] + //public string ManufactureName { 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 string ImplementerFIO { get; set; } = string.Empty; + //[DisplayName("Дата создания")] + //public DateTime DateCreate { get; set; } = DateTime.Now; + //[DisplayName("Дата выполнения")] + //public DateTime? DateImplement { get; set; } + + [Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } - public int? ImplementerId { get; set; } = null; - public int ClientId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public int ManufactureId { get; set; } - [DisplayName("Кузнечное изделие")] + [Column("Wood's name", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ManufactureName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(visible: false)] + public int ClientId { get; set; } + [Column("Client's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column("Implementer's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string? ImplementerFIO { get; set; } + [Column("Count", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Sum", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Status", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Исполнитель")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Дата создания")] + [Column("Date of creation", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Date of completion", width: 100)] public DateTime? DateImplement { get; set; } } } -- 2.25.1 From 351cd7930154fe81408b9f30baf0495931341aef Mon Sep 17 00:00:00 2001 From: Kristina Date: Mon, 3 Jun 2024 15:14:13 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ImplementerViewModel.cs | 9 -------- .../ViewModels/ManufactureViewModel.cs | 10 --------- .../ViewModels/MessageInfoViewModel.cs | 11 +--------- .../ViewModels/OrderViewModel.cs | 21 ------------------- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs index 2882272..ed4be13 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -11,15 +11,6 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - //public int Id { get; set; } - //[DisplayName("ФИО исполнителя")] - //public string ImplementerFIO { get; set; } = string.Empty; - //[DisplayName("Стаж работы")] - //public int WorkExperience { get; set; } = 0; - //[DisplayName("Квалификация")] - //public int Qualification { get; set; } = 0; - //[DisplayName("Пароль")] - //public string Password { get; set; } = string.Empty; [Column(visible: false)] public int Id { get; set; } [Column("FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index 447483d..f9ac906 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -11,16 +11,6 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ManufactureViewModel : IManufactureModel { - //public int Id { get; set; } - //[DisplayName("Название кузнечного изделия")] - //public string ManufactureName { get; set; } = string.Empty; - //[DisplayName("Цена")] - //public double Price { get; set; } - //public Dictionary ManufactureComponents - //{ - // get; - // set; - //} = new(); [Column(visible: false)] public int Id { get; set; } [Column("Wood's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs index b9989fb..14b30d2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -11,16 +11,7 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - //public string MessageId { get; set; } = string.Empty; - //public int? ClientId { get; set; } - //[DisplayName("Отправитель")] - //public string SenderName { get; set; } = string.Empty; - //[DisplayName("Дата письма")] - //public DateTime DateDelivery { get; set; } - //[DisplayName("Заголовок")] - //public string Subject { get; set; } = string.Empty; - //[DisplayName("Текст")] - //public string Body { get; set; } = string.Empty; + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; [Column(visible: false)] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index efada83..fa283d7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -12,27 +12,6 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class OrderViewModel : IOrderModel { - //[DisplayName("Номер")] - //public int Id { get; set; } - //public int? ImplementerId { get; set; } = null; - //public int ClientId { get; set; } - //[DisplayName("Клиент")] - //public string ClientFIO { get; set; } = string.Empty; - //public int ManufactureId { get; set; } - //[DisplayName("Кузнечное изделие")] - //public string ManufactureName { 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 string ImplementerFIO { get; set; } = string.Empty; - //[DisplayName("Дата создания")] - //public DateTime DateCreate { get; set; } = DateTime.Now; - //[DisplayName("Дата выполнения")] - //public DateTime? DateImplement { get; set; } [Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } -- 2.25.1