гОтОвая 8 лаба

This commit is contained in:
Алина 2024-05-18 15:12:05 +04:00
parent 038bd21e3a
commit a26eb406fe
33 changed files with 662 additions and 618 deletions

View File

@ -20,5 +20,6 @@ namespace TypographyContracts.BindingModels
public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; }
}
public int Id { get; set; }
}
}

View File

@ -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;
}
}
}

View File

@ -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; }
}
}
}

View File

@ -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; }
}
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}
}

View File

@ -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<int, (IComponentModel, int)> PrintedComponents { get; set; } = new();
[Column(visible: false)]
public Dictionary<int, (IComponentModel, int)> PrintedComponents { get; set; } = new();
}
}
}

View File

@ -6,8 +6,8 @@ using System.Threading.Tasks;
namespace TypographyDataModels.Models
{
public interface IMessageInfoModel
{
public interface IMessageInfoModel : IId
{
string MessageId { get; }
int? ClientId { get; }

View File

@ -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");
});

View File

@ -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<MessageInfo> ClientMessages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
{
if (model == null)
{
return null;
@ -64,4 +65,4 @@ namespace TypographyDatabaseImplement.Models
Password = Password
};
}
}
}

View File

@ -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
};
}
}
}

View File

@ -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<Order> ImplementerOrders { get; set; } = new();
[ForeignKey("ImplementerId")]
public virtual List<Order> 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
};
}
}

View File

@ -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
};
}
}

View File

@ -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
};
}
}
}

View File

@ -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<int, (IComponentModel, int)>? _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;
}
}
}
}

View File

@ -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();
}
}
}

View File

@ -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));
}
}

View File

@ -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()));
}
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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()));
}
}
}

View File

@ -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<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _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()));
}
}
}

View File

@ -13,7 +13,6 @@
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
<ProjectReference Include="..\TypographyListImplement\TypographyListImplement.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>

View File

@ -0,0 +1,46 @@
using TypographyContracts.Attributes;
namespace TypographyView
{
internal 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;
}
}
}
}
}
}

View File

@ -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)

View File

@ -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<FormComponent>();
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<FormComponent>();
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();
}
}
}

View File

@ -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<FormImplementer>();
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<FormImplementer>();
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();
}
}
}

View File

@ -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;
}
}

View File

@ -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<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
public FormMain(ILogger<FormMain> 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<FormComponents>();
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<FormPrinteds>();
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<FormClients>();
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<FormImplementers>();
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<FormReportPrintedComponents>();
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<FormReportOrders>();
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<IImplementerLogic>(), _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<FormMessages>();
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<FormCreateOrder>();
form.ShowDialog();
LoadData();
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)

View File

@ -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)

View File

@ -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<int, (IComponentModel, int)> _printedComponents;
public int Id { set { _id = value; } }
public FormPrinted(ILogger<FormPrinted> 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<FormPrintedComponent>();
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<FormPrintedComponent>();
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();
}
}
}

View File

@ -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<FormPrinted>();
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<FormPrinted>();
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();
}
}
}

View File

@ -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;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -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<AbstractMailWorker>();
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
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<ILogger>();
var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPrintedStorage, PrintedStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
private static void InitDependency()
{
DependencyManager.InitDependency();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPrintedLogic, PrintedLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<IPrintedLogic, PrintedLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormPrinted>();
services.AddTransient<FormPrinteds>();
services.AddTransient<FormPrintedComponent>();
services.AddTransient<FormClients>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormReportPrintedComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormMessages>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormComponent>();
DependencyManager.Instance.RegisterType<FormComponents>();
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormPrinted>();
DependencyManager.Instance.RegisterType<FormPrinteds>();
DependencyManager.Instance.RegisterType<FormPrintedComponent>();
DependencyManager.Instance.RegisterType<FormClients>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormReportPrintedComponents>();
DependencyManager.Instance.RegisterType<FormReportOrders>();
DependencyManager.Instance.RegisterType<FormMessages>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
}
}