вроде готово

This commit is contained in:
sardq 2024-05-16 18:30:57 +04:00
parent ecf2e10885
commit 8f1bcf00fc
16 changed files with 148 additions and 54 deletions

View File

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

View File

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

View File

@ -12,14 +12,16 @@
public GridViewAutoSize GridViewAutoSize { get; private set; }
public bool IsUseAutoSize { get; private set; }
public string Format { get; private set; }
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;
}
}
}

View File

@ -29,6 +29,14 @@ namespace PlumbingRepairContracts.DI
}
// регистрируем зависимости
ext.RegisterServices();
var bsExtensions = ServiceProviderLoader.GetBusinessLogicImplementationExtensions();
if (bsExtensions == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей бизнес-логики");
}
// регистрируем зависимости
bsExtensions.RegisterServices();
}
/// <summary>

View File

@ -0,0 +1,7 @@
namespace PlumbingRepairContracts.DI
{
public interface IImplementationBusinessLogicExtension
{
public void RegisterServices();
}
}

View File

@ -36,6 +36,33 @@ namespace PlumbingRepairContracts.DI
}
return source;
}
public static IImplementationBusinessLogicExtension? GetBusinessLogicImplementationExtensions()
{
IImplementationBusinessLogicExtension? source = null;
var files = Directory.GetFiles(TryGetBusinessLogicImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass && typeof(IImplementationBusinessLogicExtension).IsAssignableFrom(t))
{
source = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!;
break;
}
}
}
return source;
}
private static string TryGetBusinessLogicImplementationExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetDirectories("BusinessLogicImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicImplementationExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\BusinessLogicImplementationExtensions";
}
private static string TryGetImplementationExtensionsFolder()
{

View File

@ -12,7 +12,7 @@ namespace PlumbingRepairContracts.ViewModels
public int? ClientId { get; set; }
[Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
[Column(title: "Дата отправления", width: 150)]
[Column(title: "Дата отправления", width: 150, format: "Date: dd/MM/yyyy")]
public DateTime DateDelivery { get; set; }
[Column(title: "Заголовок", width: 150)]
public string Subject { get; set; } = string.Empty;

View File

@ -36,10 +36,10 @@ namespace PlumbingRepairContracts.ViewModels
[Column(title: "Статус", width: 150)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Column(title: "Дата создания", width: 150)]
[Column(title: "Дата создания", width: 150, format: "Date: dd/MM/yyyy")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[Column(title: "Дата выполнения", width: 150)]
[Column(title: "Дата выполнения", width: 150, format: "Date: dd/MM/yyyy")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -1,20 +1,22 @@
using PlumbingRepairDataModels.Models;
using PlumbingRepairContracts.Attributes;
using PlumbingRepairDataModels.Models;
using System.ComponentModel;
namespace PlumbingRepairContracts.ViewModels
{
public class ShopViewModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Название магазина")]
[Column(title: "Название магазина", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес")]
[Column(title: "Адрес", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Address { get; set; } = string.Empty;
[DisplayName("Максимальное количество работ")]
[Column(title: "Максимальное количество работ", width: 150)]
public int maxCountWorks { get; set; }
[DisplayName("Дата открытия")]
[Column(title: "Дата открытия", width: 150, format: "Date: dd/MM/yyyy")]
public DateTime DateOpening { get; set; }
public Dictionary<int, (IWorkModel, int)> ShopWorks { get; set; } = new();

View File

@ -4,25 +4,33 @@ using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace PlumbingRepairDatabaseImplement.Models
{
[DataContract]
public class Shop
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string ShopName { get; set; } = string.Empty;
[Required]
[DataMember]
public string Address { get; set; } = string.Empty;
[Required]
[DataMember]
public DateTime DateOpening { get; set; }
[Required]
[DataMember]
public int maxCountWorks { get; set; }
private Dictionary<int, (IWorkModel, int)>? _shopWorks = null;
[NotMapped]
[DataMember]
public Dictionary<int, (IWorkModel, int)> ShopWorks
{
get

View File

@ -24,6 +24,7 @@ namespace PlumbingRepairDatabaseImplement.Models
private Dictionary<int, (IComponentModel, int)>? _workComponents = null;
[NotMapped]
[DataMember]
public Dictionary<int, (IComponentModel, int)> WorkComponents
{
get

View File

@ -1,22 +1,27 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace PlumbingRepairFileImplement.Models
{
[DataContract]
public class Shop : IShopModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ShopName { get; private set; } = string.Empty;
[DataMember]
public string Address { get; private set; } = string.Empty;
[DataMember]
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> Works { get; private set; } = new();
private Dictionary<int, (IWorkModel, int)>? _shopWorks = null;
[DataMember]
public Dictionary<int, (IWorkModel, int)> ShopWorks
{
get

View File

@ -19,7 +19,7 @@ namespace PlumbingRepairFileImplement.Models
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _workComponents = null;
[DataMember]
public Dictionary<int, (IComponentModel, int)> WorkComponents
{
get

View File

@ -1,20 +1,24 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using System.Runtime.Serialization;
namespace PlumbingRepairListImplement.Models
{
[DataContract]
public class Shop
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ShopName { get; private set; } = string.Empty;
[DataMember]
public string Address { get; private set; } = string.Empty;
[DataMember]
public DateTime DateOpening { get; private set; }
[DataMember]
public Dictionary<int, (IWorkModel, int)> ShopWorks { get; private set; } = new Dictionary<int, (IWorkModel, int)>();
[DataMember]
public int maxCountWorks { get; private set; }
public static Shop? Create(ShopBindingModel? model)

View File

@ -14,7 +14,7 @@ namespace PlumbingRepairListImplement.Models
public string WorkName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
[DataMember]
public Dictionary<int, (IComponentModel, int)> WorkComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Work? Create(WorkBindingModel? model)

View File

@ -57,16 +57,6 @@ namespace PlumbingRepairView
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<IWorkLogic, WorkLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
@ -80,13 +70,15 @@ namespace PlumbingRepairView
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormWork>();
DependencyManager.Instance.RegisterType<FormWorks>();
DependencyManager.Instance.RegisterType<FormWorkComponent>();
DependencyManager.Instance.RegisterType<FormReportShopWorks>();
DependencyManager.Instance.RegisterType<FormReportWorkComponents>();
DependencyManager.Instance.RegisterType<FormReportOrders>();
DependencyManager.Instance.RegisterType<FormClients>();
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormMail>();
DependencyManager.Instance.RegisterType<FormMails>();
}
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
}