From a26eb406fefbc7086f3011ff1015054157207987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D0=BD=D0=B0?= <Алина@DESKTOP-PH8VQJA> Date: Sat, 18 May 2024 15:12:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=9E=D1=82=D0=9E=D0=B2=D0=B0=D1=8F=208?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/MessageInfoBindingModel.cs | 3 +- .../ViewModels/ClientViewModel.cs | 24 ++-- .../ViewModels/ComponentViewModel.cs | 20 ++- .../ViewModels/ImplementerViewModel.cs | 24 ++-- .../ViewModels/MessageInfoViewModel.cs | 31 ++-- .../ViewModels/OrderViewModel.cs | 44 +++--- .../ViewModels/PrintedViewModel.cs | 22 ++- .../Models/IMessageInfoModel.cs | 4 +- .../TypographyDatabaseModelSnapshot.cs | 4 +- .../Models/Client.cs | 29 ++-- .../Models/Component.cs | 30 ++-- .../Models/Implementer.cs | 117 +++++++-------- .../Models/MessageInfo.cs | 94 +++++++------ .../Models/Order.cs | 74 +++++----- .../Models/Printed.cs | 28 ++-- .../Models/PrintedComponent.cs | 12 +- .../TypographyFileImplement/Models/Client.cs | 133 +++++++++--------- .../Models/Component.cs | 18 ++- .../Models/Implementer.cs | 7 + .../Models/MessageInfo.cs | 10 ++ .../TypographyFileImplement/Models/Order.cs | 80 ++++++----- .../TypographyFileImplement/Models/Printed.cs | 40 +++--- .../TypographyFileImplement.csproj | 1 - .../TypographyView/DataGridViewExtension.cs | 46 ++++++ Typography/TypographyView/FormClients.cs | 9 +- Typography/TypographyView/FormComponents.cs | 34 ++--- Typography/TypographyView/FormImplementers.cs | 30 ++-- .../TypographyView/FormMain.Designer.cs | 11 +- Typography/TypographyView/FormMain.cs | 100 +++++++------ Typography/TypographyView/FormMessages.cs | 10 +- Typography/TypographyView/FormPrinted.cs | 60 ++++---- Typography/TypographyView/FormPrinteds.cs | 35 ++--- Typography/TypographyView/Program.cs | 96 ++++++------- 33 files changed, 662 insertions(+), 618 deletions(-) create mode 100644 Typography/TypographyView/DataGridViewExtension.cs diff --git a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs index 52bab9e..0571b81 100644 --- a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,6 @@ namespace TypographyContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id { get; set; } + } } diff --git a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs index e239de1..f721d00 100644 --- a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs @@ -1,24 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs index 5e43a62..357d478 100644 --- a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -1,21 +1,17 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(title: "Цена", width: 100)] + public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs index ba792fb..95bf0b7 100644 --- a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs @@ -1,27 +1,23 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + 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("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", width: 80)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(title: "Квалификация", width: 120)] + public int Qualification { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs index 39fd046..e24d6d0 100644 --- a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs @@ -1,30 +1,29 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.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("Отправитель")] + [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 120)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] 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; - } -} + [Column(visible: false)] + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs index 7463b45..1d85d3f 100644 --- a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Enums; using TypographyDataModels.Models; @@ -11,40 +6,43 @@ namespace TypographyContracts.ViewModels { public class OrderViewModel : IOrderModel { - - [DisplayName("Номер")] + [Column(title: "Номер", width: 80)] public int Id { get; set; } - public int ClientId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Клиент", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] - public string? ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Исполнитель", width: 150)] + public string? ImplementerFIO { get; set; } = string.Empty; - public int PrintedId { get; set; } + [Column(visible: false)] + public int PrintedId { get; set; } - [DisplayName("Изделие")] - public string PrintedName { get; set; } = string.Empty; + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 100)] public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Статус", width: 150)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 120)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 120)] public DateTime? DateImplement { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs index d31efdc..2c40863 100644 --- a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -1,22 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class PrintedViewModel : IPrintedModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название изделия")] - public string PrintedName { get; set; } = string.Empty; + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 100)] public double Price { get; set; } - public Dictionary PrintedComponents { get; set; } = new(); + + [Column(visible: false)] + public Dictionary PrintedComponents { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs index 83e91bd..9d0f3e0 100644 --- a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs +++ b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace TypographyDataModels.Models { - public interface IMessageInfoModel - { + public interface IMessageInfoModel : IId + { string MessageId { get; } int? ClientId { get; } diff --git a/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs index f2058cb..a1e48fe 100644 --- a/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs +++ b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs @@ -216,7 +216,7 @@ namespace TypographyDatabaseImplement.Migrations modelBuilder.Entity("TypographyDatabaseImplement.Models.MessageInfo", b => { b.HasOne("TypographyDatabaseImplement.Models.Client", "Client") - .WithMany() + .WithMany("ClientMessages") .HasForeignKey("ClientId"); b.Navigation("Client"); @@ -268,6 +268,8 @@ namespace TypographyDatabaseImplement.Migrations modelBuilder.Entity("TypographyDatabaseImplement.Models.Client", b => { + b.Navigation("ClientMessages"); + b.Navigation("ClientOrders"); }); diff --git a/Typography/TypographyDatabaseImplement/Models/Client.cs b/Typography/TypographyDatabaseImplement/Models/Client.cs index 2fc0571..25c4273 100644 --- a/Typography/TypographyDatabaseImplement/Models/Client.cs +++ b/Typography/TypographyDatabaseImplement/Models/Client.cs @@ -1,27 +1,28 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } - [Required] + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] @@ -31,7 +32,7 @@ namespace TypographyDatabaseImplement.Models public virtual List ClientMessages { get; set; } = new(); public static Client? Create(ClientBindingModel model) - { + { if (model == null) { return null; @@ -64,4 +65,4 @@ namespace TypographyDatabaseImplement.Models Password = Password }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Component.cs b/Typography/TypographyDatabaseImplement/Models/Component.cs index 0b0359d..a6069bc 100644 --- a/Typography/TypographyDatabaseImplement/Models/Component.cs +++ b/Typography/TypographyDatabaseImplement/Models/Component.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyDataModels.Models; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - - [Required] + [DataMember] + public int Id { get; private set; } + + [DataMember] + [Required] public string ComponentName { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] @@ -65,4 +65,4 @@ namespace TypographyDatabaseImplement.Models Cost = Cost }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Implementer.cs b/Typography/TypographyDatabaseImplement/Models/Implementer.cs index 739965e..ea766e6 100644 --- a/Typography/TypographyDatabaseImplement/Models/Implementer.cs +++ b/Typography/TypographyDatabaseImplement/Models/Implementer.cs @@ -1,71 +1,72 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Implementer : IImplementerModel - { - public int Id { get; set; } + [DataContract] + public class Implementer : IImplementerModel + { + [DataMember] + public int Id { get; set; } - [Required] - public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] + [Required] + public string ImplementerFIO { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + [Required] + public string Password { get; set; } = string.Empty; - [Required] - public int WorkExperience { get; set; } + [DataMember] + [Required] + public int WorkExperience { get; set; } - [Required] - public int Qualification { get; set; } + [DataMember] + [Required] + public int Qualification { get; set; } - [ForeignKey("ImplementerId")] - public virtual List ImplementerOrders { get; set; } = new(); + [ForeignKey("ImplementerId")] + public virtual List ImplementerOrders { get; set; } = new(); - public static Implementer? Create(ImplementerBindingModel model) - { - if (model == null) - { - return null; - } - return new Implementer() - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } - public void Update(ImplementerBindingModel model) - { - if (model == null) - { - return; - } - ImplementerFIO = model.ImplementerFIO; - Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; - } - - public ImplementerViewModel GetViewModel => new() - { - Id = Id, - ImplementerFIO = ImplementerFIO, - Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification - }; - } -} + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs index a3ffa8f..4e474d9 100644 --- a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs +++ b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs @@ -2,56 +2,68 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using System.ComponentModel.DataAnnotations.Schema; namespace TypographyDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel - { - [Key] - public string MessageId { get; private set; } = string.Empty; + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + [Key] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public virtual Client? Client { get; private set; } + public virtual Client? Client { get; private set; } - [Required] - public string SenderName { get; private set; } = string.Empty; + [DataMember] + [Required] + public string SenderName { get; private set; } = string.Empty; - [Required] - public DateTime DateDelivery { get; private set; } + [DataMember] + [Required] + public DateTime DateDelivery { get; private set; } - [Required] - public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Subject { get; private set; } = string.Empty; - [Required] - public string Body { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Body { get; private set; } = string.Empty; - public static MessageInfo? Create(MessageInfoBindingModel? model) - { - if (model == null) - { - return null; - } - return new MessageInfo() - { - MessageId = model.MessageId, - ClientId = model.ClientId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - Subject = model.Subject, - Body = model.Body - }; - } + [NotMapped] + public int Id { get; private set; } + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } - public MessageInfoViewModel GetViewModel => new() - { - MessageId = MessageId, - ClientId = ClientId, - SenderName = SenderName, - DateDelivery = DateDelivery, - Subject = Subject, - Body = Body - }; - } -} + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Order.cs b/Typography/TypographyDatabaseImplement/Models/Order.cs index 5c1ef5d..651081d 100644 --- a/Typography/TypographyDatabaseImplement/Models/Order.cs +++ b/Typography/TypographyDatabaseImplement/Models/Order.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Enums; @@ -11,37 +7,47 @@ using TypographyDataModels.Models; namespace TypographyDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - [Required] - public int ClientId { get; private set; } + [DataMember] + [Required] + public int ClientId { get; private set; } - public virtual Client Client { get; set; } = new(); + public virtual Client Client { get; set; } = new(); - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } - public virtual Implementer? Implementer { get; set; } = new(); + public virtual Implementer? Implementer { get; set; } = new(); - [Required] + [DataMember] + [Required] public int PrintedId { get; private set; } public virtual Printed Printed { get; set; } = new(); - [Required] + [DataMember] + [Required] public int Count { get; private set; } - [Required] + [DataMember] + [Required] public double Sum { get; private set; } - [Required] + [DataMember] + [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model, TypographyDatabase context) { @@ -52,11 +58,11 @@ namespace TypographyDatabaseImplement.Models return new Order() { Id = model.Id, - ClientId = model.ClientId, - Client = context.Clients.First(x => model.ClientId == x.Id), - ImplementerId = model.ImplementerId, - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null, - PrintedId = model.PrintedId, + ClientId = model.ClientId, + Client = context.Clients.First(x => model.ClientId == x.Id), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null, + PrintedId = model.PrintedId, Printed = context.Printeds.First(x => model.PrintedId == x.Id), Count = model.Count, Sum = model.Sum, @@ -72,21 +78,21 @@ namespace TypographyDatabaseImplement.Models { return; } - ImplementerId = model.ImplementerId; - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null; - Status = model.Status; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null; + Status = model.Status; DateImplement = model.DateImplement; - } + } public OrderViewModel GetViewModel => new() { Id = Id, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - ClientEmail = Client.Email, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, + ClientEmail = Client.Email, ImplementerId = ImplementerId, - ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, - PrintedId = PrintedId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, + PrintedId = PrintedId, PrintedName = Printed.PrintedName, Count = Count, Sum = Sum, @@ -95,4 +101,4 @@ namespace TypographyDatabaseImplement.Models DateImplement = DateImplement }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Printed.cs b/Typography/TypographyDatabaseImplement/Models/Printed.cs index 63d1a17..9bedcd5 100644 --- a/Typography/TypographyDatabaseImplement/Models/Printed.cs +++ b/Typography/TypographyDatabaseImplement/Models/Printed.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } - [Required] + [DataMember] + [Required] public string PrintedName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _printedComponents = null; @@ -76,7 +76,7 @@ namespace TypographyDatabaseImplement.Models { var printedComponents = context.PrintedComponents.Where(rec => rec.PrintedId == model.Id).ToList(); if (printedComponents != null && printedComponents.Count > 0) - { + { context.PrintedComponents.RemoveRange(printedComponents.Where(rec => !model.PrintedComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); @@ -101,4 +101,4 @@ namespace TypographyDatabaseImplement.Models _printedComponents = null; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs index 3230de1..a4b9982 100644 --- a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs +++ b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class PrintedComponent + public class PrintedComponent { public int Id { get; set; } @@ -24,4 +20,4 @@ namespace TypographyDatabaseImplement.Models public virtual Printed Printed { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Client.cs b/Typography/TypographyFileImplement/Models/Client.cs index 6fb9b7e..40f6ecb 100644 --- a/Typography/TypographyFileImplement/Models/Client.cs +++ b/Typography/TypographyFileImplement/Models/Client.cs @@ -1,76 +1,79 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } - public static Client? Create(ClientBindingModel model) - { - if (model == null) - { - return null; - } - return new Client() - { - Id = model.Id, - ClientFIO = model.ClientFIO, - Email = model.Email, - Password = model.Password - }; - } + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; - public static Client? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Client() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ClientFIO = element.Element("ClientFIO")!.Value, - Email = element.Element("Email")!.Value, - Password = element.Element("Password")!.Value - }; - } + [DataMember] + public string Email { get; private set; } = string.Empty; - public void Update(ClientBindingModel model) - { - if (model == null) - { - return; - } - ClientFIO = model.ClientFIO; - Email = model.Email; - Password = model.Password; - } + [DataMember] + public string Password { get; private set; } = string.Empty; - public ClientViewModel GetViewModel => new() - { - Id = Id, - ClientFIO = ClientFIO, - Email = Email, - Password = Password - }; + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } - public XElement GetXElement => new("Client", - new XAttribute("Id", Id), - new XElement("ClientFIO", ClientFIO), - new XElement("Email", Email), - new XElement("Password", Password)); - } -} + public static Client? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Client() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ClientFIO = element.Element("ClientFIO")!.Value, + Email = element.Element("Email")!.Value, + Password = element.Element("Password")!.Value + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("ClientFIO", ClientFIO), + new XElement("Email", Email), + new XElement("Password", Password)); + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Component.cs b/Typography/TypographyFileImplement/Models/Component.cs index d07ae16..76edde8 100644 --- a/Typography/TypographyFileImplement/Models/Component.cs +++ b/Typography/TypographyFileImplement/Models/Component.cs @@ -2,14 +2,21 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [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) { @@ -61,5 +68,4 @@ namespace TypographyFileImplement.Models new XElement("ComponentName", ComponentName), new XElement("Cost", Cost.ToString())); } - -} +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Implementer.cs b/Typography/TypographyFileImplement/Models/Implementer.cs index 693358c..89575f3 100644 --- a/Typography/TypographyFileImplement/Models/Implementer.cs +++ b/Typography/TypographyFileImplement/Models/Implementer.cs @@ -3,19 +3,26 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; using System.Reflection; +using System.Runtime.Serialization; namespace TypographyFileImplement.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/Typography/TypographyFileImplement/Models/MessageInfo.cs b/Typography/TypographyFileImplement/Models/MessageInfo.cs index 02c1b24..42272e3 100644 --- a/Typography/TypographyFileImplement/Models/MessageInfo.cs +++ b/Typography/TypographyFileImplement/Models/MessageInfo.cs @@ -2,23 +2,33 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] public string SenderName { get; private set; } = string.Empty; + [DataMember] public DateTime DateDelivery { get; private set; } + [DataMember] public string Subject { get; private set; } = string.Empty; + [DataMember] public string Body { get; private set; } = string.Empty; + public int Id { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Order.cs b/Typography/TypographyFileImplement/Models/Order.cs index 8399283..7b10d56 100644 --- a/Typography/TypographyFileImplement/Models/Order.cs +++ b/Typography/TypographyFileImplement/Models/Order.cs @@ -1,28 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; using System.Xml.Linq; using TypographyDataModels.Enums; -using TypographyDataModels.Models; -using TypographyContracts.BindingModels; -using TypographyContracts.ViewModels; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - + [DataMember] public int Id { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } - public int PrintedId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + + [DataMember] + public int ClientId { get; private set; } + + [DataMember] + public int? ImplementerId { get; private set; } + + [DataMember] + public int PrintedId { get; private 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 static Order? Create(OrderBindingModel model) { @@ -33,9 +46,9 @@ namespace TypographyFileImplement.Models return new Order() { Id = model.Id, - ClientId = model.ClientId, - ImplementerId = model.ImplementerId, - PrintedId = model.PrintedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + PrintedId = model.PrintedId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,9 +66,9 @@ namespace TypographyFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), - PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -71,17 +84,17 @@ namespace TypographyFileImplement.Models { return; } - ImplementerId = model.ImplementerId; - Status = model.Status; + ImplementerId = model.ImplementerId; + Status = model.Status; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, - ClientId = ClientId, - ImplementerId = ImplementerId, - PrintedId = PrintedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + PrintedId = PrintedId, Count = Count, Sum = Sum, Status = Status, @@ -91,14 +104,13 @@ namespace TypographyFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XElement("ClientId", ClientId), - new XElement("ImplementerId", ImplementerId), - new XElement("PrintedId", PrintedId), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), + new XElement("PrintedId", PrintedId), new XElement("Count", Count), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); } -} - +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Printed.cs b/Typography/TypographyFileImplement/Models/Printed.cs index 7a5ff47..51db7f7 100644 --- a/Typography/TypographyFileImplement/Models/Printed.cs +++ b/Typography/TypographyFileImplement/Models/Printed.cs @@ -1,20 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; private set; } - public string PrintedName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string PrintedName { get; private set; } = string.Empty; + + [DataMember] + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); private Dictionary? _productComponents = null; @@ -26,12 +29,13 @@ namespace TypographyFileImplement.Models if (_productComponents == null) { var source = DataFileSingleton.GetInstance(); - _productComponents = Components.ToDictionary(x => x.Key, y => - ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + _productComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,y.Value)); } return _productComponents; } } + public static Printed? Create(PrintedBindingModel model) { if (model == null) @@ -46,6 +50,7 @@ namespace TypographyFileImplement.Models Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2) }; } + public static Printed? Create(XElement element) { if (element == null) @@ -58,10 +63,11 @@ namespace TypographyFileImplement.Models PrintedName = element.Element("ProductName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), Components = element.Element("ProductComponents")!.Elements("ProductComponent").ToDictionary(x => - Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; } + public void Update(PrintedBindingModel model) { if (model == null) @@ -70,9 +76,10 @@ namespace TypographyFileImplement.Models } PrintedName = model.PrintedName; Price = model.Price; - Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + Components = model.PrintedComponents.ToDictionary(x => x.Key, x =>x.Value.Item2); _productComponents = null; } + public PrintedViewModel GetViewModel => new() { Id = Id, @@ -80,6 +87,7 @@ namespace TypographyFileImplement.Models Price = Price, PrintedComponents = PrintedComponents }; + public XElement GetXElement => new("Product", new XAttribute("Id", Id), new XElement("ProductName", PrintedName), @@ -90,4 +98,4 @@ namespace TypographyFileImplement.Models new XElement("Value", x.Value))) .ToArray())); } -} +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/TypographyFileImplement.csproj b/Typography/TypographyFileImplement/TypographyFileImplement.csproj index 06faf2d..cfb0043 100644 --- a/Typography/TypographyFileImplement/TypographyFileImplement.csproj +++ b/Typography/TypographyFileImplement/TypographyFileImplement.csproj @@ -13,7 +13,6 @@ - diff --git a/Typography/TypographyView/DataGridViewExtension.cs b/Typography/TypographyView/DataGridViewExtension.cs new file mode 100644 index 0000000..f7cc8d1 --- /dev/null +++ b/Typography/TypographyView/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using TypographyContracts.Attributes; + +namespace TypographyView +{ + internal 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; + } + } + } + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormClients.cs b/Typography/TypographyView/FormClients.cs index d5019d9..a20a2ef 100644 --- a/Typography/TypographyView/FormClients.cs +++ b/Typography/TypographyView/FormClients.cs @@ -1,6 +1,7 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace TypographyView { @@ -25,13 +26,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewClients.DataSource = list; - dataGridViewClients.Columns["Id"].Visible = false; - dataGridViewClients.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewClients.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/Typography/TypographyView/FormComponents.cs b/Typography/TypographyView/FormComponents.cs index 85d0784..c035e5f 100644 --- a/Typography/TypographyView/FormComponents.cs +++ b/Typography/TypographyView/FormComponents.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -23,16 +25,10 @@ namespace TypographyView private void LoadData() { - try + try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewComponents.DataSource = list; - dataGridViewComponents.Columns["Id"].Visible = false; - dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridViewComponents.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { @@ -43,13 +39,10 @@ namespace TypographyView 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(); } } @@ -57,14 +50,11 @@ namespace TypographyView { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/FormImplementers.cs b/Typography/TypographyView/FormImplementers.cs index a159582..03f11c6 100644 --- a/Typography/TypographyView/FormImplementers.cs +++ b/Typography/TypographyView/FormImplementers.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -25,13 +27,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewImplementers.DataSource = list; - dataGridViewImplementers.Columns["Id"].Visible = false; - dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewImplementers.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -43,13 +39,10 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -57,14 +50,11 @@ namespace TypographyView { if (dataGridViewImplementers.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/FormMain.Designer.cs b/Typography/TypographyView/FormMain.Designer.cs index c756755..4d2efd6 100644 --- a/Typography/TypographyView/FormMain.Designer.cs +++ b/Typography/TypographyView/FormMain.Designer.cs @@ -44,6 +44,7 @@ ordersListToolStripMenuItem = new ToolStripMenuItem(); workLaunchToolStripMenuItem = new ToolStripMenuItem(); messagesToolStripMenuItem = new ToolStripMenuItem(); + createBackUpToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -94,7 +95,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem, createBackUpToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1482, 28); @@ -178,6 +179,13 @@ messagesToolStripMenuItem.Text = "Письма"; messagesToolStripMenuItem.Click += MessagesToolStripMenuItem_Click; // + // createBackUpToolStripMenuItem + // + createBackUpToolStripMenuItem.Name = "createBackUpToolStripMenuItem"; + createBackUpToolStripMenuItem.Size = new Size(123, 24); + createBackUpToolStripMenuItem.Text = "Создать бекап"; + createBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -218,5 +226,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem workLaunchToolStripMenuItem; private ToolStripMenuItem messagesToolStripMenuItem; + private ToolStripMenuItem createBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.cs b/Typography/TypographyView/FormMain.cs index 1e5d7df..d3aa5f1 100644 --- a/Typography/TypographyView/FormMain.cs +++ b/Typography/TypographyView/FormMain.cs @@ -1,6 +1,9 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.DI; namespace TypographyView { @@ -10,14 +13,17 @@ namespace TypographyView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + 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) @@ -29,16 +35,7 @@ namespace TypographyView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridViewOrders.DataSource = list; - dataGridViewOrders.Columns["ClientId"].Visible = false; - dataGridViewOrders.Columns["ClientEmail"].Visible = false; - dataGridViewOrders.Columns["ImplementerId"].Visible = false; - dataGridViewOrders.Columns["PrintedId"].Visible = false; - dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewOrders.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -50,38 +47,26 @@ namespace TypographyView private void ComponentsToolStripMenuItem_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 PrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); - if (service is FormPrinteds 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 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 PrintedsListToolStripMenuItem_Click(object sender, EventArgs e) @@ -96,45 +81,58 @@ namespace TypographyView private void ComponentPrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPrintedComponents)); - if (service is FormReportPrintedComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersListToolStripMenuItem_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 WorkLaunchToolStripMenuItem_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 MessagesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMessages)); - if (service is FormMessages form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } 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 ButtonIssuedOrder_Click(object sender, EventArgs e) diff --git a/Typography/TypographyView/FormMessages.cs b/Typography/TypographyView/FormMessages.cs index fe66a35..46d91ff 100644 --- a/Typography/TypographyView/FormMessages.cs +++ b/Typography/TypographyView/FormMessages.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; +using System.Windows.Forms; using TypographyContracts.BusinessLogicsContracts; namespace TypographyView @@ -25,14 +26,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewMessages.DataSource = list; - dataGridViewMessages.Columns["MessageId"].Visible = false; - dataGridViewMessages.Columns["ClientId"].Visible = false; - dataGridViewMessages.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewMessages.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка входящих писем"); } catch (Exception ex) diff --git a/Typography/TypographyView/FormPrinted.cs b/Typography/TypographyView/FormPrinted.cs index ddb1c5d..ea9cf0e 100644 --- a/Typography/TypographyView/FormPrinted.cs +++ b/Typography/TypographyView/FormPrinted.cs @@ -3,6 +3,7 @@ using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.SearchModels; using TypographyDataModels.Models; using Microsoft.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -14,6 +15,7 @@ namespace TypographyView private Dictionary _printedComponents; public int Id { set { _id = value; } } + public FormPrinted(ILogger logger, IPrintedLogic logic) { InitializeComponent(); @@ -81,27 +83,24 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent 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 (_printedComponents.ContainsKey(form.Id)) - { - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + if (_printedComponents.ContainsKey(form.Id)) + { + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } @@ -109,23 +108,20 @@ namespace TypographyView { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _printedComponents[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); - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/Typography/TypographyView/FormPrinteds.cs b/Typography/TypographyView/FormPrinteds.cs index 50fead6..be674ed 100644 --- a/Typography/TypographyView/FormPrinteds.cs +++ b/Typography/TypographyView/FormPrinteds.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -23,17 +25,10 @@ namespace TypographyView private void LoadData() { - try + try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewPrinteds.DataSource = list; - dataGridViewPrinteds.Columns["Id"].Visible = false; - dataGridViewPrinteds.Columns["PrintedComponents"].Visible = false; - dataGridViewPrinteds.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка печатной продукции"); + dataGridViewPrinteds.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка печатной продукции"); } catch (Exception ex) { @@ -44,13 +39,10 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -58,14 +50,11 @@ namespace TypographyView { if (dataGridViewPrinteds.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/Program.cs b/Typography/TypographyView/Program.cs index 2e799a9..b7e26e0 100644 --- a/Typography/TypographyView/Program.cs +++ b/Typography/TypographyView/Program.cs @@ -1,22 +1,17 @@ using TypographyBusinessLogic.BusinessLogics; using TypographyContracts.BusinessLogicsContracts; -using TypographyContracts.StoragesContracts; -using TypographyDatabaseImplement.Implements; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; using TypographyBusinessLogic.OfficePackage.Implements; using TypographyBusinessLogic.OfficePackage; using TypographyBusinessLogic.MailWorker; using TypographyContracts.BindingModels; +using TypographyContracts.DI; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace TypographyView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// /// The main entry point for the application. /// @@ -26,13 +21,11 @@ namespace TypographyView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,57 +40,54 @@ namespace TypographyView } 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) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + private static void InitDependency() + { + DependencyManager.InitDependency(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + 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(); + 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