From 44548da8defe8c4760668b2eed16d2b1dd03b46b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sat, 20 Apr 2024 21:08:46 +0400 Subject: [PATCH] Set ViewModel attributes --- .../Attrubites/ColumnAttribute.cs | 26 +++++++ .../Attrubites/GridViewAutoSize.cs | 14 ++++ .../ViewModels/ClientViewModel.cs | 22 +++--- .../ViewModels/ComponentViewModel.cs | 16 ++--- .../ViewModels/ImplementerViewModel.cs | 22 +++--- .../ViewModels/MessageInfoViewModel.cs | 28 ++++---- .../ViewModels/OrderViewModel.cs | 69 ++++++++++--------- .../ViewModels/RepairViewModel.cs | 26 ++++--- 8 files changed, 133 insertions(+), 90 deletions(-) create mode 100644 AutoWorkshopContracts/Attrubites/ColumnAttribute.cs create mode 100644 AutoWorkshopContracts/Attrubites/GridViewAutoSize.cs diff --git a/AutoWorkshopContracts/Attrubites/ColumnAttribute.cs b/AutoWorkshopContracts/Attrubites/ColumnAttribute.cs new file mode 100644 index 0000000..6b0e3a4 --- /dev/null +++ b/AutoWorkshopContracts/Attrubites/ColumnAttribute.cs @@ -0,0 +1,26 @@ +namespace AutoWorkshopContracts.Attrubites +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public ColumnAttribute(string Title = "", bool Visible = true, int Width = 0, + GridViewAutoSize GridViewAutoSize = GridViewAutoSize.None, bool IsUseAutoSize = false) + { + this.Title = Title; + this.Visible = Visible; + this.Width = Width; + this.GridViewAutoSize = GridViewAutoSize; + this.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/AutoWorkshopContracts/Attrubites/GridViewAutoSize.cs b/AutoWorkshopContracts/Attrubites/GridViewAutoSize.cs new file mode 100644 index 0000000..e885bb8 --- /dev/null +++ b/AutoWorkshopContracts/Attrubites/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace AutoWorkshopContracts.Attrubites +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/AutoWorkshopContracts/ViewModels/ClientViewModel.cs b/AutoWorkshopContracts/ViewModels/ClientViewModel.cs index 8437dca..d8c7bbf 100644 --- a/AutoWorkshopContracts/ViewModels/ClientViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/ClientViewModel.cs @@ -1,19 +1,19 @@ -using AutoWorkshopDataModels.Models; -using System.ComponentModel; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.ViewModels { - public class ClientViewModel : IClientModel + public class ClientViewModel : IClientModel { public int Id { get; set; } + + [Column(Title: "ФИО клиента", Width: 150)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(Title: "Логин (эл. почта)", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + + [Column(Title: "Пароль", Width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs b/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs index ead047b..8b191e2 100644 --- a/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -1,16 +1,16 @@ -using AutoWorkshopDataModels.Models; -using System.ComponentModel; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.ViewModels { - public class ComponentViewModel : IComponentModel + public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(Title: "Название компонента", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + + [Column(Title: "Цена", Width: 150)] + public double Cost { get; set; } } } diff --git a/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs b/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs index cf93e02..4e49515 100644 --- a/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -1,22 +1,22 @@ -using AutoWorkshopDataModels.Models; -using System.ComponentModel; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.ViewModels { - public class ImplementerViewModel : IImplementerModel + public class ImplementerViewModel : IImplementerModel { public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column(Title: "ФИО исполнителя", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(Title: "Пароль", Width: 100)] + public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } + [Column(Title: "Стаж работы", Width: 60)] + public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(Title: "Квалификация", Width: 60)] + public int Qualification { get; set; } } } diff --git a/AutoWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/AutoWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 34d2b95..2a1371a 100644 --- a/AutoWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,26 @@ -using AutoWorkshopDataModels.Models; -using System.ComponentModel; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.ViewModels { - public class MessageInfoViewModel : IMessageInfoModel + public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(Visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [Column(Visible: false)] + public int? ClientId { get; set; } - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + [Column(Title: "Отправитель", Width: 150)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата доставки")] - public DateTime DateDelivery { get; set; } + [Column(Title: "Дата доставки", Width: 120)] + public DateTime DateDelivery { get; set; } - [DisplayName("Тема")] - public string Subject { get; set; } = string.Empty; + [Column(Title: "Тема", Width: 120)] + public string Subject { get; set; } = string.Empty; - [DisplayName("Содержание")] - public string Body { get; set; } = string.Empty; + [Column(Title: "Содержание", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string Body { get; set; } = string.Empty; } } diff --git a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs index ed8da9e..bc4638a 100644 --- a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs @@ -1,45 +1,48 @@ -using AutoWorkshopDataModels.Enums; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Enums; using AutoWorkshopDataModels.Models; -using System.ComponentModel; namespace AutoWorkshopContracts.ViewModels { - public class OrderViewModel : IOrderModel + public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - - public int RepairId { get; set; } + [Column(Title: "Номер", Width: 90)] + public int Id { get; set; } - [DisplayName("Ремонт")] - public string RepairName { get; set; } = string.Empty; + [Column(Visible: false)] + public int RepairId { get; set; } - public int ClientId { get; set; } - - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(Title: "Ремонт", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string RepairName { get; set; } = string.Empty; - [DisplayName("Почта клиента")] - public string ClientEmail { get; set; } = string.Empty; + [Column(Visible: false)] + public int ClientId { get; set; } - public int? ImplementerId { get; set; } - - [DisplayName("Исполнитель")] - public string? ImplementerFIO { get; set; } + [Column(Title: "Клиент", Width: 190)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - - [DisplayName("Сумма")] - public double Sum { get; set; } - - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Undefined; - - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(Title: "Почта клиента", Width: 190)] + public string ClientEmail { get; set; } = string.Empty; + + [Column(Visible: false)] + public int? ImplementerId { get; set; } + + [Column(Title: "Исполнитель", Width: 150)] + public string? ImplementerFIO { get; set; } + + [Column(Title: "Количество", Width: 100)] + public int Count { get; set; } + + [Column(Title: "Сумма", Width: 120)] + public double Sum { get; set; } + + [Column(Title: "Статус", Width: 70)] + public OrderStatus Status { get; set; } = OrderStatus.Undefined; + + [Column(Title: "Дата создания", Width: 120)] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [Column(Title: "Дата выполнения", Width: 120)] + public DateTime? DateImplement { get; set; } } } diff --git a/AutoWorkshopContracts/ViewModels/RepairViewModel.cs b/AutoWorkshopContracts/ViewModels/RepairViewModel.cs index d0a5f54..e79ffd0 100644 --- a/AutoWorkshopContracts/ViewModels/RepairViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/RepairViewModel.cs @@ -1,22 +1,20 @@ -using AutoWorkshopDataModels.Models; -using System.ComponentModel; +using AutoWorkshopContracts.Attrubites; +using AutoWorkshopDataModels.Models; namespace AutoWorkshopContracts.ViewModels { - public class RepairViewModel : IRepairModel + public class RepairViewModel : IRepairModel { - public int Id { get; set; } + [Column(Visible: false)] + public int Id { get; set; } - [DisplayName("Название ремонта")] - public string RepairName { get; set; } = string.Empty; + [Column(Title: "Название ремонта", GridViewAutoSize: GridViewAutoSize.Fill, IsUseAutoSize: true)] + public string RepairName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - - public Dictionary RepairComponents - { - get; - set; - } = new(); + [Column(Title: "Цена", Width: 70)] + public double Price { get; set; } + + [Column(Visible: false)] + public Dictionary RepairComponents { get; set; } = new(); } }