From 63fef77d35baf4b228ae7f560cbeaf176af2a60a Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Apr 2023 21:40:26 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201.=20=D0=A2?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D0=B9=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataGridViewExtension.cs | 51 +++++++++++++++++++ .../FurnitureAssembly/FormClients.cs | 15 ++---- .../FurnitureAssembly/FormComponents.cs | 12 ++--- .../FurnitureAssembly/FormFurnitures.cs | 13 ++--- .../FurnitureAssembly/FormImplementers.cs | 12 ++--- .../FurnitureAssembly/FormMail.cs | 12 ++--- .../FurnitureAssembly/FormMain.cs | 9 +--- .../Attributes/ColumnAttribute.cs | 24 +++++++++ .../Attributes/GridViewAutoSize.cs | 14 +++++ .../ViewModels/ClientViewModel.cs | 11 ++-- .../ViewModels/ComponentViewModel.cs | 15 +++--- .../ViewModels/FurnitureViewModel.cs | 10 ++-- .../ViewModels/ImplementerViewModel.cs | 15 +++--- .../ViewModels/MessageInfoViewModel.cs | 18 ++++--- .../ViewModels/OrderViewModel.cs | 25 +++++---- 15 files changed, 155 insertions(+), 101 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs diff --git a/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs new file mode 100644 index 0000000..6952f2e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using FurnitureAssemblyContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssembly +{ + 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/FurnitureAssembly/FurnitureAssembly/FormClients.cs b/FurnitureAssembly/FurnitureAssembly/FormClients.cs index 1d18bca..c293ba3 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormClients.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormClients.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using Microsoft.Extensions.Logging; @@ -24,17 +25,7 @@ namespace FurnitureAssembly { 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"].Visible = false; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormComponents.cs b/FurnitureAssembly/FurnitureAssembly/FormComponents.cs index ea435f5..1c1e4db 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormComponents.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormComponents.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using Microsoft.Extensions.Logging; using System; @@ -34,14 +35,7 @@ namespace FurnitureAssembly { 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) diff --git a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs index ad82020..0d33300 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using Microsoft.Extensions.Logging; using System; @@ -33,15 +34,7 @@ namespace FurnitureAssembly { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["FurnitureName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["FurnitureComponents"].Visible = false; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs index df5aa63..2d177cf 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using Microsoft.Extensions.Logging; @@ -25,14 +26,7 @@ namespace FurnitureAssembly { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.cs index fd2afdb..52c8e9e 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMail.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; using Microsoft.Extensions.Logging; using System.Windows.Forms; @@ -20,14 +21,7 @@ namespace FurnitureAssembly { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewMail.DataSource = list; - dataGridViewMail.Columns["ClientId"].Visible = false; - dataGridViewMail.Columns["MessageId"].Visible = false; - dataGridViewMail.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewMail.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 21806d5..d47b0eb 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -36,14 +36,7 @@ namespace FurnitureAssembly { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["FurnitureId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..f453606 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,24 @@ +using System; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..722d1bb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace FurnitureAssemblyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs index 76344c0..585f75c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ClientViewModel.cs @@ -1,17 +1,18 @@ -using FurnitureAssemblyDataModels.Models; -using System.ComponentModel; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; namespace FurnitureAssemblyContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true )] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs index 516ff28..88c8df3 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs @@ -1,19 +1,16 @@ -using FurnitureAssemblyDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; + namespace FurnitureAssemblyContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Cost { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs index ea144c1..9dd4ce6 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs @@ -1,7 +1,7 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,11 +10,13 @@ namespace FurnitureAssemblyContracts.ViewModels { public class FurnitureViewModel : IFurnitureModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string FurnitureName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Price { get; set; } + [Column(visible: false)] public Dictionary FurnitureComponents{ get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs index 198964e..3d0e32a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs @@ -1,7 +1,7 @@ -using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,15 +9,16 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel - { + { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Опыт работы")] + [Column(title: "Опыт работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 98b85aa..5a90aac 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -1,20 +1,22 @@ -using FurnitureAssemblyDataModels.Models; -using System.ComponentModel; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; + namespace FurnitureAssemblyContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Заголовок", width: 170)] + public string Subject { get; set; } = string.Empty; + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index f2fb1e3..f8ff5de 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -1,8 +1,8 @@ -using FurnitureAssemblyDataModels.Enums; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Enums; using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,26 +11,29 @@ namespace FurnitureAssemblyContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 50)] public int Id { get; set; } + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("Клиент")] + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public int FurnitureId { get; set; } - [DisplayName("Изделие")] + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string FurnitureName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? ImplementerFIO { get; set; } = string.Empty; } } -- 2.25.1 From a5df575dab8337b752ea871646469cf04137f814 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Apr 2023 23:57:23 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=91?= =?UTF-8?q?=D1=8D=D0=BA=D0=B0=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BackUpInfo.cs | 30 ++++++ .../Models/Client.cs | 9 +- .../Models/Component.cs | 5 + .../Models/Furniture.cs | 8 +- .../Models/Implementer.cs | 10 +- .../Models/MessageInfo.cs | 15 ++- .../Models/Order.cs | 20 ++-- .../FurnitureAssembly/FormMain.Designer.cs | 12 ++- .../FurnitureAssembly/FormMain.cs | 29 +++++- .../FurnitureAssembly/Program.cs | 3 + .../BackUpLogic.cs | 97 +++++++++++++++++++ .../BindingModels/BackUpSaveBinidngModel.cs | 7 ++ .../BindingModels/MessageInfoBindingModel.cs | 2 + .../BusinessLogicsContarcts/IBackUpLogic.cs | 9 ++ .../StoragesContracts/IBackUpInfo.cs | 8 ++ .../ViewModels/MessageInfoViewModel.cs | 2 + .../Models/IMessageInfoModel.cs | 2 +- .../Implements/BackUpInfo.cs | 26 +++++ .../Models/Client.cs | 6 ++ .../Models/Component.cs | 5 + .../Models/Furniture.cs | 6 ++ .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 14 ++- .../Models/Order.cs | 13 ++- .../Models/MessageInfo.cs | 2 + 25 files changed, 316 insertions(+), 31 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5ffab2c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyContracts.StoragesContracts; +using System.Reflection; + +namespace FurnitureAssemFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + DataFileSingleton dataFileSingleton = DataFileSingleton.GetInstance(); + return (List?) dataFileSingleton.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))? + .GetValue(dataFileSingleton); + } + + 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/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs index d7b6e6a..31c39d2 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Client.cs @@ -4,20 +4,23 @@ using FurnitureAssemblyDataModels.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 FurnitureAssemFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ClientFIO { get; private set; } = string.Empty; - + [DataMember] public string Email { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs index ce0dbca..1a81bf5 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs @@ -1,14 +1,19 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs index 6689a82..f4a1d80 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs @@ -1,17 +1,23 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Furniture : IFurnitureModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string FurnitureName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _furnitureComponents = null; + [DataMember] public Dictionary FurnitureComponents { get diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs index b0071be..11327f5 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Implementer.cs @@ -1,19 +1,23 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs index f051bf3..0e20dae 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs @@ -1,22 +1,25 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [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 static MessageInfo? Create(MessageInfoBindingModel model) @@ -71,5 +74,7 @@ namespace FurnitureAssemFileImplement.Models new XElement("Body", Body), new XElement("Subject", Subject) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs index 7e92e6e..8e86daf 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs @@ -7,32 +7,34 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int FurnitureId { get; private set; } - public string FurnitureName { get; private set; } = string.Empty; - + [DataMember] public int Count { get; private set; } - + [DataMember] public double Sum { get; private set; } - + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; - + [DataMember] public DateTime? DateImplement { get; private set; } - + [DataMember] public int Id { get; private set; } - + [DataMember] public int ClientId { get; private set; } - + [DataMember] public int? ImplementerId { get; private set; } = null; public static Order? Create(OrderBindingModel? model) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 2087b46..3de3ff0 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -44,6 +44,7 @@ this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mailToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.CreateBackUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -93,7 +94,8 @@ this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.doWorkToolStripMenuItem, - this.mailToolStripMenuItem}); + this.mailToolStripMenuItem, + this.CreateBackUpToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1065, 24); @@ -184,6 +186,13 @@ this.mailToolStripMenuItem.Text = "Письма"; this.mailToolStripMenuItem.Click += new System.EventHandler(this.mailToolStripMenuItem_Click); // + // CreateBackUpToolStripMenuItem + // + this.CreateBackUpToolStripMenuItem.Name = "CreateBackUpToolStripMenuItem"; + this.CreateBackUpToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.CreateBackUpToolStripMenuItem.Text = "Создать Бэкап"; + this.CreateBackUpToolStripMenuItem.Click += new System.EventHandler(this.CreateBackUpToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -224,5 +233,6 @@ private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem; private ToolStripMenuItem mailToolStripMenuItem; + private ToolStripMenuItem CreateBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index d47b0eb..902d9be 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -20,13 +20,15 @@ namespace FurnitureAssembly private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workModeling; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workModeling = workModeling; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -221,5 +223,30 @@ namespace FurnitureAssembly form.ShowDialog(); } } + + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 775c796..10c4b47 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -74,6 +74,8 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); @@ -85,6 +87,7 @@ namespace FurnitureAssembly services.AddTransient(); services.AddSingleton(); + services.AddTransient(); services.AddTransient(); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..ef5ed08 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BackUpLogic.cs @@ -0,0 +1,97 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace FurnitureAssemblyBusinessLogic +{ + 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/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..23320f7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace FurnitureAssemblyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs index 10e611a..d96f499 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace FurnitureAssemblyContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs new file mode 100644 index 0000000..c0f25b3 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using FurnitureAssemblyContracts.BindingModels; + +namespace FurnitureAssemblyContracts.BusinessLogicsContarcts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..f770812 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace FurnitureAssemblyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 5a90aac..659ffda 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -18,5 +18,7 @@ namespace FurnitureAssemblyContracts.ViewModels public string Subject { get; set; } = string.Empty; [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs index 6139889..b8eb1b3 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ namespace FurnitureAssemblyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..e2bf4b8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,26 @@ +using FurnitureAssemblyContracts.StoragesContracts; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new FurnitureAssemblyDatabase(); + 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/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs index bfc1dc9..c6aee58 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Client.cs @@ -3,17 +3,23 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs index 1ec3c8a..73634d2 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs @@ -4,15 +4,20 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List FurnitureComponents { get; set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index 992dc97..ffdfe7d 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -6,20 +6,26 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Furniture : IFurnitureModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string FurnitureName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _furnitureComponents = null; [NotMapped] + [DataMember] public Dictionary FurnitureComponents { get diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs index ba2ad20..f52fcab 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs @@ -3,19 +3,26 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; private set; } [Required] + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs index 291789b..c3dd42e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs @@ -2,22 +2,25 @@ using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; - + [DataMember] public int? ClientId { get; private set; } - + [DataMember] public string SenderName { get; private set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; - + [DataMember] public string Subject { get; private set; } = string.Empty; - + [DataMember] public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; private set; } @@ -49,5 +52,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models DateDelivery = DateDelivery, }; + public int Id => throw new NotImplementedException(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index 5f8782f..7e541b1 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -8,32 +8,41 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int FurnitureId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; - + [DataMember] public DateTime? DateImplement { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } public virtual Client Client { get; set; } - + [DataMember] public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs index 332bb9f..8888064 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs @@ -44,5 +44,7 @@ namespace FurnitureAssemblyListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } -- 2.25.1 From 76fce8f0361578ced5f3564960144e7300625e13 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Apr 2023 11:06:54 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../FileImplementationExtension.cs | 22 +++++ .../FurnitureAssemFileImplement.csproj | 4 + .../FurnitureAssembly/FormComponents.cs | 25 ++--- .../FurnitureAssembly/FormFurniture.cs | 44 +++++---- .../FurnitureAssembly/FormFurnitures.cs | 27 +++--- .../FurnitureAssembly/FormImplementers.cs | 27 +++--- .../FurnitureAssembly/FormMain.cs | 76 ++++++---------- .../FurnitureAssembly/Program.cs | 91 ++++++++----------- .../DI/DependencyManager.cs | 64 +++++++++++++ .../DI/IDependencyContainer.cs | 34 +++++++ .../DI/IImplementationExtension.cs | 11 +++ .../DI/ServiceDependencyContainer.cs | 57 ++++++++++++ .../DI/ServiceProviderLoader.cs | 52 +++++++++++ .../DI/UnityDependencyContainer.cs | 52 +++++++++++ .../FurnitureAssemblyContracts.csproj | 2 + .../DatabaseImplementationExtension.cs | 22 +++++ .../FurnitureAssemblyDatabaseImplement.csproj | 4 + .../FurnitureAssemblyListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 18 ++++ .../ListImplementationExtension.cs | 22 +++++ 21 files changed, 494 insertions(+), 165 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..a299f6f 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +*.dll diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..075b27f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemFileImplement.Implements; + +namespace FurnitureAssemFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj b/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj index c0fa55b..23d6782 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssembly/FormComponents.cs b/FurnitureAssembly/FurnitureAssembly/FormComponents.cs index 1c1e4db..866fef7 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormComponents.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormComponents.cs @@ -1,6 +1,7 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -48,31 +49,25 @@ namespace FurnitureAssembly private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs b/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs index a089a15..44b96df 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormFurniture.cs @@ -1,5 +1,6 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyDataModels.Models; using Microsoft.Extensions.Logging; @@ -86,38 +87,35 @@ namespace FurnitureAssembly private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormFurnitureComponent)); - if (service is FormFurnitureComponent form) - { - if (form.ShowDialog() == DialogResult.OK) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); - if (_productComponents.ContainsKey(form.Id)) - { - _productComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _productComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _productComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); } + } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridViewFurn.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormFurnitureComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormFurnitureComponent form) { int id = diff --git a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs index 0d33300..0dc8ce0 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormFurnitures.cs @@ -1,6 +1,7 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -47,31 +48,27 @@ namespace FurnitureAssembly private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormFurniture)); - if (service is FormFurniture form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormFurniture)); - if (service is FormFurniture form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs index 2d177cf..336405b 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs @@ -1,6 +1,7 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; @@ -39,31 +40,27 @@ namespace FurnitureAssembly private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 902d9be..668ddce 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -1,6 +1,7 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -50,32 +51,27 @@ namespace FurnitureAssembly } private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormFurnitures)); - if (service is FormFurnitures form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + LoadData(); + } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { @@ -173,55 +169,43 @@ namespace FurnitureAssembly private void FurnitureComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportFurnitureComponents)); - if (service is FormReportFurnitureComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); } private void ClientsMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); } private void doWorkToolStripMenuItem_Click(object sender, EventArgs e) { _workModeling.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); } private void mailToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); - if (service is FormMail form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 10c4b47..e0382ce 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -2,20 +2,16 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyBusinessLogic.OfficePackage.Implements; using FurnitureAssemblyBusinessLogic.OfficePackage; using FurnitureAssemblyContracts.BusinessLogicsContarcts; -using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemblyDatabaseImplement.Implements; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using FurnitureAssemblyBusinessLogic.MailWorker; using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.DI; namespace FurnitureAssembly { internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + { /// /// The main entry point for the application. /// @@ -25,13 +21,11 @@ namespace FurnitureAssembly // 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(); + InitDependency(); + try { - var mailSender = - _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = @@ -54,61 +48,56 @@ namespace FurnitureAssembly } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + + + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(true); - services.AddSingleton(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - - 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..6b99863 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs @@ -0,0 +1,64 @@ +using Microsoft.Extensions.Logging; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..e0fbe35 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.Logging; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..0878428 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,11 @@ +namespace FurnitureAssemblyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..cebccbe --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace FurnitureAssemblyContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..6778099 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,52 @@ +using System.Reflection; + +namespace FurnitureAssemblyContracts.DI +{ + public static partial class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", + SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", + SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..6425937 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace FurnitureAssemblyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer container; + + public UnityDependencyContainer() + { + container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + // регистрируем логгер в контейнере + var factory = LoggerFactory.Create(configure); + container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + container.RegisterSingleton(); + } + else + { + container.RegisterType(); + } + } + + public T Resolve() + { + return container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + if (isSingle) + { + container.RegisterSingleton(); + } + else + { + container.RegisterType(); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj index f9f8ab4..ee3530e 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj +++ b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj @@ -11,6 +11,8 @@ + + diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..1364576 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDatabaseImplement.Implements; + +namespace FurnitureAssemblyDatabaseImplement +{ + 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/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj index a46e4e9..171cdd5 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj index 5081f9c..d932e5c 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..b099c9c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,18 @@ +using FurnitureAssemblyContracts.StoragesContracts; + + +namespace FurnitureAssemblyListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..8f39b42 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using FurnitureAssemblyContracts.DI; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyListImplement.Implements; + +namespace FurnitureAssemblyListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} -- 2.25.1 From e7941ff84cdbc8344ac0593ad80b106fddd65bd3 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Apr 2023 12:14:24 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileImplementationExtension.cs | 1 + .../Models/Shop.cs | 10 ++++- .../FurnitureAssembly/FormMail.cs | 14 +++--- .../FurnitureAssembly/FormMain.cs | 45 +++++++++---------- .../FurnitureAssembly/FormShops.cs | 35 ++++++--------- .../ViewModels/ShopViewModel.cs | 18 +++----- .../DatabaseImplementationExtension.cs | 1 + .../Models/Shop.cs | 9 +++- .../ListImplementationExtension.cs | 1 + .../Models/Shop.cs | 12 +++-- 10 files changed, 74 insertions(+), 72 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs index 075b27f..47adf83 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/FileImplementationExtension.cs @@ -17,6 +17,7 @@ namespace FurnitureAssemFileImplement DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } } } diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Shop.cs index aeb1cc6..50264ba 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Shop.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Shop.cs @@ -3,19 +3,24 @@ using FurnitureAssemblyDataModels.Models; using FurnitureAssemblyContracts.ViewModels; using System.Xml.Linq; using System.Diagnostics; +using System.Runtime.Serialization; namespace FurnitureAssemFileImplement.Models { + [DataContract] public class Shop : IShopModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ShopName { get; private set; } = string.Empty; - + [DataMember] public string Address { get; private set; } = string.Empty; - + [DataMember] public DateTime DateOpening { get; private set; } private Dictionary? _furnitures = null; + [DataMember] public Dictionary Furnitures { get @@ -32,6 +37,7 @@ namespace FurnitureAssemFileImplement.Models } private set { } } + [DataMember] public int MaxCount { get; private set; } public Dictionary CurrentCount { get; private set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.cs index 7603b3d..39475a4 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMail.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.cs @@ -1,5 +1,6 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; using System.Windows.Forms; @@ -82,15 +83,14 @@ namespace FurnitureAssembly { if (dataGridViewMail.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormOneMail)); - if (service is FormOneMail form) + var form = DependencyManager.Instance.Resolve(); + + form.MessageId = (string)dataGridViewMail.SelectedRows[0].Cells["MessageId"].Value; + if (form.ShowDialog() == DialogResult.OK) { - form.MessageId = (string)dataGridViewMail.SelectedRows[0].Cells["MessageId"].Value; - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index d511d53..cceadd2 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -157,29 +157,26 @@ namespace FurnitureAssembly private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void ReplenishmentToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReplenishmentShop)); - if (service is FormReplenishmentShop form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void buttonSell_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSell)); - if (service is FormSell form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void FurnituresToolStripMenuItem_Click(object sender, EventArgs @@ -227,20 +224,18 @@ namespace FurnitureAssembly private void ShopsFurnituresToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportShopFurnitures)); - if (service is FormReportShopFurnitures form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void OrderDateToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportCountOrdersByPeriod)); - if (service is FormReportCountOrdersByPeriod form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + + form.ShowDialog(); + } private void ClientsMenuItem_Click(object sender, EventArgs e) diff --git a/FurnitureAssembly/FurnitureAssembly/FormShops.cs b/FurnitureAssembly/FurnitureAssembly/FormShops.cs index 65487cc..34490c3 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormShops.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.cs @@ -1,5 +1,6 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; using Microsoft.Extensions.Logging; @@ -19,14 +20,13 @@ namespace FurnitureAssembly private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void FormShops_Load(object sender, EventArgs e) @@ -38,14 +38,7 @@ namespace FurnitureAssembly { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Furnitures"].Visible = false; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) @@ -60,16 +53,14 @@ namespace FurnitureAssembly { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index 37982f1..c4e811e 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -1,25 +1,21 @@ -using FurnitureAssemblyDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using FurnitureAssemblyContracts.Attributes; +using FurnitureAssemblyDataModels.Models; + namespace FurnitureAssemblyContracts.ViewModels { public class ShopViewModel : IShopModel { public int Id { get; set; } - [DisplayName("Название магазина")] + [Column(title: "Название магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес магазина")] + [Column(title: "Адрес магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public string Address { get; set; } = string.Empty; - [DisplayName("Дата открытия")] + [Column(title: "Дата открытия", width: 100)] public DateTime DateOpening { get; set; } public Dictionary Furnitures { get; set; } = new(); - [DisplayName("Вместимость")] + [Column(title: "Вместимость", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public int MaxCount { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs index 1364576..ae2a8ae 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/DatabaseImplementationExtension.cs @@ -17,6 +17,7 @@ namespace FurnitureAssemblyDatabaseImplement DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs index c3fe6ac..5e37c33 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs @@ -7,23 +7,30 @@ 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 FurnitureAssemblyDatabaseImplement.Models { + [DataContract] public class Shop : IShopModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ShopName { get; private set; } = string.Empty; [Required] + [DataMember] public string Address { get; private set; } = string.Empty; [Required] + [DataMember] public DateTime DateOpening { get; private set; } private Dictionary? _furnitures = null; [NotMapped] + [DataMember] public Dictionary Furnitures { get @@ -39,7 +46,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models } private set { } } - + [DataMember] public int MaxCount { get; private set; } [ForeignKey("ShopId")] diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs index 8f39b42..d518656 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/ListImplementationExtension.cs @@ -17,6 +17,7 @@ namespace FurnitureAssemblyListImplement DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs index 1a73183..3a0b438 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs @@ -5,22 +5,26 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace FurnitureAssemblyListImplement.Models { + [DataContract] public class Shop : IShopModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ShopName { get; private set; } = string.Empty; - + [DataMember] public string Address { get; private set; } = string.Empty; - + [DataMember] public DateTime DateOpening { get; private set; } - + [DataMember] public Dictionary Furnitures { get; private set; } = new(); - + [DataMember] public int MaxCount { get; private set; } public static Shop? Create(ShopBindingModel? model) -- 2.25.1 From 11bd076201e1ec2a63b8d21fb1d8923e5d2d4737 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Apr 2023 12:20:37 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201.=20=D0=A4?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BA=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/DataGridViewExtension.cs | 4 ++++ .../Attributes/ColumnAttribute.cs | 8 +++++++- .../ViewModels/ComponentViewModel.cs | 2 +- .../ViewModels/FurnitureViewModel.cs | 2 +- .../ViewModels/MessageInfoViewModel.cs | 6 +++--- .../ViewModels/OrderViewModel.cs | 6 +++--- .../ViewModels/ShopViewModel.cs | 2 +- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs index 6952f2e..7a53b7a 100644 --- a/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs +++ b/FurnitureAssembly/FurnitureAssembly/DataGridViewExtension.cs @@ -44,6 +44,10 @@ namespace FurnitureAssembly { column.Width = columnAttr.Width; } + if (columnAttr.IsFormatable) + { + column.DefaultCellStyle.Format = columnAttr.Formatter; + } } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs index f453606..8e7aab7 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; namespace FurnitureAssemblyContracts.Attributes { @@ -7,18 +8,23 @@ namespace FurnitureAssemblyContracts.Attributes { public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool - isUseAutoSize = false) + isUseAutoSize = false, bool isFormatable = false, string? formatter = null) { Title = title; Visible = visible; Width = width; GridViewAutoSize = gridViewAutoSize; IsUseAutoSize = isUseAutoSize; + IsFormatable = isFormatable; + Formatter = formatter; + } 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; } + public bool IsFormatable { get; private set; } + public string? Formatter { get; private set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs index 88c8df3..144db76 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs @@ -10,7 +10,7 @@ namespace FurnitureAssemblyContracts.ViewModels public int Id { get; set; } [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [Column(title: "Цена", width: 70)] + [Column(title: "Цена", width: 70, isFormatable: true, formatter: "0.00##")] public double Cost { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs index 9dd4ce6..3f7355a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs @@ -14,7 +14,7 @@ namespace FurnitureAssemblyContracts.ViewModels public int Id { get; set; } [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string FurnitureName { get; set; } = string.Empty; - [Column(title: "Цена", width: 70)] + [Column(title: "Цена", width: 70, isFormatable: true, formatter: "0.00##")] public double Price { get; set; } [Column(visible: false)] public Dictionary FurnitureComponents{ get; set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 2723ba9..e92813a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -12,15 +12,15 @@ namespace FurnitureAssemblyContracts.ViewModels public int? ClientId { get; set; } [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [Column(title: "Дата письма", width: 100)] + [Column(title: "Дата письма", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] public DateTime DateDelivery { get; set; } [Column(title: "Заголовок", width: 170)] public string Subject { get; set; } = string.Empty; [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; - [DisplayName("Прочитано")] + [Column(title: "Прочитано", width: 10)] public bool IsRead { get; set; } - [DisplayName("Ответ")] + [Column(title: "Ответ", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? Reply { get; set; } public int Id => throw new NotImplementedException(); diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index f8ff5de..a353a4f 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -23,13 +23,13 @@ namespace FurnitureAssemblyContracts.ViewModels public string FurnitureName { get; set; } = string.Empty; [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public int Count { get; set; } - [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true, isFormatable: true, formatter: "0.00##")] public double Sum { get; set; } [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Column(title: "Дата создания", width: 100)] + [Column(title: "Дата создания", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] public DateTime DateCreate { get; set; } = DateTime.Now; - [Column(title: "Дата выполнения", width: 100)] + [Column(title: "Дата выполнения", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] public DateTime? DateImplement { get; set; } [Column(visible: false)] public int? ImplementerId { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index c4e811e..8157048 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -11,7 +11,7 @@ namespace FurnitureAssemblyContracts.ViewModels public string ShopName { get; set; } = string.Empty; [Column(title: "Адрес магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public string Address { get; set; } = string.Empty; - [Column(title: "Дата открытия", width: 100)] + [Column(title: "Дата открытия", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] public DateTime DateOpening { get; set; } public Dictionary Furnitures { get; set; } = new(); -- 2.25.1 From 34d42994eab9740cfb1d3f24ed4b261ce6cc650b Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Apr 2023 14:54:27 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?(=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/Program.cs | 16 ------- .../BusinessLogicImplementationExtension.cs | 39 +++++++++++++++ .../FurnitureAssemblyBusinessLogic.csproj | 4 ++ .../DI/DependencyManager.cs | 9 +++- .../IImplementationBusinessLogicExtension.cs | 6 +++ .../DI/ServiceProviderLoader.cs | 47 +++++++++++++++++++ .../ViewModels/ShopViewModel.cs | 1 + 7 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 0c9d8bc..1e2e879 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -67,22 +67,6 @@ namespace FurnitureAssembly option.AddNLog("nlog.config"); }); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - - DependencyManager.Instance.RegisterType(true); - - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs new file mode 100644 index 0000000..eae3a4f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs @@ -0,0 +1,39 @@ +using FurnitureAssemblyBusinessLogic.MailWorker; +using FurnitureAssemblyBusinessLogic.OfficePackage.Implements; +using FurnitureAssemblyBusinessLogic.OfficePackage; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.DI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic +{ + public class BusinessLogicImplementationExtension : IImplementationBusinessLogicExtension + { + public int Priority => 3; + + public void RegisterServices() + { + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj index 92c1d36..b2c7842 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs index 6b99863..6be1b4c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs @@ -28,10 +28,17 @@ namespace FurnitureAssemblyContracts.DI var ext = ServiceProviderLoader.GetImplementationExtensions(); if (ext == null) { - throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (хранилище)"); } // регистрируем зависимости ext.RegisterServices(); + + var extBL = ServiceProviderLoader.GetImplementationBusinessLogicExtensions(); + if (extBL == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (бизнес-логика)"); + } + extBL.RegisterServices(); } /// /// Регистрация логгера diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..084a213 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs @@ -0,0 +1,6 @@ +namespace FurnitureAssemblyContracts.DI +{ + public interface IImplementationBusinessLogicExtension : IImplementationExtension + { + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs index 6778099..a1ec41c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs @@ -48,5 +48,52 @@ namespace FurnitureAssemblyContracts.DI } return $"{directory?.FullName}\\ImplementationExtensions"; } + + /// + /// Загрузка всех классов-реализаций IImplementationBLExtension (бизнес-логика) + /// + /// + public static IImplementationBusinessLogicExtension? GetImplementationBusinessLogicExtensions() + { + IImplementationBusinessLogicExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationBLExtensionsFolder(), "*.dll", + SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationBusinessLogicExtension).IsAssignableFrom(t)) + { + + if (source == null) + { + source = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + + } + } + } + return source; + } + private static string TryGetImplementationBLExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationBLExtensions", + SearchOption.AllDirectories).Any(x => x.Name == "ImplementationBLExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationBLExtensions"; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index 8157048..3a99152 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -6,6 +6,7 @@ namespace FurnitureAssemblyContracts.ViewModels { public class ShopViewModel : IShopModel { + [Column(visible:false)] public int Id { get; set; } [Column(title: "Название магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public string ShopName { get; set; } = string.Empty; -- 2.25.1 From 3893b69ece48a3c7a69849b82350da08744251ab Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Fri, 5 May 2023 10:35:44 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B0=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=BE=20Id?= =?UTF-8?q?=20(MessageInfo)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/MessageInfoViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 659ffda..3416cec 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -18,7 +18,7 @@ namespace FurnitureAssemblyContracts.ViewModels 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(); } } -- 2.25.1 From e2746c2043b5eba8caf528b461c89101588d1010 Mon Sep 17 00:00:00 2001 From: pgirl1 Date: Mon, 24 Apr 2023 10:06:31 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/ColumnAttribute.cs | 9 ++++----- .../ViewModels/ComponentViewModel.cs | 2 +- .../ViewModels/FurnitureViewModel.cs | 2 +- .../ViewModels/MessageInfoViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 6 +++--- .../ViewModels/ShopViewModel.cs | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs index 8e7aab7..b4c48ee 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/Attributes/ColumnAttribute.cs @@ -8,14 +8,13 @@ namespace FurnitureAssemblyContracts.Attributes { public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool - isUseAutoSize = false, bool isFormatable = false, string? formatter = null) + isUseAutoSize = false, string formatter = "") { Title = title; Visible = visible; Width = width; GridViewAutoSize = gridViewAutoSize; - IsUseAutoSize = isUseAutoSize; - IsFormatable = isFormatable; + IsUseAutoSize = isUseAutoSize; Formatter = formatter; } @@ -24,7 +23,7 @@ namespace FurnitureAssemblyContracts.Attributes public int Width { get; private set; } public GridViewAutoSize GridViewAutoSize { get; private set; } public bool IsUseAutoSize { get; private set; } - public bool IsFormatable { get; private set; } - public string? Formatter { get; private set; } + public bool IsFormatable => !string.IsNullOrEmpty(Formatter) ; + public string Formatter { get; private set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs index 144db76..2ff8290 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ComponentViewModel.cs @@ -10,7 +10,7 @@ namespace FurnitureAssemblyContracts.ViewModels public int Id { get; set; } [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [Column(title: "Цена", width: 70, isFormatable: true, formatter: "0.00##")] + [Column(title: "Цена", width: 70, formatter: "0.00##")] public double Cost { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs index 3f7355a..8809904 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureViewModel.cs @@ -14,7 +14,7 @@ namespace FurnitureAssemblyContracts.ViewModels public int Id { get; set; } [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string FurnitureName { get; set; } = string.Empty; - [Column(title: "Цена", width: 70, isFormatable: true, formatter: "0.00##")] + [Column(title: "Цена", width: 70, formatter: "0.00##")] public double Price { get; set; } [Column(visible: false)] public Dictionary FurnitureComponents{ get; set; } = new(); diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 2127267..4aa0065 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -12,7 +12,7 @@ namespace FurnitureAssemblyContracts.ViewModels public int? ClientId { get; set; } [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [Column(title: "Дата письма", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] + [Column(title: "Дата письма", width: 100, formatter: "dd/MM/yyyy")] public DateTime DateDelivery { get; set; } [Column(title: "Заголовок", width: 170)] public string Subject { get; set; } = string.Empty; diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index a353a4f..a2c6768 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -23,13 +23,13 @@ namespace FurnitureAssemblyContracts.ViewModels public string FurnitureName { get; set; } = string.Empty; [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public int Count { get; set; } - [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true, isFormatable: true, formatter: "0.00##")] + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true, formatter: "0.00##")] public double Sum { get; set; } [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Column(title: "Дата создания", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] + [Column(title: "Дата создания", width: 100, formatter: "dd/MM/yyyy")] public DateTime DateCreate { get; set; } = DateTime.Now; - [Column(title: "Дата выполнения", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] + [Column(title: "Дата выполнения", width: 100, formatter: "dd/MM/yyyy")] public DateTime? DateImplement { get; set; } [Column(visible: false)] public int? ImplementerId { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index 9075b41..9b7c400 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -13,7 +13,7 @@ namespace FurnitureAssemblyContracts.ViewModels public string ShopName { get; set; } = string.Empty; [Column(title: "Адрес магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)] public string Address { get; set; } = string.Empty; - [Column(title: "Дата открытия", width: 100, isFormatable: true, formatter: "dd/MM/yyyy")] + [Column(title: "Дата открытия", width: 100, formatter: "dd/MM/yyyy")] public DateTime DateOpening { get; set; } [JsonIgnore] public Dictionary Furnitures { get; set; } = new(); -- 2.25.1