From c26b883fa1a714841bf05f73de381abef7b54f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sat, 18 May 2024 23:30:39 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D1=85=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 --- .../Attributes/ColumnAttribute.cs | 26 ++++++++++++ .../Attributes/GridViewAutoSize.cs | 27 ++++++++++++ .../BindingModels/MessageInfoBindingModel.cs | 2 + .../ViewModels/ClientViewModel.cs | 9 ++-- .../ViewModels/ComponentViewModel.cs | 7 ++-- .../ViewModels/ImplementerViewModel.cs | 13 +++--- .../ViewModels/MessageInfoViewModel.cs | 16 ++++--- .../ViewModels/OrderViewModel.cs | 23 +++++----- .../ViewModels/RepairViewModel.cs | 8 ++-- .../Models/IMessageInfoModel.cs | 2 +- .../Models/MessageInfo.cs | 2 + .../Models/MessageInfo.cs | 2 + .../Models/MessageInfo.cs | 2 + .../DataGridViewExtension.cs | 42 +++++++++++++++++++ .../CarRepairShopView/FormClients.cs | 8 +--- .../CarRepairShopView/FormComponents.cs | 8 +--- .../CarRepairShopView/FormImplementers.cs | 8 +--- .../CarRepairShopView/FormLetters.cs | 8 +--- .../CarRepairShopView/FormMain.Designer.cs | 28 ++++++------- CarRepairShop/CarRepairShopView/FormMain.cs | 9 +--- .../CarRepairShopView/FormRepairs.cs | 9 +--- 21 files changed, 168 insertions(+), 91 deletions(-) create mode 100644 CarRepairShop/CarRepairShopContracts/Attributes/ColumnAttribute.cs create mode 100644 CarRepairShop/CarRepairShopContracts/Attributes/GridViewAutoSize.cs create mode 100644 CarRepairShop/CarRepairShopView/DataGridViewExtension.cs diff --git a/CarRepairShop/CarRepairShopContracts/Attributes/ColumnAttribute.cs b/CarRepairShop/CarRepairShopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..4ea4ea5 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/Attributes/GridViewAutoSize.cs b/CarRepairShop/CarRepairShopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..64de1d8 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs index c78da34..847d674 100644 --- a/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace CarRepairShopContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs index 3141e26..0bc8205 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs @@ -1,7 +1,7 @@ using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,15 +10,16 @@ namespace CarRepairShopContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title:"ФИО клиента", width:150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title:"Логин (эл.почта)", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title:"Пароль", width:150)] public string Password { get; set; } = string.Empty; } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs index c7c54ef..012858e 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ComponentViewModel.cs @@ -1,7 +1,7 @@ using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,12 +10,13 @@ namespace CarRepairShopContracts.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:150)] public double Cost { get; set; } } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs index c6c2c19..770ca13 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs @@ -1,7 +1,7 @@ using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,18 +10,19 @@ namespace CarRepairShopContracts.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: "Опыт работы", width: 150)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 150)] public int Qualification { get; set; } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs index 6c4745a..8cd2fe8 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,7 +1,7 @@ using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,20 +10,24 @@ namespace CarRepairShopContracts.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: "Почта отправителя", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата получения")] + [Column(title: "Дата получения", width: 150)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст письма")] + [Column(title: "Текст письма", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string Body { get; set; } = string.Empty; + + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs index e886296..c6c039e 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -3,7 +3,7 @@ using CarRepairShopDataModels.Enums; using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,35 +12,38 @@ namespace CarRepairShopContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 50)] public int Id { get; set; } + [Column(visible: false)] public int RepairId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", gridViewAutoSize:GridViewAutoSize.Fill, isUseAutoSize:true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Ремонт")] + [Column(title: "Ремонт", width: 100)] public string RepairName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 80)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 100)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 120)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 110)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs index ee30f01..01d349a 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/RepairViewModel.cs @@ -1,7 +1,7 @@ using CarRepairShopDataModels.Models; using System; using System.Collections.Generic; -using System.ComponentModel; +using CarRepairShopContracts.Attributes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,14 +10,16 @@ namespace CarRepairShopContracts.ViewModels { public class RepairViewModel : IRepairModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("Название ремонта")] + [Column(title: "Название ремонта", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string RepairName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Price { get; set; } + [Column(visible: false)] public Dictionary RepairComponents { get; set; } = new(); } } diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs index 8d85ee6..854e1a7 100644 --- a/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs +++ b/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace CarRepairShopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs index c5a83c4..e895e14 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs @@ -51,5 +51,7 @@ namespace CarRepairShopDatabaseImplement.Models Subject = Subject, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs index bd25770..7c93ff7 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs @@ -70,5 +70,7 @@ namespace CarRepairShopFileImplement.Models new XElement("Subject", Subject), new XElement("Body", Body), new XElement("SenderName", SenderName)); + + public int Id => throw new NotImplementedException(); } } diff --git a/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs index 8e0d346..9bb98c6 100644 --- a/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs +++ b/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs @@ -46,5 +46,7 @@ namespace CarRepairShopListImplement.Models Subject = Subject, Body = Body, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/CarRepairShop/CarRepairShopView/DataGridViewExtension.cs b/CarRepairShop/CarRepairShopView/DataGridViewExtension.cs new file mode 100644 index 0000000..a02cf86 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/DataGridViewExtension.cs @@ -0,0 +1,42 @@ +using CarRepairShopContracts.Attributes; + + +namespace CarRepairShopView +{ + 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/CarRepairShop/CarRepairShopView/FormClients.cs b/CarRepairShop/CarRepairShopView/FormClients.cs index 949de5d..7c5cab8 100644 --- a/CarRepairShop/CarRepairShopView/FormClients.cs +++ b/CarRepairShop/CarRepairShopView/FormClients.cs @@ -34,13 +34,7 @@ namespace CarRepairShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/CarRepairShop/CarRepairShopView/FormComponents.cs b/CarRepairShop/CarRepairShopView/FormComponents.cs index 5a9f1c6..1f99507 100644 --- a/CarRepairShop/CarRepairShopView/FormComponents.cs +++ b/CarRepairShop/CarRepairShopView/FormComponents.cs @@ -32,13 +32,7 @@ namespace CarRepairShopView { 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/CarRepairShop/CarRepairShopView/FormImplementers.cs b/CarRepairShop/CarRepairShopView/FormImplementers.cs index 5b05e68..1e50c79 100644 --- a/CarRepairShop/CarRepairShopView/FormImplementers.cs +++ b/CarRepairShop/CarRepairShopView/FormImplementers.cs @@ -27,13 +27,7 @@ namespace CarRepairShopView { 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/CarRepairShop/CarRepairShopView/FormLetters.cs b/CarRepairShop/CarRepairShopView/FormLetters.cs index 76929e9..bcd43ee 100644 --- a/CarRepairShop/CarRepairShopView/FormLetters.cs +++ b/CarRepairShop/CarRepairShopView/FormLetters.cs @@ -27,13 +27,7 @@ namespace CarRepairShopView private void FormLetters_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка писем"); - var list = _logic.ReadList(null); - if(list != null ) - { - dataGridView.DataSource = list; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); } } } diff --git a/CarRepairShop/CarRepairShopView/FormMain.Designer.cs b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs index 5c0b4bb..38733e1 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.Designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs @@ -39,11 +39,11 @@ ClientsToolStripMenuItem = new ToolStripMenuItem(); workStartToolStripMenuItem = new ToolStripMenuItem(); implementersToolStripMenuItem = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - почтаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -53,7 +53,7 @@ menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ClientsToolStripMenuItem, workStartToolStripMenuItem, implementersToolStripMenuItem, почтаToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1059, 24); + menuStrip1.Size = new Size(1256, 24); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // @@ -127,6 +127,13 @@ implementersToolStripMenuItem.Text = "Исполнители"; implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(53, 20); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + // // dataGridView // dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; @@ -139,13 +146,13 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(827, 349); + dataGridView.Size = new Size(1024, 398); dataGridView.TabIndex = 1; // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.Location = new Point(844, 54); + buttonCreateOrder.Location = new Point(1041, 54); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(198, 28); buttonCreateOrder.TabIndex = 2; @@ -156,7 +163,7 @@ // buttonIssuedOrder // buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.Location = new Point(844, 109); + buttonIssuedOrder.Location = new Point(1041, 109); buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Size = new Size(198, 28); buttonIssuedOrder.TabIndex = 5; @@ -167,7 +174,7 @@ // buttonRef // buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.Location = new Point(844, 164); + buttonRef.Location = new Point(1041, 164); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(198, 28); buttonRef.TabIndex = 6; @@ -175,18 +182,11 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // - // почтаToolStripMenuItem - // - почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - почтаToolStripMenuItem.Size = new Size(53, 20); - почтаToolStripMenuItem.Text = "Почта"; - почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1059, 377); + ClientSize = new Size(1256, 426); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); Controls.Add(buttonCreateOrder); diff --git a/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index 541b841..4f7cfb2 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -37,14 +37,7 @@ namespace CarRepairShopView private void LoadData() { _logger.LogInformation("Загрузка заказов"); - var _list = _orderLogic.ReadList(null); - if (_list != null) - { - dataGridView.DataSource = _list; - dataGridView.Columns["RepairId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - } + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/CarRepairShop/CarRepairShopView/FormRepairs.cs b/CarRepairShop/CarRepairShopView/FormRepairs.cs index 2d75929..24282e0 100644 --- a/CarRepairShop/CarRepairShopView/FormRepairs.cs +++ b/CarRepairShop/CarRepairShopView/FormRepairs.cs @@ -33,14 +33,7 @@ namespace CarRepairShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["RepairComponents"].Visible = false; - dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка ремонта"); } catch (Exception ex) -- 2.25.1 From d2845480705b747499f2a7890e9c46c1b785664c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sun, 19 May 2024 00:27:15 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B0?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82=D1=8B=20=D0=B2=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/BackUpSaveBindingModel.cs | 13 ++++++++ .../BusinessLogicsContracts/IBackUpLogic.cs | 9 ++++++ .../StoragesContracts/IBackUpInfo.cs | 14 ++++++++ .../Implements/BackUpInfo.cs | 31 ++++++++++++++++++ .../Models/Client.cs | 6 ++++ .../Models/Component.cs | 5 +++ .../Models/Implementer.cs | 7 ++++ .../Models/MessageInfo.cs | 9 +++++- .../Models/Order.cs | 13 ++++++-- .../Models/Repair.cs | 6 ++++ .../Implements/BackUpInfo.cs | 32 +++++++++++++++++++ .../Models/Client.cs | 6 ++++ .../Models/Component.cs | 6 +++- .../Models/Implementer.cs | 11 ++++--- .../Models/MessageInfo.cs | 13 +++++--- .../Models/Order.cs | 11 +++++++ .../Models/Repair.cs | 6 ++++ 17 files changed, 185 insertions(+), 13 deletions(-) create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/BackUpSaveBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/Implements/BackUpInfo.cs diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/BackUpSaveBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..5fa1a83 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..04f9806 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using CarRepairShopContracts.BindingModels; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IBackUpInfo.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..1bb9dc8 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/BackUpInfo.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f59cfa0 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,31 @@ +using CarRepairShopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new CarRepairShopDatabase(); + 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/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs index 25869b7..fc65fae 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs @@ -6,22 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarRepairShopDatabaseImplement.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/CarRepairShop/CarRepairShopDatabaseImplement/Models/Component.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Component.cs index 5a48894..0395aae 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Component.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Component.cs @@ -6,19 +6,24 @@ 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 CarRepairShopDatabaseImplement.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")] diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs index 6d393ed..82d50cf 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs @@ -9,25 +9,32 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarRepairShopDatabaseImplement.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/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs index e895e14..5cf00d0 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs @@ -5,25 +5,32 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarRepairShopDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; set; } = string.Empty; - + [DataMember] public int? ClientId { get; set; } [Required] + [DataMember] public string SenderName { get; set; } = string.Empty; [Required] + [DataMember] public DateTime DateDelivery { get; set; } [Required] + [DataMember] public string Subject { get; set; } = string.Empty; [Required] + [DataMember] public string Body { get; set; } = string.Empty; public virtual Client Client { get; private set; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs index bb30b00..c8c9c48 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs @@ -6,35 +6,44 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarRepairShopDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public int RepairId { get; set; } [Required] + [DataMember] public int ClientId { get; set; } - + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; set; } [Required] + [DataMember] public double Sum { get; set; } [Required] + [DataMember] public OrderStatus Status { get; set; } [Required] + [DataMember] public DateTime DateCreate { get; set; } - + [DataMember] public DateTime? DateImplement { get; set; } public virtual Repair Repair { get; set; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs index 26349fb..58be49a 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs @@ -7,24 +7,30 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarRepairShopDatabaseImplement.Models { + [DataContract] public class Repair : IRepairModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string RepairName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _repairComponents = null; [NotMapped] + [DataMember] public Dictionary RepairComponents { get diff --git a/CarRepairShop/CarRepairShopFileImplement/Implements/BackUpInfo.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..6191f4c --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using CarRepairShopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties().FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs index 50091d9..a7753e8 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs @@ -4,17 +4,23 @@ using CarRepairShopDataModels.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 CarRepairShopFileImplement.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/CarRepairShop/CarRepairShopFileImplement/Models/Component.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Component.cs index c000e83..487db9b 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Component.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Component.cs @@ -4,17 +4,21 @@ using CarRepairShopDataModels.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 CarRepairShopFileImplement.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/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs index e679ef1..37ab77d 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs @@ -5,22 +5,25 @@ using DocumentFormat.OpenXml.Spreadsheet; 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 CarRepairShopFileImplement.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/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs index 7c93ff7..9e20e6e 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs @@ -4,24 +4,27 @@ using CarRepairShopDataModels.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 CarRepairShopFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; set; } = string.Empty; - + [DataMember] public int? ClientId { get; set; } - + [DataMember] public string SenderName { get; set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; set; } - + [DataMember] public string Subject { get; set; } = string.Empty; - + [DataMember] public string Body { get; set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel? model) diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs index 0ef4a5a..577a59c 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs @@ -5,22 +5,33 @@ using CarRepairShopDataModels.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 CarRepairShopFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int RepairId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; set; } + [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; } public virtual Repair Repair { get; set; } diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Repair.cs index 97cc984..8575cc8 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Repair.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Repair.cs @@ -5,19 +5,25 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarRepairShopFileImplement.Models { + [DataContract] public class Repair : IRepairModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string RepairName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _repairComponents = null; + [DataMember] public Dictionary RepairComponents { get -- 2.25.1 From 59c04ccfa3c3d5507e3022c232ff885961b685d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sun, 19 May 2024 01:10:58 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B1=D0=B5=D0=BA=D0=B0=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/BackUpLogic.cs | 97 +++++++++++++++++++ .../CarRepairShopView/FormMain.Designer.cs | 11 ++- CarRepairShop/CarRepairShopView/FormMain.cs | 27 +++++- CarRepairShop/CarRepairShopView/Program.cs | 2 + 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/BackUpLogic.cs diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/BackUpLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..ed6411b --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,97 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopDataModels; +using DocumentFormat.OpenXml.Office.CustomUI; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBindingModel 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 + { + 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/CarRepairShop/CarRepairShopView/FormMain.Designer.cs b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs index 38733e1..cc5f4d2 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.Designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs @@ -44,13 +44,14 @@ buttonCreateOrder = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); + CreateBackUpToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ClientsToolStripMenuItem, workStartToolStripMenuItem, implementersToolStripMenuItem, почтаToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ClientsToolStripMenuItem, workStartToolStripMenuItem, implementersToolStripMenuItem, почтаToolStripMenuItem, CreateBackUpToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1256, 24); @@ -182,6 +183,13 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // + // CreateBackUpToolStripMenuItem + // + CreateBackUpToolStripMenuItem.Name = "CreateBackUpToolStripMenuItem"; + CreateBackUpToolStripMenuItem.Size = new Size(97, 20); + CreateBackUpToolStripMenuItem.Text = "Создать бекап"; + CreateBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -221,5 +229,6 @@ private ToolStripMenuItem workStartToolStripMenuItem; private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem CreateBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index 4f7cfb2..0372400 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -20,13 +20,15 @@ namespace CarRepairShopView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -215,5 +217,28 @@ namespace CarRepairShopView 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 BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index 0dc5a85..0f5b4f7 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -67,6 +67,7 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -75,6 +76,7 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddSingleton(); -- 2.25.1 From 717bcbc5b51c79620667985de180abfddbaf2fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sun, 19 May 2024 15:47:14 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=85=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC=20=D0=BD=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=B7=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ca1c7a3..d32f1fd 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/CarRepairShop/ImplementationExtensions -- 2.25.1 From 81ba4173fbdb23851e93d7d6d76d75673c12d703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sun, 19 May 2024 15:47:43 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=85=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC=20=D0=BD=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=B7=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShopContracts.csproj | 6 ++ .../DI/DependencyManager.cs | 34 +++++++ .../DI/IDependencyContainer.cs | 13 +++ .../DI/IImplementationExtension.cs | 14 +++ .../DI/ServiceProviderLoader.cs | 51 +++++++++++ .../DI/UnityDependencyContainer.cs | 55 ++++++++++++ .../CarRepairShopDatabaseImplement.csproj | 4 + .../DatabaseImplementationExtension.cs | 27 ++++++ .../CarRepairShopFileImplement.csproj | 4 + .../FileImplementationExtension.cs | 27 ++++++ .../CarRepairShopListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 22 +++++ .../ListImplementationExtension.cs | 27 ++++++ .../CarRepairShopView/FormComponents.cs | 23 +++-- .../CarRepairShopView/FormImplementers.cs | 21 ++--- CarRepairShop/CarRepairShopView/FormMain.cs | 66 +++++--------- CarRepairShop/CarRepairShopView/FormRepair.cs | 56 ++++++------ .../CarRepairShopView/FormRepairs.cs | 21 ++--- CarRepairShop/CarRepairShopView/Program.cs | 88 ++++++++----------- 19 files changed, 402 insertions(+), 161 deletions(-) create mode 100644 CarRepairShop/CarRepairShopContracts/DI/DependencyManager.cs create mode 100644 CarRepairShop/CarRepairShopContracts/DI/IDependencyContainer.cs create mode 100644 CarRepairShop/CarRepairShopContracts/DI/IImplementationExtension.cs create mode 100644 CarRepairShop/CarRepairShopContracts/DI/ServiceProviderLoader.cs create mode 100644 CarRepairShop/CarRepairShopContracts/DI/UnityDependencyContainer.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/FileImplementationExtension.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/BackUpInfo.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/ListImplementationExtension.cs diff --git a/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj index 215400f..38d69ae 100644 --- a/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj +++ b/CarRepairShop/CarRepairShopContracts/CarRepairShopContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/CarRepairShop/CarRepairShopContracts/DI/DependencyManager.cs b/CarRepairShop/CarRepairShopContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..1b3ccbe --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/DI/DependencyManager.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.Logging; + +namespace CarRepairShopContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + private static DependencyManager? _manager; + private static readonly object _lockObject = new(); + private DependencyManager() + { + _dependencyManager = new UnityDependencyContainer(); + } + public static DependencyManager Instance { get { if (_manager == null) { lock (_lockObject) { _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/CarRepairShop/CarRepairShopContracts/DI/IDependencyContainer.cs b/CarRepairShop/CarRepairShopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..84c55c5 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.Logging; + + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/DI/IImplementationExtension.cs b/CarRepairShop/CarRepairShopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..2444219 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/DI/ServiceProviderLoader.cs b/CarRepairShop/CarRepairShopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..b35247c --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.DI +{ + public static partial class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach(var t in asm.GetExportedTypes()) + { + if(t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if(source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if(newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/DI/UnityDependencyContainer.cs b/CarRepairShop/CarRepairShopContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..369e64b --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; + +namespace CarRepairShopContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var logger = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(logger)); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabaseImplement.csproj b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabaseImplement.csproj index 5e3533c..0c914fd 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabaseImplement.csproj +++ b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabaseImplement.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/DatabaseImplementationExtension.cs b/CarRepairShop/CarRepairShopDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..ff6b4ce --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarRepairShopContracts.DI; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement +{ + 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/CarRepairShop/CarRepairShopFileImplement/CarRepairShopFileImplement.csproj b/CarRepairShop/CarRepairShopFileImplement/CarRepairShopFileImplement.csproj index b1210f3..2daf12b 100644 --- a/CarRepairShop/CarRepairShopFileImplement/CarRepairShopFileImplement.csproj +++ b/CarRepairShop/CarRepairShopFileImplement/CarRepairShopFileImplement.csproj @@ -13,4 +13,8 @@ + + + + diff --git a/CarRepairShop/CarRepairShopFileImplement/FileImplementationExtension.cs b/CarRepairShop/CarRepairShopFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..b444b6c --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarRepairShopContracts.DI; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopFileImplement +{ + 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/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj index e49be3f..60d2cac 100644 --- a/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj +++ b/CarRepairShop/CarRepairShopListImplement/CarRepairShopListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/BackUpInfo.cs b/CarRepairShop/CarRepairShopListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..cdfa280 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using CarRepairShopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + internal class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/ListImplementationExtension.cs b/CarRepairShop/CarRepairShopListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..b7e2738 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarRepairShopContracts.DI; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormComponents.cs b/CarRepairShop/CarRepairShopView/FormComponents.cs index 1f99507..632da26 100644 --- a/CarRepairShop/CarRepairShopView/FormComponents.cs +++ b/CarRepairShop/CarRepairShopView/FormComponents.cs @@ -1,5 +1,6 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -44,28 +45,24 @@ namespace CarRepairShopView 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/CarRepairShop/CarRepairShopView/FormImplementers.cs b/CarRepairShop/CarRepairShopView/FormImplementers.cs index 1e50c79..4e83fe8 100644 --- a/CarRepairShop/CarRepairShopView/FormImplementers.cs +++ b/CarRepairShop/CarRepairShopView/FormImplementers.cs @@ -1,4 +1,5 @@ using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -44,13 +45,10 @@ namespace CarRepairShopView private void buttonCreate_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(); } } @@ -58,14 +56,11 @@ namespace CarRepairShopView { 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/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index 0372400..e2f0d3f 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -1,5 +1,6 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using CarRepairShopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -44,30 +45,26 @@ namespace CarRepairShopView 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(FormRepairs)); - if (service is FormRepairs 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) @@ -168,54 +165,39 @@ namespace CarRepairShopView private void ComponentRepairsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportRepairComponents)); - if (service is FormReportRepairComponents 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 ClientsToolStripMenuItem_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 workStartToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } 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 почтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormLetters)); - if (service is FormLetters form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/CarRepairShop/CarRepairShopView/FormRepair.cs b/CarRepairShop/CarRepairShopView/FormRepair.cs index a9f57fa..39d5c2d 100644 --- a/CarRepairShop/CarRepairShopView/FormRepair.cs +++ b/CarRepairShop/CarRepairShopView/FormRepair.cs @@ -1,5 +1,6 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using CarRepairShopContracts.SearchModels; using CarRepairShopDataModels.Models; using Microsoft.Extensions.Logging; @@ -79,26 +80,23 @@ namespace CarRepairShopView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); - if (service is FormRepairComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {componentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - if (_repairComponents.ContainsKey(form.Id)) - { - _repairComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _repairComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: {componentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_repairComponents.ContainsKey(form.Id)) + { + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _repairComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } @@ -106,22 +104,20 @@ namespace CarRepairShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); - if (service is FormRepairComponent form) + var form = DependencyManager.Instance.Resolve(); + + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _repairComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _repairComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - _repairComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/CarRepairShop/CarRepairShopView/FormRepairs.cs b/CarRepairShop/CarRepairShopView/FormRepairs.cs index 24282e0..f96e572 100644 --- a/CarRepairShop/CarRepairShopView/FormRepairs.cs +++ b/CarRepairShop/CarRepairShopView/FormRepairs.cs @@ -1,5 +1,6 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -45,13 +46,10 @@ namespace CarRepairShopView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); - if (service is FormRepair form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -59,14 +57,11 @@ namespace CarRepairShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); - if (service is FormRepair 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/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index 0f5b4f7..4e6a1c1 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -4,6 +4,7 @@ using CarRepairShopBusinessLogic.OfficePackage; using CarRepairShopBusinessLogic.OfficePackage.Implements; using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.DI; using CarRepairShopContracts.StoragesContracts; using CarRepairShopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; @@ -15,9 +16,6 @@ namespace CarRepairShopView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// /// The main entry point for the application. /// @@ -28,12 +26,10 @@ namespace CarRepairShopView // 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 = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,58 +43,50 @@ namespace CarRepairShopView } 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"); + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + 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(); - services.AddTransient(); - services.AddSingleton(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - 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 -- 2.25.1