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
{
public int Id { get; set; }
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Shop's name")]
public string Name { get; set; } = string.Empty;
[Column(title: "Shop's name", width: 200)]
public string Name { get; set; } = string.Empty;
[DisplayName("Address")]
public string Address { get; set; } = string.Empty;
[Column(title: "Address", width: 100)]
public string Address { get; set; } = string.Empty;
[DisplayName("Maximum cars' count in shop")]
public int MaxCountCars { get; set; }
[Column(title: "Maximum cars' count in shop", width: 100)]
public int MaxCountCars { get; set; }
[DisplayName("Opening date")]
public DateTime OpeningDate { get; set; }
[Column(title: "Opening date", width: 100, format: "d")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
[Column(visible: false)]
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
public List<Tuple<string, int>>? CarAndCount { 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,27 +1,28 @@
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
{
public class Shop : IShopModel
{
public int Id { get; set; }
[DataContract]
public class Shop : IShopModel
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
[Required]
public string Name { get; set; } = string.Empty;
[Required]
[DataMember]
[Required]
public string Address { get; set; } = string.Empty;
[Required]
[DataMember]
[Required]
public DateTime OpeningDate { get; set; }
[ForeignKey("ShopId")]
@ -29,7 +30,8 @@ namespace AutomobilePlantDatabaseImplement.Models
private Dictionary<int, (ICarModel, int)>? _shopCars = null;
[NotMapped]
[DataMember]
[NotMapped]
public Dictionary<int, (ICarModel, int)> ShopCars
{
get
@ -42,7 +44,8 @@ namespace AutomobilePlantDatabaseImplement.Models
}
}
[Required]
[DataMember]
[Required]
public int MaxCountCars { get; set; }
public static Shop Create(AutomobilePlantDatabase context, ShopBindingModel model)

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,26 +1,29 @@
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
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public int MaxCountCars { get; private set; }
public DateTime OpeningDate { get; private set; }
[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;
public Dictionary<int, (ICarModel, int)> ShopCars
[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,13 +50,10 @@ namespace AutomobilePlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMail));
if (service is FormMail form)
{
form.MessageId = (string)(dataGridView.SelectedRows[0].Cells["MessageId"].Value);
form.ShowDialog();
LoadData();
}
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,20 +53,14 @@ namespace AutomobilePlantView
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
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)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormShopSupply>();
form.ShowDialog();
}
private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
@ -114,11 +108,8 @@ namespace AutomobilePlantView
private void sellCarsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
if (service is FormShopSell form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormShopSell>();
form.ShowDialog();
}
private void shopsListToolStripMenuItem_Click(object sender, EventArgs e)
@ -136,11 +127,8 @@ namespace AutomobilePlantView
private void storeCongestionToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopCars));
if (service is FormReportShopCars form)
{
form.ShowDialog();
}
var form = DependencyManager.Instance.Resolve<FormReportShopCars>();
form.ShowDialog();
}
private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e)
@ -151,11 +139,8 @@ namespace AutomobilePlantView
private void listOdOrdersByDatesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders));
if (service is FormReportDateOrders form)
{
form.ShowDialog();
}
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
{
@ -33,18 +25,9 @@ namespace AutomobilePlantView
private void LoadData()
{
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;
}
_logger.LogInformation("Загрузка магазинов");
{
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
@ -61,14 +44,10 @@ 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)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
@ -76,16 +55,11 @@ namespace AutomobilePlantView
{
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)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
LoadData();
}
}
}

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