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/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj index 4b96496..b0eee31 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -1,14 +1,18 @@  - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - + + + + + + + + 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/BlackcmithWorkshopFileImplement/Models/Client.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Client.cs index e4f3e5f..083746b 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Client.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Client.cs @@ -4,18 +4,24 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs index e7a419c..7bd026e 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs @@ -4,17 +4,22 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; set; } - public string ComponentName { get; set; } = string.Empty; - public double Cost { get; set; } + [DataMember] + public int Id { get; set; } + [DataMember] + public string ComponentName { get; set; } = string.Empty; + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { if (model == null) diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs index 241bebf..1071c1b 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs @@ -4,19 +4,26 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int Qualification { get; set; } = 0; - public int WorkExperience { get; set; } = 0; + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public int Qualification { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; public static Implementer? Create(ImplementerBindingModel model) { if (model == null) diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs index 7d42aa5..10d4778 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs @@ -5,19 +5,25 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class Manufacture : IManufactureModel + [DataContract] + public class Manufacture : IManufactureModel { - public int Id { get; private set; } - public string ManufactureName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ManufactureName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); - private Dictionary? _ManufactureComponents = null; + private Dictionary? _ManufactureComponents = null; + [DataMember] public Dictionary ManufactureComponents { get diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/MessageInfo.cs index f487570..14df40a 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/MessageInfo.cs @@ -4,21 +4,30 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class MessageInfo : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; - public static MessageInfo? Create(MessageInfoBindingModel model) + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) { @@ -67,5 +76,5 @@ namespace BlacksmithWorkshopFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + } } diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs index 98b409b..8fbe085 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs @@ -5,23 +5,34 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace BlacksmithWorkshopFileImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int ManufactureId { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } = null; - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } - public DateTime? DateImplement { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public int ManufactureId { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } = null; + [DataMember] + public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } + [DataMember] + public DateTime DateCreate { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ClientsForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ClientsForm.cs index 9c72412..e6cf692 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ClientsForm.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ClientsForm.cs @@ -27,15 +27,7 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/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..7c639ea 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; @@ -32,14 +33,7 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -51,8 +45,8 @@ namespace BlacksmithWorkshop } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -64,9 +58,8 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponent form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); @@ -76,7 +69,6 @@ namespace BlacksmithWorkshop } } } - } private void DeleteButton_Click(object sender, EventArgs e) { @@ -107,7 +99,6 @@ namespace BlacksmithWorkshop } } } - } private void RefreshButton_Click(object sender, EventArgs e) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 08ad4c8..52b95c0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -20,208 +20,216 @@ 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.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1267, 24); - menuStrip.TabIndex = 0; - menuStrip.Text = "Меню"; - // - // GuidesToolStripMenuItem - // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem, StartWorkingToolStripMenuItem, MailToolStripMenuItem }); - GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; - GuidesToolStripMenuItem.Size = new Size(94, 20); - GuidesToolStripMenuItem.Text = "Справочники"; - // - // ComponentsToolStripMenuItem - // - ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(181, 22); - ComponentsToolStripMenuItem.Text = "Компоненты"; - ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; - // - // ManufacturesToolStripMenuItem - // - ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(181, 22); - ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; - ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; - // - // ClientsToolStripMenuItem - // - ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(181, 22); - ClientsToolStripMenuItem.Text = "Клиенты"; - ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // ImplementersToolStripMenuItem - // - ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; - ImplementersToolStripMenuItem.Size = new Size(181, 22); - ImplementersToolStripMenuItem.Text = "Исполнители"; - ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; - // - // StartWorkingToolStripMenuItem - // - StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; - StartWorkingToolStripMenuItem.Size = new Size(181, 22); - StartWorkingToolStripMenuItem.Text = "Старт работ"; - StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; - // - // ReportsToolStripMenuItem - // - ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); - ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; - ReportsToolStripMenuItem.Size = new Size(60, 20); - ReportsToolStripMenuItem.Text = "Отчёты"; - // - // ManufacturesListToolStripMenuItem - // - ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem"; - ManufacturesListToolStripMenuItem.Size = new Size(225, 22); - ManufacturesListToolStripMenuItem.Text = "Список кузнечных изделий"; - ManufacturesListToolStripMenuItem.Click += ManufacturesListToolStripMenuItem_Click; - // - // ManufacturesComponentsListToolStripMenuItem - // - ManufacturesComponentsListToolStripMenuItem.Name = "ManufacturesComponentsListToolStripMenuItem"; - ManufacturesComponentsListToolStripMenuItem.Size = new Size(225, 22); - ManufacturesComponentsListToolStripMenuItem.Text = "Компоненты по изделиям"; - ManufacturesComponentsListToolStripMenuItem.Click += ManufacturesComponentsListToolStripMenuItem_Click; - // - // OrdersListToolStripMenuItem - // - OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem"; - OrdersListToolStripMenuItem.Size = new Size(225, 22); - OrdersListToolStripMenuItem.Text = "Список заказов"; - OrdersListToolStripMenuItem.Click += OrdersListToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 23); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(1101, 427); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(1107, 27); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(148, 31); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += CreateOrderButton_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(1107, 175); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(148, 31); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += RefreshButton_Click; - // - // buttonIssued - // - buttonIssued.Location = new Point(1107, 138); - buttonIssued.Name = "buttonIssued"; - buttonIssued.Size = new Size(148, 31); - buttonIssued.TabIndex = 4; - buttonIssued.Text = "Заказ выдан"; - buttonIssued.UseVisualStyleBackColor = true; - buttonIssued.Click += IssuedButton_Click; - // - // buttonReady - // - buttonReady.Location = new Point(1107, 101); - buttonReady.Name = "buttonReady"; - buttonReady.Size = new Size(148, 31); - buttonReady.TabIndex = 5; - buttonReady.Text = "Заказ готов"; - buttonReady.UseVisualStyleBackColor = true; - buttonReady.Click += ReadyButton_Click; - // - // buttonTakeInWork - // - buttonTakeInWork.Location = new Point(1107, 64); - buttonTakeInWork.Name = "buttonTakeInWork"; - buttonTakeInWork.Size = new Size(148, 31); - buttonTakeInWork.TabIndex = 6; - buttonTakeInWork.Text = "Отдать на выполнение"; - buttonTakeInWork.UseVisualStyleBackColor = true; - buttonTakeInWork.Click += TakeInWorkButton_Click; - // - // MailToolStripMenuItem - // - MailToolStripMenuItem.Name = "MailToolStripMenuItem"; - MailToolStripMenuItem.Size = new Size(181, 22); - MailToolStripMenuItem.Text = "Почта"; - MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1267, 450); - Controls.Add(buttonTakeInWork); - Controls.Add(buttonReady); - Controls.Add(buttonIssued); - Controls.Add(buttonRefresh); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - 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.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1267, 24); + 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(94, 20); + GuidesToolStripMenuItem.Text = "Справочники"; + // + // ComponentsToolStripMenuItem + // + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(181, 22); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; + // + // ManufacturesToolStripMenuItem + // + ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; + ManufacturesToolStripMenuItem.Size = new Size(181, 22); + ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; + ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; + // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(181, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(181, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // StartWorkingToolStripMenuItem + // + StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; + StartWorkingToolStripMenuItem.Size = new Size(181, 22); + StartWorkingToolStripMenuItem.Text = "Старт работ"; + StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; + // + // MailToolStripMenuItem + // + MailToolStripMenuItem.Name = "MailToolStripMenuItem"; + MailToolStripMenuItem.Size = new Size(181, 22); + MailToolStripMenuItem.Text = "Почта"; + MailToolStripMenuItem.Click += MailToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(60, 20); + ReportsToolStripMenuItem.Text = "Отчёты"; + // + // ManufacturesListToolStripMenuItem + // + ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem"; + ManufacturesListToolStripMenuItem.Size = new Size(225, 22); + ManufacturesListToolStripMenuItem.Text = "Список кузнечных изделий"; + ManufacturesListToolStripMenuItem.Click += ManufacturesListToolStripMenuItem_Click; + // + // ManufacturesComponentsListToolStripMenuItem + // + ManufacturesComponentsListToolStripMenuItem.Name = "ManufacturesComponentsListToolStripMenuItem"; + ManufacturesComponentsListToolStripMenuItem.Size = new Size(225, 22); + ManufacturesComponentsListToolStripMenuItem.Text = "Компоненты по изделиям"; + ManufacturesComponentsListToolStripMenuItem.Click += ManufacturesComponentsListToolStripMenuItem_Click; + // + // OrdersListToolStripMenuItem + // + OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem"; + OrdersListToolStripMenuItem.Size = new Size(225, 22); + OrdersListToolStripMenuItem.Text = "Список заказов"; + OrdersListToolStripMenuItem.Click += OrdersListToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 23); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(1101, 427); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1107, 27); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(148, 31); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += CreateOrderButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(1107, 175); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(148, 31); + buttonRefresh.TabIndex = 3; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonIssued + // + buttonIssued.Location = new Point(1107, 138); + buttonIssued.Name = "buttonIssued"; + buttonIssued.Size = new Size(148, 31); + buttonIssued.TabIndex = 4; + buttonIssued.Text = "Заказ выдан"; + buttonIssued.UseVisualStyleBackColor = true; + buttonIssued.Click += IssuedButton_Click; + // + // buttonReady + // + buttonReady.Location = new Point(1107, 101); + buttonReady.Name = "buttonReady"; + buttonReady.Size = new Size(148, 31); + buttonReady.TabIndex = 5; + buttonReady.Text = "Заказ готов"; + buttonReady.UseVisualStyleBackColor = true; + buttonReady.Click += ReadyButton_Click; + // + // buttonTakeInWork + // + buttonTakeInWork.Location = new Point(1107, 64); + buttonTakeInWork.Name = "buttonTakeInWork"; + buttonTakeInWork.Size = new Size(148, 31); + buttonTakeInWork.TabIndex = 6; + buttonTakeInWork.Text = "Отдать на выполнение"; + buttonTakeInWork.UseVisualStyleBackColor = true; + buttonTakeInWork.Click += TakeInWorkButton_Click; + // + // BackupToolStripMenuItem + // + BackupToolStripMenuItem.Name = "BackupToolStripMenuItem"; + BackupToolStripMenuItem.Size = new Size(181, 22); + BackupToolStripMenuItem.Text = "Создать бэкап"; + BackupToolStripMenuItem.Click += BackupToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1267, 450); + Controls.Add(buttonTakeInWork); + Controls.Add(buttonReady); + Controls.Add(buttonIssued); + Controls.Add(buttonRefresh); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + 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; @@ -239,5 +247,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 18de462..6e8d5c5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -14,221 +15,237 @@ 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(); - } - } - private void MailToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(ViewMailForm)); - if (service is ViewMailForm 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 + { + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _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 = 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..8938138 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,8 +80,8 @@ namespace BlacksmithWorkshop } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); - if (service is FormManufactureComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormManufactureComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -105,8 +106,8 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); - if (service is FormManufactureComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormManufactureComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index 98c512c..a10f395 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; @@ -31,14 +32,7 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ManufactureComponents"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка кузнечных изделий"); } catch (Exception ex) @@ -49,8 +43,8 @@ namespace BlacksmithWorkshop } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); - if (service is FormManufacture form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormManufacture form) { if (form.ShowDialog() == DialogResult.OK) { @@ -62,8 +56,8 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); - if (service is FormManufacture form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormManufacture form) { var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs index e16ad69..2e084bd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs @@ -22,96 +22,90 @@ #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() - { - dataGridView = new DataGridView(); - CreateButton = new Button(); - ChangeButton = new Button(); - DeleteButton = new Button(); - RefreshButton = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(10, 9); - dataGridView.Margin = new Padding(3, 2, 3, 2); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(494, 320); - dataGridView.TabIndex = 0; - // - // CreateButton - // - CreateButton.Location = new Point(510, 9); - CreateButton.Margin = new Padding(3, 2, 3, 2); - CreateButton.Name = "CreateButton"; - CreateButton.Size = new Size(179, 22); - CreateButton.TabIndex = 1; - CreateButton.Text = "Создать"; - CreateButton.UseVisualStyleBackColor = true; - CreateButton.Click += CreateButton_Click; - // - // ChangeButton - // - ChangeButton.Location = new Point(510, 35); - ChangeButton.Margin = new Padding(3, 2, 3, 2); - ChangeButton.Name = "ChangeButton"; - ChangeButton.Size = new Size(179, 22); - ChangeButton.TabIndex = 2; - ChangeButton.Text = "Изменить"; - ChangeButton.UseVisualStyleBackColor = true; - ChangeButton.Click += ChangeButton_Click; - // - // DeleteButton - // - DeleteButton.Location = new Point(510, 62); - DeleteButton.Margin = new Padding(3, 2, 3, 2); - DeleteButton.Name = "DeleteButton"; - DeleteButton.Size = new Size(179, 22); - DeleteButton.TabIndex = 3; - DeleteButton.Text = "Удалить"; - DeleteButton.UseVisualStyleBackColor = true; - DeleteButton.Click += DeleteButton_Click; - // - // RefreshButton - // - RefreshButton.Location = new Point(510, 88); - RefreshButton.Margin = new Padding(3, 2, 3, 2); - RefreshButton.Name = "RefreshButton"; - RefreshButton.Size = new Size(179, 22); - RefreshButton.TabIndex = 4; - RefreshButton.Text = "Обновить"; - RefreshButton.UseVisualStyleBackColor = true; - RefreshButton.Click += RefreshButton_Click; - // - // ImplementersForm - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(700, 338); - Controls.Add(RefreshButton); - Controls.Add(DeleteButton); - Controls.Add(ChangeButton); - Controls.Add(CreateButton); - Controls.Add(dataGridView); - Margin = new Padding(3, 2, 3, 2); - Name = "ImplementersForm"; - Text = "Исполнители"; - Load += ImplementersForm_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + CreateButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView1"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(565, 426); + dataGridView.TabIndex = 0; + // + // CreateButton + // + CreateButton.Location = new Point(583, 12); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(205, 29); + CreateButton.TabIndex = 1; + CreateButton.Text = "Создать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += CreateButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(583, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(205, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(583, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(205, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(583, 117); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(205, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // ImplementersForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(CreateButton); + Controls.Add(dataGridView); + Name = "ImplementersForm"; + Text = "Исполнители"; + Load += ImplementersForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } #endregion - private DataGridView dataGridView; + private DataGridView dataGridView; private Button CreateButton; private Button ChangeButton; private Button DeleteButton; diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs index 56272d1..bd57232 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; @@ -31,17 +32,8 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) { @@ -51,8 +43,8 @@ namespace BlacksmithWorkshop } private void CreateButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); - if (service is ImplementerForm form) + var service = DependencyManager.Instance.Resolve(); + if (service is ImplementerForm form) { if (form.ShowDialog() == DialogResult.OK) { @@ -64,9 +56,8 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(ImplementerForm)); - if (service is ImplementerForm form) + var service = DependencyManager.Instance.Resolve(); + if (service is ImplementerForm form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 8f98da0..eaa35d2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -10,90 +10,78 @@ using NLog.Extensions.Logging; using System; using BlacksmithWorkshopBusinessLogic.MailWorker; using BlacksmithWorkshopContracts.BindingModels; +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(); - } + 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(); + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs index 04ab472..b04b21c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs @@ -26,15 +26,8 @@ namespace BlacksmithWorkshop { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка списка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/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/BindingModels/MessageInfoBindingModel .cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel .cs index 6073666..f15ba6d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/MessageInfoBindingModel .cs @@ -15,5 +15,6 @@ namespace BlacksmithWorkshopContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id => throw new NotImplementedException(); + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj index f685e06..c3ccda5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -6,6 +6,10 @@ enable + + + + 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/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ClientViewModel.cs index bfdc6d1..a19750c 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,14 @@ namespace BlacksmithWorkshopContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Email клиента", gridViewAutoSize: GridViewAutoSize.Fill, + isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", 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..7ed3660 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 { - public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } - } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column(title: "Цена", width: 80)] + public double Cost { get; set; } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs index 58ee191..75f0d99 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,18 @@ 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(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, + isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public int WorkExperience { get; set; } = 0; + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public int Qualification { get; set; } = 0; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs index 64ac3a9..f952553 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,12 +11,15 @@ 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 + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название кузнечного изделия", gridViewAutoSize: GridViewAutoSize.Fill, + isUseAutoSize: true)] + public string ManufactureName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary ManufactureComponents { get; set; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 9093103..cab0b9a 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,21 @@ 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; } + [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, + isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; + [Column(title: "Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, + isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 0cd267f..ac74dd8 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,35 @@ 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("Кузнечное изделие")] + [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public int Id { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } = null; + [Column(visible: false)] + public int ClientId { get; set; } + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, + isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int ManufactureId { get; set; } + [Column(title: "Кузнечное изделие", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] 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("Исполнитель")] + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public int Count { get; set; } + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public double Sum { get; set; } + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.AllCells, + isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Исполнитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs index e25db0d..524dbcf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } 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/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj index 1cd795d..a045cf9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj @@ -1,23 +1,27 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + - - - - + + + + + + + + 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/BlacksmithWorkshopDatabaseImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs index 9ab918f..f7bb33e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs @@ -8,18 +8,24 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; [Required] - public string Email { get; set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); [ForeignKey("ClientId")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs index cbb7bd8..1d88131 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs @@ -6,18 +6,23 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public string ComponentName { get; private set; } = string.Empty; [Required] - public double Cost { get; set; } + [DataMember] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List ManufactureComponents { get; set; } = new(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs index 7d07cf7..763f78a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs @@ -8,20 +8,27 @@ using System.Threading.Tasks; using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopDatabaseImplement.Models; using BlacksmithWorkshopContracts.ViewModels; +using System.Runtime.Serialization; namespace BlacksmithWorkshopDataModels.Models { - public class Implementer : IImplementerModel - { - public int Id { get; private set; } + [DataContract] + public class Implementer : IImplementerModel + { + [DataMember] + public int Id { get; private set; } [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; [Required] - public int Qualification { get; set; } = 0; + [DataMember] + public int Qualification { get; set; } = 0; [Required] - public int WorkExperience { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; [ForeignKey("ImplementerId")] public virtual List Orders { get; set; } = new(); public static Implementer? Create(ImplementerBindingModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs index 24f00be..57603e9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs @@ -6,22 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class Manufacture : IManufactureModel - { - public int Id { get; set; } + [DataContract] + public class Manufacture : IManufactureModel + { + [DataMember] + public int Id { get; set; } [Required] - public string ManufactureName { get; set; } = string.Empty; + [DataMember] + public string ManufactureName { get; set; } = string.Empty; [Required] - public double Price { get; set; } + [DataMember] + public double Price { get; set; } private Dictionary? _manufactureComponents = null; [NotMapped] - public Dictionary ManufactureComponents + [DataMember] + public Dictionary ManufactureComponents { get { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs index 261a1e9..524758c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -4,23 +4,34 @@ using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public Client? Client { get; private set; } - public static MessageInfo? Create(BlacksmithWorkshopDataBase context, MessageInfoBindingModel model) + [NotMapped] + public int Id => throw new NotImplementedException(); + public static MessageInfo? Create(BlacksmithWorkshopDataBase context, MessageInfoBindingModel model) { if (model == null) { @@ -46,5 +57,5 @@ namespace BlacksmithWorkshopDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 852f053..89395c3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -6,30 +6,41 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace BlacksmithWorkshopDatabaseImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } [Required] - public int ClientId { get; private set; } + [DataMember] + public int ClientId { get; private set; } public virtual Client Client { get; private set; } [Required] - public int Count { get; private set; } + [DataMember] + public int Count { get; private set; } [Required] - public double Sum { get; private set; } + [DataMember] + public double Sum { get; private set; } [Required] - public OrderStatus Status { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } [Required] - public DateTime DateCreate { get; private set; } - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime DateCreate { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } [Required] - public int ManufactureId { get; private set; } + [DataMember] + public int ManufactureId { get; private set; } public virtual Manufacture? Manufacture { get; set; } - public int? ImplementerId { get; private set; } = null; + [DataMember] + public int? ImplementerId { get; private set; } = null; public virtual Implementer? Implementer { get; private set; } public static Order Create(OrderBindingModel model) 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 b65badc..9b97e8e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -1,14 +1,18 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - + + + + + + + + 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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs index e20590b..3bf762d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/MessageInfo.cs @@ -17,7 +17,8 @@ namespace BlacksmithWorkshopListImplement.Models public DateTime DateDelivery { get; private set; } = DateTime.Now; public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; - public static MessageInfo? Create(MessageInfoBindingModel model) + public int Id => throw new NotImplementedException(); + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) { @@ -42,5 +43,5 @@ namespace BlacksmithWorkshopListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + } }