From 4429dec0c6010eb44a458be18ac07219cce6b4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D0=B1=D0=B5=D0=B5=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Sun, 19 May 2024 20:03:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=208=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/BackUpLogic.cs | 103 +++++ .../Attributes/ColumnAttribute.cs | 31 ++ .../Attributes/GridViewAutoSize.cs | 27 ++ .../BindingModels/BackUpSaveBindingModel.cs | 13 + .../BindingModels/MessageInfoBindingModel.cs | 4 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 14 + .../CarpentryWorkshopContracts.csproj | 8 + .../DI/DependencyManager.cs | 41 ++ .../DI/IDependencyContainer.cs | 20 + .../DI/IImplementationExtension.cs | 14 + .../DI/ServiceDependencyContainer.cs | 62 +++ .../DI/ServiceProviderLoader.cs | 51 +++ .../DI/UnityDependencyContainer.cs | 55 +++ .../StoragesContracts/IBackUpInfo.cs | 14 + .../ViewModels/ClientViewModel.cs | 18 +- .../ViewModels/ComponentViewModel.cs | 14 +- .../ViewModels/ImplementerViewModel.cs | 22 +- .../ViewModels/MessageInfoViewModel.cs | 30 +- .../ViewModels/OrderViewModel.cs | 48 +- .../ViewModels/WoodViewModel.cs | 17 +- .../Models/IMessageInfoModel.cs | 2 +- .../CarpentryWorkshopDatabaseImplement.csproj | 4 + .../DatabaseImplementationExtension.cs | 27 ++ .../Implements/BackUpInfo.cs | 31 ++ ...20240519151003_FourthMigration.Designer.cs | 298 +++++++++++++ .../20240519151003_FourthMigration.cs | 22 + .../Models/Client.cs | 16 +- .../Models/Component.cs | 13 +- .../Models/Implementer.cs | 19 +- .../Models/MessageInfo.cs | 11 +- .../Models/Order.cs | 32 +- .../Models/Wood.cs | 16 +- .../CarpentryWorkshopFileImplement.csproj | 4 + .../FileImplementationExtension.cs | 27 ++ .../Implements/BackUpInfo.cs | 32 ++ .../Models/Client.cs | 19 +- .../Models/Component.cs | 15 +- .../Models/Implementer.cs | 23 +- .../Models/MessageInfo.cs | 26 +- .../Models/Order.cs | 39 +- .../Models/Wood.cs | 18 +- .../CarpentryWorkshopListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 22 + .../ListImplementationExtension.cs | 27 ++ .../Models/MessageInfo.cs | 4 +- .../DataGridViewExtension.cs | 51 +++ .../CarpentryWorkshopView/FormClients.cs | 10 +- .../CarpentryWorkshopView/FormComponents.cs | 35 +- .../CarpentryWorkshopView/FormImplementers.cs | 46 +- .../CarpentryWorkshopView/FormMails.cs | 9 +- .../FormMain.Designer.cs | 19 +- .../CarpentryWorkshopView/FormMain.cs | 417 +++++++++--------- .../CarpentryWorkshopView/FormWood.cs | 64 ++- .../CarpentryWorkshopView/FormWoods.cs | 36 +- .../CarpentryWorkshopView/Program.cs | 99 ++--- 55 files changed, 1603 insertions(+), 540 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/ColumnAttribute.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/GridViewAutoSize.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/BackUpSaveBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/DependencyManager.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/IDependencyContainer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/IImplementationExtension.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceDependencyContainer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceProviderLoader.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/DI/UnityDependencyContainer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopFileImplement/FileImplementationExtension.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/BackUpInfo.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/BackUpInfo.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/ListImplementationExtension.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/DataGridViewExtension.cs diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..ce85895 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,103 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopDataModels; +using Microsoft.Extensions.Logging; +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 CarpentryWorkshopBusinessLogic.BusinessLogics +{ + 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(BackUpSaveBindingModel 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/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/ColumnAttribute.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..f735b4e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/GridViewAutoSize.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..adb540e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/BackUpSaveBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..d398bbc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/MessageInfoBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/MessageInfoBindingModel.cs index 860e22d..973fcbd 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/MessageInfoBindingModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace CarpentryWorkshopContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..bcd86b2 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using CarpentryWorkshopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj index 6ef3d42..ce0035a 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj @@ -6,6 +6,14 @@ enable + + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/DI/DependencyManager.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..78b9928 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/DependencyManager.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _lockObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_lockObject) { _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/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IDependencyContainer.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..45b20f1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IImplementationExtension.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..b0b79d6 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceDependencyContainer.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..7a48637 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/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 CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceProviderLoader.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..8feff12 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.DI +{ + public class ServiceProviderLoader + { + 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/CarpentryWorkshop/CarpentryWorkshopContracts/DI/UnityDependencyContainer.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..e130ef0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; + +namespace CarpentryWorkshopContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var logger = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(logger)); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IBackUpInfo.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..40880eb --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ClientViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ClientViewModel.cs index b393731..618679e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ClientViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,16 @@ namespace CarpentryWorkshopContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "ФИО клиента", width:150)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs index 31f15c0..c42c97e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace CarpentryWorkshopContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] + public double Cost { get; set; } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs index f7f6e92..94109f7 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace CarpentryWorkshopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "ФИО", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Qualification { get; set; } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/MessageInfoViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/MessageInfoViewModel.cs index 2a84ecc..7d2dc22 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/MessageInfoViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,25 @@ namespace CarpentryWorkshopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [Column(visible: false)] + public int? ClientId { get; set; } - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + [Column(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } + [Column(title: "Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; + [Column(title: "Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs index 6340ad6..7d05aea 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Enums; using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; @@ -11,34 +12,37 @@ namespace CarpentryWorkshopContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int WoodId { get; set; } - public int ClientId { get; set; } - public int? ImplementerId { get; set; } + [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + [Column(visible: false)] + public int WoodId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] - public string WoodName { get; set; } = string.Empty; + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string WoodName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs index 3960f0c..559d445 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs @@ -1,4 +1,5 @@ -using CarpentryWorkshopDataModels.Models; +using CarpentryWorkshopContracts.Attributes; +using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,13 @@ namespace CarpentryWorkshopContracts.ViewModels { public class WoodViewModel : IWoodModel { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string WoodName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary WoodComponents { get; set; } = new(); + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string WoodName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary WoodComponents { get; set; } = new(); } } diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IMessageInfoModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IMessageInfoModel.cs index ea0e453..aa07ad7 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IMessageInfoModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace CarpentryWorkshopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabaseImplement.csproj b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabaseImplement.csproj index 96db0ca..9c238ab 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabaseImplement.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/DatabaseImplementationExtension.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..e810176 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarpentryWorkshopContracts.DI; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDatabaseImplement +{ + 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/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/BackUpInfo.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..6ec1b1c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,31 @@ +using CarpentryWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new CarpentryWorkshopDatabase(); + 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/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.Designer.cs new file mode 100644 index 0000000..433d3ac --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.Designer.cs @@ -0,0 +1,298 @@ +// +using System; +using CarpentryWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarpentryWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(CarpentryWorkshopDatabase))] + [Migration("20240519151003_FourthMigration")] + partial class FourthMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("WoodId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("WoodId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("WoodName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Woods"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("WoodId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("WoodId"); + + b.ToTable("WoodComponents"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood") + .WithMany("Orders") + .HasForeignKey("WoodId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Wood"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b => + { + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("WoodComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood") + .WithMany("Components") + .HasForeignKey("WoodId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Wood"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("WoodComponents"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.cs new file mode 100644 index 0000000..7211f2c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240519151003_FourthMigration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarpentryWorkshopDatabaseImplement.Migrations +{ + /// + public partial class FourthMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Client.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Client.cs index a8dcdb6..0cb27b4 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Client.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Client.cs @@ -8,21 +8,27 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace CarpentryWorkshopDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; [Required] - public string Email { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Component.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Component.cs index 5be7e93..f2c7f29 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Component.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Component.cs @@ -6,20 +6,25 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarpentryWorkshopDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public string ComponentName { get; private set; } = string.Empty; [Required] - public double Cost { get; set; } + [DataMember] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List WoodComponents { get; set; } = new(); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs index 3041ffe..6b428d4 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs @@ -8,20 +8,27 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace CarpentryWorkshopDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Qualification { get; private set; } [ForeignKey("ImplementerId")] public virtual List Orders { get; set; } = new(); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/MessageInfo.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/MessageInfo.cs index 4bbff6d..022e9cf 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -5,15 +5,18 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarpentryWorkshopDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -53,5 +56,7 @@ namespace CarpentryWorkshopDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs index bf867a5..a8298c2 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs @@ -7,35 +7,47 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarpentryWorkshopDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public int WoodId { get; set; } + [DataMember] + public int WoodId { get; set; } [Required] - public int ClientId { get; set; } - public int? ImplementerId { get; private set; } + [DataMember] + public int ClientId { get; set; } + + [DataMember] + public int? ImplementerId { get; private set; } [Required] - public int Count { get; set; } + [DataMember] + public int Count { get; set; } [Required] - public double Sum { get; set; } + [DataMember] + public double Sum { get; set; } [Required] - public OrderStatus Status { get; set; } + [DataMember] + public OrderStatus Status { get; set; } [Required] - public DateTime DateCreate { get; set; } + [DataMember] + public DateTime DateCreate { get; set; } - public DateTime? DateImplement { get; set; } + [DataMember] + public DateTime? DateImplement { get; set; } public virtual Wood Wood { get; set; } public virtual Client Client { get; set; } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Wood.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Wood.cs index 79278e0..4c08b54 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Wood.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Wood.cs @@ -6,25 +6,31 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CarpentryWorkshopDatabaseImplement.Models { - public class Wood : IWoodModel + [DataContract] + public class Wood : IWoodModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string WoodName { get; set; } = string.Empty; + [DataMember] + public string WoodName { get; set; } = string.Empty; [Required] - public double Price { get; set; } + [DataMember] + public double Price { get; set; } private Dictionary? _woodComponents = null; [NotMapped] - public Dictionary WoodComponents + [DataMember] + public Dictionary WoodComponents { get { diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/CarpentryWorkshopFileImplement.csproj b/CarpentryWorkshop/CarpentryWorkshopFileImplement/CarpentryWorkshopFileImplement.csproj index 6003264..e536179 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/CarpentryWorkshopFileImplement.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/CarpentryWorkshopFileImplement.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/FileImplementationExtension.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..fe9b73c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarpentryWorkshopContracts.DI; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopFileImplement +{ + 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/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/BackUpInfo.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ef28576 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using CarpentryWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopFileImplement.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/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Client.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Client.cs index aaa875d..5fbccbd 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Client.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Client.cs @@ -4,18 +4,27 @@ using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + + [DataMember] + public string Email { get; private set; } = string.Empty; + + [DataMember] + public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Component.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Component.cs index 61b7cee..cc226d2 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Component.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Component.cs @@ -4,17 +4,24 @@ using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel? model) { diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs index 7878d65..fea4a1d 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs @@ -4,19 +4,30 @@ using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + + [DataMember] + public string Password { get; private set; } = string.Empty; + + [DataMember] + public int WorkExperience { get; private set; } + + [DataMember] + public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel model) { diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/MessageInfo.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/MessageInfo.cs index 58c93ef..659d92f 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/MessageInfo.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/MessageInfo.cs @@ -4,25 +4,33 @@ using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -75,5 +83,7 @@ namespace CarpentryWorkshopFileImplement.Models new XAttribute("MessageId", MessageId), new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery)); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs index 4f86775..8359737 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs @@ -6,23 +6,42 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - public int WoodId { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public int WoodId { get; private set; } + + [DataMember] + public int ClientId { get; private set; } + + [DataMember] + public int? ImplementerId { get; private set; } + + [DataMember] + public int Count { get; private set; } + + [DataMember] + public double Sum { get; private set; } + + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + [DataMember] + public DateTime? DateImplement { get; private set; } public virtual Wood Wood { get; set; } public virtual Client Client { get; set; } diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Wood.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Wood.cs index 7bbfeb5..f602bc1 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Wood.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Wood.cs @@ -4,22 +4,30 @@ using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace CarpentryWorkshopFileImplement.Models { - public class Wood : IWoodModel + [DataContract] + public class Wood : IWoodModel { - public int Id { get; private set; } - public string WoodName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string WoodName { get; private set; } = string.Empty; + + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _woodComponents = null; - public Dictionary WoodComponents { + [DataMember] + public Dictionary WoodComponents { get { if (_woodComponents == null) { diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj index 319d159..9c00e95 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/BackUpInfo.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..2462f64 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using CarpentryWorkshopContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.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/CarpentryWorkshop/CarpentryWorkshopListImplement/ListImplementationExtension.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..1221098 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using CarpentryWorkshopContracts.DI; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement +{ + public class ListImplementationExtension + { + 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/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/MessageInfo.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/MessageInfo.cs index 59d762f..2b975c1 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/MessageInfo.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/MessageInfo.cs @@ -49,5 +49,7 @@ namespace CarpentryWorkshopListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/DataGridViewExtension.cs b/CarpentryWorkshop/CarpentryWorkshopView/DataGridViewExtension.cs new file mode 100644 index 0000000..af5d9a1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using CarpentryWorkshopContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopView +{ + 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; + } + } + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormClients.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormClients.cs index 795e593..bba11ae 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormClients.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormClients.cs @@ -33,14 +33,8 @@ namespace CarpentryWorkshopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) { diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs index 442cc42..eefe606 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs @@ -1,5 +1,6 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using CarpentryWorkshopContracts.SearchModels; using Microsoft.Extensions.Logging; using System; @@ -33,14 +34,8 @@ namespace CarpentryWorkshopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { @@ -51,13 +46,10 @@ namespace CarpentryWorkshopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } @@ -65,14 +57,11 @@ namespace CarpentryWorkshopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs index fdb1708..b551321 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs @@ -1,5 +1,6 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,8 @@ namespace CarpentryWorkshopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка исполнителей"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) { @@ -52,31 +47,22 @@ namespace CarpentryWorkshopView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void buttonUpd_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } private void buttonDel_Click(object sender, EventArgs e) { diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMails.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMails.cs index 5cc9761..125be2e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMails.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMails.cs @@ -27,14 +27,7 @@ namespace CarpentryWorkshopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs index f0ae5d6..faa9194 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -44,13 +44,14 @@ ButtonCreateOrder = new Button(); ButtonIssuedOrder = new Button(); ButtonRef = new Button(); + создатьБекапToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem, создатьБекапToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1389, 24); @@ -67,28 +68,28 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(149, 22); + компонентыToolStripMenuItem.Size = new Size(180, 22); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // изделияToolStripMenuItem // изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(149, 22); + изделияToolStripMenuItem.Size = new Size(180, 22); изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(149, 22); + клиентыToolStripMenuItem.Size = new Size(180, 22); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(149, 22); + исполнителиToolStripMenuItem.Size = new Size(180, 22); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; // @@ -183,6 +184,13 @@ ButtonRef.UseVisualStyleBackColor = true; ButtonRef.Click += ButtonRef_Click; // + // создатьБекапToolStripMenuItem + // + создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + создатьБекапToolStripMenuItem.Size = new Size(97, 20); + создатьБекапToolStripMenuItem.Text = "Создать бекап"; + создатьБекапToolStripMenuItem.Click += создатьБекапToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -222,5 +230,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs index 591845f..cc2bce7 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -1,6 +1,7 @@ using CarpentryWorkshopBusinessLogic.BusinessLogics; using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using CarpentryWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -15,235 +16,227 @@ using System.Windows.Forms; namespace CarpentryWorkshopView { - public partial class FormMain : Form - { - private readonly ILogger _logger; + public partial class FormMain : Form + { + private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; + private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; + private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } + private readonly IBackUpLogic _backUpLogic; - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - - try - { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["WoodId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } - - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } - - private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - - private void изделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormWoods)); - - if (service is FormWoods form) - { - form.ShowDialog(); - } - } - - private void письмаToolStripMenuItem_Click(object sender, EventArgs e) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + _backUpLogic = backUpLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try { - form.ShowDialog(); + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void изделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void письмаToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id, - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveComponentsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } - private void ComponentWoodsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportWoodComponents)); - if (service is FormReportWoodComponents form) - { - form.ShowDialog(); - } - } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + private void ComponentWoodsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } - } + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs index 9213665..91f3113 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs @@ -1,5 +1,6 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using CarpentryWorkshopContracts.SearchModels; using CarpentryWorkshopDataModels.Models; using Microsoft.Extensions.Logging; @@ -80,27 +81,23 @@ namespace CarpentryWorkshopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWoodComponent)); - if (service is FormWoodComponent form) - { - if (form.ShowDialog() == DialogResult.OK) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - if (_woodComponents.ContainsKey(form.Id)) - { - _woodComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _woodComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } - + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_woodComponents.ContainsKey(form.Id)) + { + _woodComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _woodComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } @@ -108,23 +105,20 @@ namespace CarpentryWorkshopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWoodComponent)); - if (service is FormWoodComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _woodComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - _woodComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _woodComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; } - } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _woodComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs index 6127444..ed8fe0b 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs @@ -1,5 +1,6 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,15 +34,8 @@ namespace CarpentryWorkshopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["WoodComponents"].Visible = false; - dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка изделий"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { @@ -52,13 +46,10 @@ namespace CarpentryWorkshopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWood)); - if (service is FormWood form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } @@ -66,14 +57,11 @@ namespace CarpentryWorkshopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWood)); - if (service is FormWood form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs index 513aae9..705cfda 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs @@ -4,6 +4,7 @@ using CarpentryWorkshopBusinessLogic.OfficePackage; using CarpentryWorkshopBusinessLogic.OfficePackage.Implements; using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.DI; using CarpentryWorkshopContracts.StoragesContracts; using CarpentryWorkshopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; @@ -15,26 +16,17 @@ namespace CarpentryWorkshopView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// [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 + try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel - { + { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, @@ -44,58 +36,53 @@ namespace CarpentryWorkshopView }); // 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, " "); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { + Application.Run(DependencyManager.Instance.Resolve()); + } + private static void InitDependency() + { + 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(); + 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(); - 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(true); - 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(); + 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