8 laba complicated

This commit is contained in:
Timourka 2024-05-19 00:34:32 +05:00
parent d4f781674c
commit d7ac4d7627
19 changed files with 176 additions and 135 deletions

View File

@ -17,4 +17,8 @@
<ProjectReference Include="..\AutomobilePlantContracts\AutomobilePlantContracts.csproj" /> <ProjectReference Include="..\AutomobilePlantContracts\AutomobilePlantContracts.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)BusinessLogicExtensions\*.dll&quot;" />
</Target>
</Project> </Project>

View File

@ -0,0 +1,36 @@
using AutomobilePlantBusinessLogic.BusinessLogics;
using AutomobilePlantBusinessLogic.MailWorker;
using AutomobilePlantBusinessLogic.OfficePackage.Implements;
using AutomobilePlantBusinessLogic.OfficePackage;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
namespace AutomobilePlantBusinessLogic
{
public class BusinessLogicExtension : IBusinessLogicExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ICarLogic, CarLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
}
}
}

View File

@ -3,18 +3,20 @@
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute public class ColumnAttribute : Attribute
{ {
public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "")
{ {
Title = title; Title = title;
Visible = visible; Visible = visible;
Width = width; Width = width;
GridViewAutoSize = gridViewAutoSize; GridViewAutoSize = gridViewAutoSize;
IsUseAutoSize = isUseAutoSize; IsUseAutoSize = isUseAutoSize;
Format = format;
} }
public string Title { get; private set; } public string Title { get; private set; }
public bool Visible { get; private set; } public bool Visible { get; private set; }
public int Width { get; private set; } public int Width { get; private set; }
public GridViewAutoSize GridViewAutoSize { get; private set; } public GridViewAutoSize GridViewAutoSize { get; private set; }
public bool IsUseAutoSize { get; private set; } public bool IsUseAutoSize { get; private set; }
public string Format { get; private set; }
} }
} }

View File

@ -17,7 +17,6 @@ namespace AutomobilePlantContracts.BindingModels
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public bool IsReaded { get; set; } public bool IsReaded { get; set; }
public string? Reply { get; set; } public string? Reply { get; set; }
}
public int Id => throw new NotImplementedException(); public int Id => throw new NotImplementedException();
} }

View File

@ -25,13 +25,15 @@ namespace AutomobilePlantContracts.DI
/// </summary> /// </summary>
public static void InitDependency() public static void InitDependency()
{ {
var ext = ServiceProviderLoader.GetImplementationExtensions(); var extDB = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null) var extBL = ServiceProviderLoader.GetBusinessLogicExtensions();
if (extDB == null || extBL == null)
{ {
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
} }
// регистрируем зависимости // регистрируем зависимости
ext.RegisterServices(); extDB.RegisterServices();
extBL.RegisterServices();
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,9 @@
namespace AutomobilePlantContracts.DI
{
public interface IBusinessLogicExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -40,6 +40,35 @@ namespace AutomobilePlantContracts.DI
return source; return source;
} }
public static IBusinessLogicExtension? GetBusinessLogicExtensions()
{
IBusinessLogicExtension? source = null;
var files = Directory.GetFiles(TryGetBusinessLogicExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass && typeof(IBusinessLogicExtension).IsAssignableFrom(t))
{
if (source == null)
{
source = (IBusinessLogicExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource = (IBusinessLogicExtension)Activator.CreateInstance(t)!;
if (newSource.Priority > source.Priority)
{
source = newSource;
}
}
}
}
}
return source;
}
private static string TryGetImplementationExtensionsFolder() private static string TryGetImplementationExtensionsFolder()
{ {
var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
@ -49,5 +78,15 @@ namespace AutomobilePlantContracts.DI
} }
return $"{directory?.FullName}\\ImplementationExtensions"; return $"{directory?.FullName}\\ImplementationExtensions";
} }
private static string TryGetBusinessLogicExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetDirectories("BusinessLogicExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\BusinessLogicExtensions";
}
} }
} }

View File

@ -1,31 +1,29 @@
using AutomobilePlantDataModels.Models; using AutomobilePlantContracts.Attributes;
using System; using AutomobilePlantDataModels.Models;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.ViewModels namespace AutomobilePlantContracts.ViewModels
{ {
public class ShopViewModel : IShopModel public class ShopViewModel : IShopModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Shop's name")] [Column(title: "Shop's name", width: 200)]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[DisplayName("Address")] [Column(title: "Address", width: 100)]
public string Address { get; set; } = string.Empty; public string Address { get; set; } = string.Empty;
[DisplayName("Maximum cars' count in shop")] [Column(title: "Maximum cars' count in shop", width: 100)]
public int MaxCountCars { get; set; } public int MaxCountCars { get; set; }
[DisplayName("Opening date")] [Column(title: "Opening date", width: 100, format: "d")]
public DateTime OpeningDate { get; set; } public DateTime OpeningDate { get; set; }
[Column(visible: false)]
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new(); public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
[Column(visible: false)]
public List<Tuple<string, int>>? CarAndCount { get; set; } = new(); public List<Tuple<string, int>>? CarAndCount { get; set; } = new();
} }
} }

View File

@ -17,6 +17,7 @@ namespace AutomobilePlantDatabaseImplement
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>(); DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>(); DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
} }
} }
} }

View File

@ -1,26 +1,27 @@
using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels; using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models; using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantDatabaseImplement.Models namespace AutomobilePlantDatabaseImplement.Models
{ {
[DataContract]
public class Shop : IShopModel public class Shop : IShopModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[DataMember]
[Required] [Required]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[DataMember]
[Required] [Required]
public string Address { get; set; } = string.Empty; public string Address { get; set; } = string.Empty;
[DataMember]
[Required] [Required]
public DateTime OpeningDate { get; set; } public DateTime OpeningDate { get; set; }
@ -29,6 +30,7 @@ namespace AutomobilePlantDatabaseImplement.Models
private Dictionary<int, (ICarModel, int)>? _shopCars = null; private Dictionary<int, (ICarModel, int)>? _shopCars = null;
[DataMember]
[NotMapped] [NotMapped]
public Dictionary<int, (ICarModel, int)> ShopCars public Dictionary<int, (ICarModel, int)> ShopCars
{ {
@ -42,6 +44,7 @@ namespace AutomobilePlantDatabaseImplement.Models
} }
} }
[DataMember]
[Required] [Required]
public int MaxCountCars { get; set; } public int MaxCountCars { get; set; }

View File

@ -17,6 +17,7 @@ namespace AutomobilePlantFileImplement
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>(); DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>(); DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
} }
} }
} }

View File

@ -1,25 +1,28 @@
using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels; using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models; using AutomobilePlantDataModels.Models;
using System; using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace AutomobilePlantFileImplement.Models namespace AutomobilePlantFileImplement.Models
{ {
[DataContract]
public class Shop : IShopModel public class Shop : IShopModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[DataMember]
public string Address { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty;
[DataMember]
public int MaxCountCars { get; private set; } public int MaxCountCars { get; private set; }
[DataMember]
public DateTime OpeningDate { get; private set; } public DateTime OpeningDate { get; private set; }
public Dictionary<int, int> Cars { get; private set; } = new(); public Dictionary<int, int> Cars { get; private set; } = new();
private Dictionary<int, (ICarModel, int)>? _shopCars = null; private Dictionary<int, (ICarModel, int)>? _shopCars = null;
[DataMember]
public Dictionary<int, (ICarModel, int)> ShopCars public Dictionary<int, (ICarModel, int)> ShopCars
{ {
get get

View File

@ -17,6 +17,7 @@ namespace AutomobilePlantListImplement
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>(); DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>(); DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>(); DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
} }
} }
} }

View File

@ -38,6 +38,7 @@ namespace AutomobilePlantView
{ {
column.Width = columnAttr.Width; column.Width = columnAttr.Width;
} }
column.DefaultCellStyle.Format = columnAttr.Format;
} }
} }
} }

View File

@ -1,4 +1,5 @@
using AutomobilePlantContracts.BusinessLogicsContracts; using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace AutomobilePlantView namespace AutomobilePlantView
@ -49,9 +50,7 @@ namespace AutomobilePlantView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMail)); var form = DependencyManager.Instance.Resolve<FormMail>();
if (service is FormMail form)
{
form.MessageId = (string)(dataGridView.SelectedRows[0].Cells["MessageId"].Value); form.MessageId = (string)(dataGridView.SelectedRows[0].Cells["MessageId"].Value);
form.ShowDialog(); form.ShowDialog();
LoadData(); LoadData();
@ -59,4 +58,3 @@ namespace AutomobilePlantView
} }
} }
} }
}

View File

@ -87,7 +87,7 @@
// //
// toolStripMenuItemCatalogs // toolStripMenuItemCatalogs
// //
toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem, implementersToolStripMenuItem, mailsToolStripMenuItem }); toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem, shopsToolStripMenuItem, shopsSupplyToolStripMenuItem, sellCarsToolStripMenuItem, implementersToolStripMenuItem, mailsToolStripMenuItem });
toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs";
toolStripMenuItemCatalogs.Size = new Size(65, 20); toolStripMenuItemCatalogs.Size = new Size(65, 20);
toolStripMenuItemCatalogs.Text = "Catalogs"; toolStripMenuItemCatalogs.Text = "Catalogs";

View File

@ -53,21 +53,15 @@ namespace AutomobilePlantView
private void shopsToolStripMenuItem_Click(object sender, EventArgs e) private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShops)); var form = DependencyManager.Instance.Resolve<FormShops>();
if (service is FormShops form)
{
form.ShowDialog(); form.ShowDialog();
} }
}
private void shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e) private void shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); var form = DependencyManager.Instance.Resolve<FormShopSupply>();
if (service is FormShopSupply form)
{
form.ShowDialog(); form.ShowDialog();
} }
}
private void clientsToolStripMenuItem_Click(object sender, EventArgs e) private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
@ -114,12 +108,9 @@ namespace AutomobilePlantView
private void sellCarsToolStripMenuItem_Click(object sender, EventArgs e) private void sellCarsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell)); var form = DependencyManager.Instance.Resolve<FormShopSell>();
if (service is FormShopSell form)
{
form.ShowDialog(); form.ShowDialog();
} }
}
private void shopsListToolStripMenuItem_Click(object sender, EventArgs e) private void shopsListToolStripMenuItem_Click(object sender, EventArgs e)
{ {
@ -136,12 +127,9 @@ namespace AutomobilePlantView
private void storeCongestionToolStripMenuItem_Click(object sender, EventArgs e) private void storeCongestionToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopCars)); var form = DependencyManager.Instance.Resolve<FormReportShopCars>();
if (service is FormReportShopCars form)
{
form.ShowDialog(); form.ShowDialog();
} }
}
private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e) private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
@ -151,12 +139,9 @@ namespace AutomobilePlantView
private void listOdOrdersByDatesToolStripMenuItem_Click(object sender, EventArgs e) private void listOdOrdersByDatesToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); var form = DependencyManager.Instance.Resolve<FormReportDateOrders>();
if (service is FormReportDateOrders form)
{
form.ShowDialog(); form.ShowDialog();
} }
}
private void createBackupToolStripMenuItem_Click(object sender, EventArgs e) private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)
{ {

View File

@ -1,15 +1,7 @@
using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts; using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutomobilePlantView namespace AutomobilePlantView
{ {
@ -34,16 +26,7 @@ namespace AutomobilePlantView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillAndConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ShopCars"].Visible = false;
}
_logger.LogInformation("Загрузка магазинов"); _logger.LogInformation("Загрузка магазинов");
} }
@ -61,34 +44,25 @@ namespace AutomobilePlantView
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShop)); var form = DependencyManager.Instance.Resolve<FormShop>();
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
}
private void buttonUpdate_Click(object sender, EventArgs e) private void buttonUpdate_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShop)); var form = DependencyManager.Instance.Resolve<FormShop>();
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
}
private void buttonDelete_Click(object sender, EventArgs e) private void buttonDelete_Click(object sender, EventArgs e)
{ {

View File

@ -59,21 +59,6 @@ namespace AutomobilePlantView
option.SetMinimumLevel(LogLevel.Information); option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config"); option.AddNLog("nlog.config");
}); });
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ICarLogic, CarLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>();
DependencyManager.Instance.RegisterType<FormMain>(); DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormComponent>(); DependencyManager.Instance.RegisterType<FormComponent>();
DependencyManager.Instance.RegisterType<FormComponents>(); DependencyManager.Instance.RegisterType<FormComponents>();