diff --git a/RenovationWork/ImplementationExtensions/RenovationWorkContracts.dll b/RenovationWork/ImplementationExtensions/RenovationWorkContracts.dll new file mode 100644 index 0000000..537d74d Binary files /dev/null and b/RenovationWork/ImplementationExtensions/RenovationWorkContracts.dll differ diff --git a/RenovationWork/ImplementationExtensions/RenovationWorkDataModels.dll b/RenovationWork/ImplementationExtensions/RenovationWorkDataModels.dll new file mode 100644 index 0000000..4e4c1d8 Binary files /dev/null and b/RenovationWork/ImplementationExtensions/RenovationWorkDataModels.dll differ diff --git a/RenovationWork/ImplementationExtensions/RenovationWorkDatabaseImplement.dll b/RenovationWork/ImplementationExtensions/RenovationWorkDatabaseImplement.dll new file mode 100644 index 0000000..73ce218 Binary files /dev/null and b/RenovationWork/ImplementationExtensions/RenovationWorkDatabaseImplement.dll differ diff --git a/RenovationWork/ImplementationExtensions/RenovationWorkFileImplement.dll b/RenovationWork/ImplementationExtensions/RenovationWorkFileImplement.dll new file mode 100644 index 0000000..068dd2b Binary files /dev/null and b/RenovationWork/ImplementationExtensions/RenovationWorkFileImplement.dll differ diff --git a/RenovationWork/ImplementationExtensions/RenovationWorkListImplement.dll b/RenovationWork/ImplementationExtensions/RenovationWorkListImplement.dll new file mode 100644 index 0000000..2f8562a Binary files /dev/null and b/RenovationWork/ImplementationExtensions/RenovationWorkListImplement.dll differ diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/BackUpLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..1f179ee --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.StorageContracts; +using RenovationWorkDataModels; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.BusinessLogic +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/RenovationWork/RenovationWorkContracts/Attributes/ColumnAttribute.cs b/RenovationWork/RenovationWorkContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..5fbbc5d --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + 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 ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/RenovationWork/RenovationWorkContracts/Attributes/GridViewAutoSize.cs b/RenovationWork/RenovationWorkContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..369882f --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/BackUpSaveBinidngModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..8cfacee --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/MessageInfoBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/MessageInfoBindingModel.cs index fac13a2..ce08f7d 100644 --- a/RenovationWork/RenovationWorkContracts/BindingModels/MessageInfoBindingModel.cs +++ b/RenovationWork/RenovationWorkContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace RenovationWorkContracts.BindingModels public DateTime DateDelivery { get; set; } public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public int Id => throw new NotImplementedException(); } } diff --git a/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IBackUpLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..a81a807 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using RenovationWorkContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/RenovationWork/RenovationWorkContracts/DI/DependencyManager.cs b/RenovationWork/RenovationWorkContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..78b1ba4 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/RenovationWork/RenovationWorkContracts/DI/IDependencyContainer.cs b/RenovationWork/RenovationWorkContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..188fde0 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.DI +{ + public interface IDependencyContainer + { + /// + /// Регистрация логгера + /// + /// + void AddLogging(Action configure); + + /// + /// Добавление зависимости + /// + /// + /// + /// + void RegisterType(bool isSingle) where U : class, T where T : class; + + /// + /// Добавление зависимости + /// + /// + /// + void RegisterType(bool isSingle) where T : class; + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + T Resolve(); + } +} diff --git a/RenovationWork/RenovationWorkContracts/DI/IImplementationExtension.cs b/RenovationWork/RenovationWorkContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..7a5c461 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/RenovationWork/RenovationWorkContracts/DI/ServiceDependencyContainer.cs b/RenovationWork/RenovationWorkContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..17973a5 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/RenovationWork/RenovationWorkContracts/DI/ServiceProviderLoader.cs b/RenovationWork/RenovationWorkContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..e0911b7 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj index 96ab30f..6b1e6c8 100644 --- a/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj +++ b/RenovationWork/RenovationWorkContracts/RenovationWorkContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/RenovationWork/RenovationWorkContracts/StorageContracts/IBackUpInfo.cs b/RenovationWork/RenovationWorkContracts/StorageContracts/IBackUpInfo.cs new file mode 100644 index 0000000..842b36c --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StorageContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.StorageContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/ClientViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ClientViewModel.cs index 5f014ed..9e13ef6 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/ClientViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Models; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,16 @@ namespace RenovationWorkContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs index e230a21..6d5da61 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Models; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,12 @@ namespace RenovationWorkContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название комплектующего", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - + [Column("Цена", width: 80)] public double Cost { get; set; } - [DisplayName("Название изделия")] - public string RepairName { get; set; } = string.Empty; } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs index c4d850f..b4f7ed5 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Models; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace RenovationWorkContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/MessageInfoModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/MessageInfoModel.cs index 61c415e..0bdb911 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/MessageInfoModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/MessageInfoModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Models; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,16 +11,23 @@ namespace RenovationWorkContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + + [Column("Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + + [Column("Заголовок", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + + [Column("Текст", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs index 28155c4..0f95302 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Enums; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Enums; using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; @@ -11,29 +12,30 @@ namespace RenovationWorkContracts.ViewModels { public class OrderViewModel : IOrderModel { - public int ClientId { get; set; } - public int? ImplementerId { get; set; } - public int RepairId { get; set; } - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } - [DisplayName("Ремонт")] - public string RepairName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] - public string ImplementerFIO { get; set; } = string.Empty; - - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } - - [DisplayName("Фамилия клиента")] + [Column(visible: false)] + public int RepairId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column("Данные клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column("Данные исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column("Компьютер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string RepairName { get; set; } = string.Empty; + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column("Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column("Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } + } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs index c416b16..218bcc8 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/RepairViewModel.cs @@ -1,4 +1,5 @@ -using RenovationWorkDataModels.Models; +using RenovationWorkContracts.Attributes; +using RenovationWorkDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,21 @@ namespace RenovationWorkContracts.ViewModels { public class RepairViewModel : IRepairModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название ремонта")] + + [Column("Название компьютера", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string RepairName { get; set; } = string.Empty; - [DisplayName("Цена")] + + [Column("Цена", width: 100)] public double Price { get; set; } - public Dictionary RepairComponents { get; set; } = new(); + + [Column(visible: false)] + public Dictionary RepairComponents + { + get; + set; + } = new(); } } diff --git a/RenovationWork/RenovationWorkDataModels/Models/IMessageInfoModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IMessageInfoModel.cs index bea1c89..d4e6654 100644 --- a/RenovationWork/RenovationWorkDataModels/Models/IMessageInfoModel.cs +++ b/RenovationWork/RenovationWorkDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace RenovationWorkDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/RenovationWork/RenovationWorkDatabaseImplement/DatabaseImplementationExtension.cs b/RenovationWork/RenovationWorkDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..25fc2dc --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using RenovationWorkContracts.DI; +using RenovationWorkContracts.StorageContracts; +using RenovationWorkDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Implements/BackUpInfo.cs b/RenovationWork/RenovationWorkDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..e44bed9 --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using RenovationWorkContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new RenovationWorkDatabase(); + return context.Set().ToList(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Model/MessageInfo.cs b/RenovationWork/RenovationWorkDatabaseImplement/Model/MessageInfo.cs index e5f41ca..ee2e19e 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/Model/MessageInfo.cs +++ b/RenovationWork/RenovationWorkDatabaseImplement/Model/MessageInfo.cs @@ -49,5 +49,7 @@ namespace RenovationWorkDatabaseImplement.Model Subject = Subject, Body = Body }; + + public int Id => throw new NotImplementedException(); } } diff --git a/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.csproj b/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.csproj index 1011373..60788a7 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.csproj +++ b/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/RenovationWork/RenovationWorkFileImplement/FileImplementationExtension.cs b/RenovationWork/RenovationWorkFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..0249184 --- /dev/null +++ b/RenovationWork/RenovationWorkFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using RenovationWorkContracts.DI; +using RenovationWorkContracts.StorageContracts; +using RenovationWorkFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/RenovationWork/RenovationWorkFileImplement/Implements/BackUpInfo.cs b/RenovationWork/RenovationWorkFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ba8f773 --- /dev/null +++ b/RenovationWork/RenovationWorkFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,35 @@ +using RenovationWorkContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/RenovationWork/RenovationWorkFileImplement/Models/MessageInfo.cs b/RenovationWork/RenovationWorkFileImplement/Models/MessageInfo.cs index 3850c25..46769b8 100644 --- a/RenovationWork/RenovationWorkFileImplement/Models/MessageInfo.cs +++ b/RenovationWork/RenovationWorkFileImplement/Models/MessageInfo.cs @@ -76,6 +76,8 @@ namespace RenovationWorkFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/RenovationWork/RenovationWorkFileImplement/RenovationWorkFileImplement.csproj b/RenovationWork/RenovationWorkFileImplement/RenovationWorkFileImplement.csproj index 2d896a8..6dfa58a 100644 --- a/RenovationWork/RenovationWorkFileImplement/RenovationWorkFileImplement.csproj +++ b/RenovationWork/RenovationWorkFileImplement/RenovationWorkFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/RenovationWork/RenovationWorkListImplement/Implements/BackUpInfo.cs b/RenovationWork/RenovationWorkListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..0d08830 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using RenovationWorkContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/ListImplementationExtension.cs b/RenovationWork/RenovationWorkListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..21a1d95 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using RenovationWorkContracts.DI; +using RenovationWorkContracts.StorageContracts; +using RenovationWorkListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Models/MessageInfo.cs b/RenovationWork/RenovationWorkListImplement/Models/MessageInfo.cs index 89b5c61..c0cb3f4 100644 --- a/RenovationWork/RenovationWorkListImplement/Models/MessageInfo.cs +++ b/RenovationWork/RenovationWorkListImplement/Models/MessageInfo.cs @@ -42,5 +42,7 @@ namespace RenovationWorkListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj index 2d896a8..6dfa58a 100644 --- a/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj +++ b/RenovationWork/RenovationWorkListImplement/RenovationWorkListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/RenovationWork/RenovationWorkView/DataGridViewExtension.cs b/RenovationWork/RenovationWorkView/DataGridViewExtension.cs new file mode 100644 index 0000000..949a34f --- /dev/null +++ b/RenovationWork/RenovationWorkView/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using RenovationWorkContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkView +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? 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; + } + } + } + } + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormClients.cs b/RenovationWork/RenovationWorkView/FormClients.cs index c0cbbfb..df6347d 100644 --- a/RenovationWork/RenovationWorkView/FormClients.cs +++ b/RenovationWork/RenovationWorkView/FormClients.cs @@ -35,13 +35,7 @@ namespace RenovationWorkView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/RenovationWork/RenovationWorkView/FormComponents.cs b/RenovationWork/RenovationWorkView/FormComponents.cs index 55f8d29..b8c7987 100644 --- a/RenovationWork/RenovationWorkView/FormComponents.cs +++ b/RenovationWork/RenovationWorkView/FormComponents.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.DI; using RenovationWorkView; using System; using System.Collections.Generic; @@ -56,7 +57,7 @@ namespace PrecastConcretePlantView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { @@ -70,7 +71,7 @@ namespace PrecastConcretePlantView { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { diff --git a/RenovationWork/RenovationWorkView/FormImplementers.cs b/RenovationWork/RenovationWorkView/FormImplementers.cs index dbdabf7..ab22965 100644 --- a/RenovationWork/RenovationWorkView/FormImplementers.cs +++ b/RenovationWork/RenovationWorkView/FormImplementers.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; +using PrecastConcretePlantView; using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -53,7 +55,7 @@ namespace RenovationWorkView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -67,7 +69,7 @@ namespace RenovationWorkView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/RenovationWork/RenovationWorkView/FormMain.Designer.cs b/RenovationWork/RenovationWorkView/FormMain.Designer.cs index 843fdb4..33d6c87 100644 --- a/RenovationWork/RenovationWorkView/FormMain.Designer.cs +++ b/RenovationWork/RenovationWorkView/FormMain.Designer.cs @@ -41,6 +41,7 @@ this.запускРаботыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.письмаToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьBackupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); @@ -59,7 +60,8 @@ this.отчетыToolStripMenuItem, this.запускРаботыToolStripMenuItem, this.письмаToolStripMenuItem, - this.письмаToolStripMenuItem1}); + this.письмаToolStripMenuItem1, + this.создатьBackupToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); @@ -156,6 +158,13 @@ this.письмаToolStripMenuItem1.Text = "Письма"; this.письмаToolStripMenuItem1.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); // + // создатьBackupToolStripMenuItem + // + this.создатьBackupToolStripMenuItem.Name = "создатьBackupToolStripMenuItem"; + this.создатьBackupToolStripMenuItem.Size = new System.Drawing.Size(130, 24); + this.создатьBackupToolStripMenuItem.Text = "Cоздать backup"; + this.создатьBackupToolStripMenuItem.Click += new System.EventHandler(this.CreateBackupToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -279,5 +288,6 @@ private ToolStripMenuItem запускРаботыToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem1; + private ToolStripMenuItem создатьBackupToolStripMenuItem; } } \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormMain.cs b/RenovationWork/RenovationWorkView/FormMain.cs index da407a1..300a7a4 100644 --- a/RenovationWork/RenovationWorkView/FormMain.cs +++ b/RenovationWork/RenovationWorkView/FormMain.cs @@ -2,6 +2,7 @@ using RenovationWorkBusinessLogic.BusinessLogic; using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.DI; using RenovationWorkDataModels.Enums; using RenovationWorkView; using System; @@ -26,14 +27,16 @@ namespace PrecastConcretePlantView private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + public FormMain(ILogger 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) @@ -66,7 +69,7 @@ namespace PrecastConcretePlantView private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponents form) { @@ -76,7 +79,7 @@ namespace PrecastConcretePlantView private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepairs)); + var service = DependencyManager.Instance.Resolve(); if (service is FormRepairs form) { @@ -86,7 +89,7 @@ namespace PrecastConcretePlantView private void CreateOrderButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { @@ -96,7 +99,8 @@ namespace PrecastConcretePlantView } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); + if (service is FormClients form) { form.ShowDialog(); @@ -104,7 +108,8 @@ namespace PrecastConcretePlantView } private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); + if (service is FormImplementers form) { form.ShowDialog(); @@ -227,7 +232,7 @@ namespace PrecastConcretePlantView } private void ComponentProductsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportRepairComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportRepairComponents form) { form.ShowDialog(); @@ -236,7 +241,7 @@ namespace PrecastConcretePlantView private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -249,17 +254,43 @@ namespace PrecastConcretePlantView private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { + } + private void CreateBackupToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + 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 запускРаботыToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork((DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); + var service = DependencyManager.Instance.Resolve(); + if (service is FormMail form) { form.ShowDialog(); diff --git a/RenovationWork/RenovationWorkView/FormRepair.cs b/RenovationWork/RenovationWorkView/FormRepair.cs index 7c9c87f..ca8cf5e 100644 --- a/RenovationWork/RenovationWorkView/FormRepair.cs +++ b/RenovationWork/RenovationWorkView/FormRepair.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using Microsoft.Extensions.Logging; using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.DI; using RenovationWorkContracts.SeatchModels; using RenovationWorkDataModels.Models; using RenovationWorkView; @@ -86,7 +87,7 @@ namespace PrecastConcretePlantView } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormRepairComponent form) { @@ -118,7 +119,7 @@ namespace PrecastConcretePlantView { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormRepairComponent form) { diff --git a/RenovationWork/RenovationWorkView/FormRepairs.cs b/RenovationWork/RenovationWorkView/FormRepairs.cs index 6f01c74..d1c8ddc 100644 --- a/RenovationWork/RenovationWorkView/FormRepairs.cs +++ b/RenovationWork/RenovationWorkView/FormRepairs.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using Microsoft.Extensions.Logging; using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.DI; using RenovationWorkView; namespace PrecastConcretePlantView @@ -57,7 +58,7 @@ namespace PrecastConcretePlantView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + var service = DependencyManager.Instance.Resolve(); if (service is FormRepair form) { @@ -71,7 +72,7 @@ namespace PrecastConcretePlantView { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + var service = DependencyManager.Instance.Resolve(); if (service is FormRepair form) { diff --git a/RenovationWork/RenovationWorkView/Program.cs b/RenovationWork/RenovationWorkView/Program.cs index 8663061..f02334c 100644 --- a/RenovationWork/RenovationWorkView/Program.cs +++ b/RenovationWork/RenovationWorkView/Program.cs @@ -11,25 +11,22 @@ using RenovationWorkBusinessLogic.OfficePackage.Implements; using RenovationWorkBusinessLogic.OfficePackage; using RenovationWorkBusinessLogic.MailWorker; using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.DI; namespace RenovationWorkView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - [STAThread] static void Main() { + // 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(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -40,65 +37,53 @@ namespace RenovationWorkView PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) }); - // - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 1000); + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, " "); + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, "Error"); } - - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddSingleton(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file