diff --git a/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs index a3b01f9..0b4eb8a 100644 --- a/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs +++ b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs @@ -12,16 +12,19 @@ public GridViewAutoSize GridViewAutoSize { get; private set; } public bool IsUseAutoSize { get; private set; } - public string Format { get; private set; } + public bool FormattedDate { get; private set; } + public bool FormattedNumber { get; private set; } - public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "") + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, bool formatDate = false, bool formattedNumber = false) { Title = title; Visible = visible; Width = width; GridViewAutoSize = gridViewAutoSize; IsUseAutoSize = isUseAutoSize; - Format = format; - } + FormattedDate = formatDate; + FormattedNumber = formattedNumber; + } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs index cb9d3ec..1872337 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs @@ -12,7 +12,7 @@ namespace PlumbingRepairContracts.ViewModels [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true, formattedNumber: true)] public double Cost { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs index c8a1c5e..0296b09 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs @@ -12,7 +12,7 @@ namespace PlumbingRepairContracts.ViewModels public int? ClientId { get; set; } [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [Column(title: "Дата отправления", width: 150, format: "Date: dd/MM/yyyy")] + [Column(title: "Дата отправления", width: 150, formatDate: true)] public DateTime DateDelivery { get; set; } [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs index 28e71d0..517a1aa 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -30,16 +30,16 @@ namespace PlumbingRepairContracts.ViewModels [Column(title: "Количество", width: 150)] public int Count { get; set; } - [Column(title: "Сумма", width: 150)] + [Column(title: "Сумма", width: 150, formattedNumber: true)] public double Sum { get; set; } [Column(title: "Статус", width: 150)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Column(title: "Дата создания", width: 150, format: "Date: dd/MM/yyyy")] + [Column(title: "Дата создания", width: 150, formatDate: true)] public DateTime DateCreate { get; set; } = DateTime.Now; - [Column(title: "Дата выполнения", width: 150, format: "Date: dd/MM/yyyy")] + [Column(title: "Дата выполнения", width: 150, formatDate: true)] public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs index a8ad960..e19d1e0 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs @@ -16,9 +16,10 @@ namespace PlumbingRepairContracts.ViewModels public string Address { get; set; } = string.Empty; [Column(title: "Максимальное количество работ", width: 150)] public int maxCountWorks { get; set; } - [Column(title: "Дата открытия", width: 150, format: "Date: dd/MM/yyyy")] + [Column(title: "Дата открытия", width: 150, formatDate: true)] public DateTime DateOpening { get; set; } - public Dictionary ShopWorks { get; set; } = new(); + [Column(visible: false)] + public Dictionary ShopWorks { get; set; } = new(); } } diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs index 1b4ff09..e598c3e 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs @@ -12,7 +12,7 @@ namespace PlumbingRepairContracts.ViewModels [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string WorkName { get; set; } = string.Empty; - [Column(title: "Цена", width: 150)] + [Column(title: "Цена", width: 150, formattedNumber: true)] public double Price { get; set; } [Column(visible: false)] public Dictionary WorkComponents { get; set; } = new(); diff --git a/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs b/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs index 7e9ef05..d08ae93 100644 --- a/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs +++ b/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs @@ -39,7 +39,15 @@ namespace PlumbingRepairView { column.Width = columnAttr.Width; } - } + if (columnAttr.FormattedDate && (column.ValueType == typeof(DateTime) || column.ValueType == typeof(DateTime?))) + { + column.DefaultCellStyle.Format = "dd MMMM yy, HH:mm:ss"; + } + if (columnAttr.FormattedNumber && column.ValueType == typeof(double)) + { + column.DefaultCellStyle.Format = "N2"; + } + } } } } diff --git a/PlumbingRepair/PlumbingRepairView/FormShops.cs b/PlumbingRepair/PlumbingRepairView/FormShops.cs index a132d1b..81ab917 100644 --- a/PlumbingRepair/PlumbingRepairView/FormShops.cs +++ b/PlumbingRepair/PlumbingRepairView/FormShops.cs @@ -27,16 +27,8 @@ namespace PlumbingRepairView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopWorks"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - - } - _logger.LogInformation("Загрузка магазинов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { diff --git a/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs index 0cdd226..8cf59f8 100644 --- a/PlumbingRepair/PlumbingRepairView/Program.cs +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -1,10 +1,7 @@ -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PlumbingRepairBusinessLogic.BusinessLogics; using PlumbingRepairContracts.BusinessLogicsContracts; -using PlumbingRepairContracts.StoragesContracts; -using PlumbingRepairFileImplement.Implements; using PlumbingRepairBusinessLogic.OfficePackage; using PlumbingRepairBusinessLogic.OfficePackage.Implements; using PlumbingRepairBusinessLogic.MailWorker; @@ -69,6 +66,7 @@ namespace PlumbingRepairView DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); @@ -78,6 +76,9 @@ namespace PlumbingRepairView DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck();