create attributes for viewmodels
This commit is contained in:
parent
ec31fa4311
commit
513bcc2ec0
47
FlowerShop/FlowerShop/DataGridViewExtension.cs
Normal file
47
FlowerShop/FlowerShop/DataGridViewExtension.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using FlowerShopContracts.Attributes;
|
||||||
|
|
||||||
|
namespace FlowerShopView
|
||||||
|
{
|
||||||
|
public static class DataGridViewExtension
|
||||||
|
{
|
||||||
|
public static void FillandConfigGrid<T>(this DataGridView grid, List<T>? 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,12 +24,7 @@ namespace FlowerShopView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _logic.ReadList(null);
|
dataGridView.FillandConfigGrid(_logic.ReadList(null));
|
||||||
if (list != null)
|
|
||||||
{
|
|
||||||
dataGridView.DataSource = list;
|
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Загрузка клиентов");
|
_logger.LogInformation("Загрузка клиентов");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -22,14 +22,7 @@ namespace FlowerShopView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _logic.ReadList(null);
|
dataGridView.FillandConfigGrid(_logic.ReadList(null));
|
||||||
if (list != null)
|
|
||||||
{
|
|
||||||
dataGridView.DataSource = list;
|
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
|
||||||
dataGridView.Columns["ComponentName"].AutoSizeMode =
|
|
||||||
DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Загрузка компонентов");
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -24,19 +24,12 @@ namespace FlowerShopView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _logic.ReadList(null);
|
dataGridView.FillandConfigGrid(_logic.ReadList(null));
|
||||||
if (list != null)
|
_logger.LogInformation("Загрузка цветов");
|
||||||
{
|
|
||||||
dataGridView.DataSource = list;
|
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
|
||||||
dataGridView.Columns["FlowerComponents"].Visible = false;
|
|
||||||
dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Загрузка компонентов");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
_logger.LogError(ex, "Ошибка загрузки цветов");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,15 +21,7 @@ namespace FlowerShopView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var List = _implementerLogic.ReadList(null);
|
DataGridView.FillandConfigGrid(_implementerLogic.ReadList(null));
|
||||||
|
|
||||||
if (List != null)
|
|
||||||
{
|
|
||||||
DataGridView.DataSource = List;
|
|
||||||
DataGridView.Columns["Id"].Visible = false;
|
|
||||||
DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("Загрузка исполнителей");
|
_logger.LogInformation("Загрузка исполнителей");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -20,16 +20,7 @@ namespace FlowerShopView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var List = _messageLogic.ReadList(null);
|
dataGridView.FillandConfigGrid(_messageLogic.ReadList(null));
|
||||||
|
|
||||||
if (List != null)
|
|
||||||
{
|
|
||||||
dataGridView.DataSource = List;
|
|
||||||
dataGridView.Columns["MessageId"].Visible = false;
|
|
||||||
dataGridView.Columns["ClientId"].Visible = false;
|
|
||||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("Загрузка почтовых собщений");
|
_logger.LogInformation("Загрузка почтовых собщений");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -25,18 +25,10 @@ namespace FlowerShopView
|
|||||||
}
|
}
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка заказов");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = _orderLogic.ReadList(null);
|
dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
|
||||||
if (list != null)
|
_logger.LogInformation("Загрузка заказов");
|
||||||
{
|
|
||||||
dataGridView.DataSource = list;
|
|
||||||
dataGridView.Columns["FlowerId"].Visible = false;
|
|
||||||
dataGridView.Columns["ClientId"].Visible = false;
|
|
||||||
dataGridView.Columns["ClientEmail"].Visible = false;
|
|
||||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
22
FlowerShop/FlowerShopContracts/Attributes/ColumnAttribute.cs
Normal file
22
FlowerShop/FlowerShopContracts/Attributes/ColumnAttribute.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace FlowerShopContracts.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; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
namespace FlowerShopContracts.Attributes
|
||||||
|
{
|
||||||
|
public enum GridViewAutoSize
|
||||||
|
{
|
||||||
|
NotSet = 0,
|
||||||
|
None = 1,
|
||||||
|
ColumnHeader = 2,
|
||||||
|
AllCellsExceptHeader = 4,
|
||||||
|
AllCells = 6,
|
||||||
|
DisplayedCellsExceptHeader = 8,
|
||||||
|
DisplayedCells = 10,
|
||||||
|
Fill = 16
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,17 @@
|
|||||||
using FlowerShopDataModels.Models;
|
using FlowerShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class ClientViewModel : IClientModel
|
public class ClientViewModel : IClientModel
|
||||||
{
|
{
|
||||||
|
[Column(visible: false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("ФИО клиента")]
|
[Column(title: "ФИО клиента", width: 150)]
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
[DisplayName("Логин (эл. почта)")]
|
[Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public string Email { get; set; } = string.Empty;
|
public string Email { get; set; } = string.Empty;
|
||||||
[DisplayName("Пароль")]
|
[Column(title: "Пароль", width: 150)]
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
using FlowerShopDataModels.Models;
|
using FlowerShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class ComponentViewModel : IComponentModel
|
public class ComponentViewModel : IComponentModel
|
||||||
{
|
{
|
||||||
|
[Column(visible: false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[DisplayName("Название компонента")]
|
[Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public string ComponentName { get; set; } = string.Empty;
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
[Column(title: "Цена", width: 150)]
|
||||||
[DisplayName("Цена")]
|
|
||||||
public double Cost { get; set; }
|
public double Cost { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
using FlowerShopDataModels.Models;
|
using FlowerShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class FlowerViewModel : IFlowerModel
|
public class FlowerViewModel : IFlowerModel
|
||||||
{
|
{
|
||||||
|
[Column(visible: false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название изделия")]
|
[Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public string FlowerName { get; set; } = string.Empty;
|
public string FlowerName { get; set; } = string.Empty;
|
||||||
[DisplayName("Цена")]
|
[Column(title: "Цена", width: 150)]
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
|
[Column(visible: false)]
|
||||||
public Dictionary<int, (IComponentModel, int)> FlowerComponents
|
public Dictionary<int, (IComponentModel, int)> FlowerComponents
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
using FlowerShopDataModels.Models;
|
using FlowerShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class ImplementerViewModel : IImplementerModel
|
public class ImplementerViewModel : IImplementerModel
|
||||||
{
|
{
|
||||||
|
[Column(visible: false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("ФИО исполнителя")]
|
[Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||||
public string ImplementerFIO { get; set; } = string.Empty;
|
public string ImplementerFIO { get; set; } = string.Empty;
|
||||||
[DisplayName("Пароль")]
|
[Column(title: "Пароль", width: 100)]
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
[DisplayName("Опыт исполнителя")]
|
[Column(title: "Опыт исполнителя" ,gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public int WorkExperience { get; set; }
|
public int WorkExperience { get; set; }
|
||||||
[DisplayName("Квалификация исполнителя")]
|
[Column(title: "Квалификация исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public int Qualification { get; set; }
|
public int Qualification { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
using FlowerShopDataModels.Models;
|
using FlowerShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class MessageInfoViewModel : IMessageInfoModel
|
public class MessageInfoViewModel : IMessageInfoModel
|
||||||
{
|
{
|
||||||
|
[Column(visible: false)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Column(visible: false)]
|
||||||
public string MessageId { get; set; } = string.Empty;
|
public string MessageId { get; set; } = string.Empty;
|
||||||
|
[Column(visible: false)]
|
||||||
public int? ClientId { get; set; }
|
public int? ClientId { get; set; }
|
||||||
[DisplayName("Отправитель")]
|
[Column(title: "Отправитель" ,width: 150)]
|
||||||
public string SenderName { get; set; } = string.Empty;
|
public string SenderName { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата доставки")]
|
[Column(title: "Дата доставки", width: 120)]
|
||||||
public DateTime DateDelivery { get; set; }
|
public DateTime DateDelivery { get; set; }
|
||||||
[DisplayName("Тема")]
|
[Column(title: "Тема", width: 120)]
|
||||||
public string Subject { get; set; } = string.Empty;
|
public string Subject { get; set; } = string.Empty;
|
||||||
[DisplayName("Содержание")]
|
[Column(title: "Содержание", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,36 @@
|
|||||||
using FlowerShopDataModels.Enums;
|
using FlowerShopContracts.Attributes;
|
||||||
|
using FlowerShopDataModels.Enums;
|
||||||
using FlowerShopDataModels.Models;
|
using FlowerShopDataModels.Models;
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace FlowerShopContracts.ViewModels
|
namespace FlowerShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class OrderViewModel : IOrderModel
|
public class OrderViewModel : IOrderModel
|
||||||
{
|
{
|
||||||
[DisplayName("Номер")]
|
[Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[Column(visible: false)]
|
||||||
public int FlowerId { get; set; }
|
public int FlowerId { get; set; }
|
||||||
|
[Column(visible: false)]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
|
[Column(visible: false)]
|
||||||
public int? ImplementerId { get; set; }
|
public int? ImplementerId { get; set; }
|
||||||
[DisplayName("Изделие")]
|
[Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||||
public string FlowerName { get; set; } = string.Empty;
|
public string FlowerName { get; set; } = string.Empty;
|
||||||
[DisplayName("ФИО клиента")]
|
[Column(title: "ФИО клиента", width: 120)]
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
[DisplayName("Почта клиента")]
|
[Column(title: "Почта клиента", width: 190]
|
||||||
public string ClientEmail { get; set; } = string.Empty;
|
public string ClientEmail { get; set; } = string.Empty;
|
||||||
[DisplayName("ФИО исполнителя")]
|
[Column(title: "ФИО исполнителя", width: 120)]
|
||||||
public string ImplementerFIO { get; set; }=string.Empty;
|
public string ImplementerFIO { get; set; }=string.Empty;
|
||||||
[DisplayName("Количество")]
|
[Column(title: "Количество", width: 100)]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[DisplayName("Сумма")]
|
[Column(title: "Сумма", width: 75)]
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
[DisplayName("Статус")]
|
[Column(title: "Статус", width:70)]
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
[DisplayName("Дата создания")]
|
[Column(title: "Дата создания", width: 120)]
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
[DisplayName("Дата выполнения")]
|
[Column(title: "Дата выполнения", width:120)]
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user