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" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)BusinessLogicExtensions\*.dll&quot;" />
</Target>
</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)]
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;
Visible = visible;
Width = width;
GridViewAutoSize = gridViewAutoSize;
IsUseAutoSize = isUseAutoSize;
Format = format;
}
public string Title { get; private set; }
public bool Visible { get; private set; }
public int Width { get; private set; }
public GridViewAutoSize GridViewAutoSize { get; private set; }
public bool IsUseAutoSize { get; private set; }
public string Format { get; private set; }
}
}

View File

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

View File

@ -25,13 +25,15 @@ namespace AutomobilePlantContracts.DI
/// </summary>
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
var extDB = ServiceProviderLoader.GetImplementationExtensions();
var extBL = ServiceProviderLoader.GetBusinessLogicExtensions();
if (extDB == null || extBL == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
// регистрируем зависимости
ext.RegisterServices();
extDB.RegisterServices();
extBL.RegisterServices();
}
/// <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;
}
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()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
@ -49,5 +78,15 @@ namespace AutomobilePlantContracts.DI
}
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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutomobilePlantContracts.Attributes;
using AutomobilePlantDataModels.Models;
namespace AutomobilePlantContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Shop's name")]
[Column(title: "Shop's name", width: 200)]
public string Name { get; set; } = string.Empty;
[DisplayName("Address")]
[Column(title: "Address", width: 100)]
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; }
[DisplayName("Opening date")]
[Column(title: "Opening date", width: 100, format: "d")]
public DateTime OpeningDate { get; set; }
[Column(visible: false)]
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
[Column(visible: false)]
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<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -87,7 +87,7 @@
//
// 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.Size = new Size(65, 20);
toolStripMenuItemCatalogs.Text = "Catalogs";

View File

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

View File

@ -1,15 +1,7 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
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
{
@ -34,16 +26,7 @@ namespace AutomobilePlantView
{
try
{
var list = _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;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка магазинов");
}
@ -61,34 +44,25 @@ namespace AutomobilePlantView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
var form = DependencyManager.Instance.Resolve<FormShop>();
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
var form = DependencyManager.Instance.Resolve<FormShop>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{

View File

@ -59,21 +59,6 @@ namespace AutomobilePlantView
option.SetMinimumLevel(LogLevel.Information);
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<FormComponent>();
DependencyManager.Instance.RegisterType<FormComponents>();