From da7f9c64e9d09725a6b7d393e5c9ab47556821ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 15 May 2023 21:17:32 +0300 Subject: [PATCH] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../BusinessLogics/BackUpLogic.cs | 103 ++++++++++++++++++ .../Attributes/ColumnAttribute.cs | 31 ++++++ .../Attributes/GridViewAutoSize.cs | 27 +++++ .../AutomobilePlantContracts.csproj | 6 + .../BindingModels/BackUpSaveBinidngModel.cs | 13 +++ .../BindingModels/MessageInfoBindingModel.cs | 2 + .../BusinessLogicsContracts/IBackUpLogic.cs | 15 +++ .../DI/DependencyManager.cs | 67 ++++++++++++ .../DI/IDependencyContainer.cs | 40 +++++++ .../DI/IImplementationExtension.cs | 17 +++ .../DI/ServiceDependencyContainer.cs | 62 +++++++++++ .../DI/ServiceProviderLoader.cs | 55 ++++++++++ .../DI/UnityServiceContainer.cs | 59 ++++++++++ .../StoragesContracts/IBackUpInfo.cs | 15 +++ .../ViewModel/CarViewModel.cs | 8 +- .../ViewModel/ClientViewModel.cs | 10 +- .../ViewModel/ComponentViewModel.cs | 7 +- .../ViewModel/ImplementerViewModel.cs | 12 +- .../ViewModel/MessageInfoViewModel.cs | 16 ++- .../ViewModel/OrderViewModel.cs | 22 ++-- .../Models/IMessageInfoModel.cs | 2 +- .../AutomobilePlantListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 17 +++ .../ListImplementationExtension.cs | 28 +++++ .../Models/MessageInfoModel.cs | 5 +- .../AutomobilePlant/DataGridViewExtension.cs | 51 +++++++++ .../AutomobilePlant/FormCar.Designer.cs | 75 ++++++++----- AutomobilePlant/AutomobilePlant/FormCar.cs | 5 +- AutomobilePlant/AutomobilePlant/FormCar.resx | 62 +---------- AutomobilePlant/AutomobilePlant/FormCars.cs | 15 +-- .../AutomobilePlant/FormClients.cs | 11 +- .../AutomobilePlant/FormComponents.cs | 14 +-- .../AutomobilePlant/FormImplementers.cs | 14 +-- .../AutomobilePlant/FormMain.Designer.cs | 24 ++-- AutomobilePlant/AutomobilePlant/FormMain.cs | 44 ++++---- .../AutomobilePlant/FormMessages.cs | 10 +- AutomobilePlant/AutomobilePlant/Program.cs | 82 +++++++------- .../AutomobilePlantDataBaseImplements.csproj | 4 + .../DBImplementationExtension.cs | 28 +++++ .../Implements/BackUpInfo.cs | 32 ++++++ .../Models/Car.cs | 5 + .../Models/CarComponent.cs | 6 + .../Models/Client.cs | 6 + .../Models/Component.cs | 5 + .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 18 ++- .../Models/Order.cs | 15 +++ .../AutomomilePlantFileImplement.csproj | 6 +- .../FileImplementationExtension.cs | 28 +++++ .../Implements/BackUpInfo.cs | 47 ++++++++ .../Models/Car.cs | 5 + .../Models/Client.cs | 6 + .../Models/Component.cs | 5 + .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 17 ++- .../Models/Order.cs | 16 ++- 57 files changed, 1065 insertions(+), 250 deletions(-) create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/Attributes/ColumnAttribute.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/Attributes/GridViewAutoSize.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/DependencyManager.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/IDependencyContainer.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/IImplementationExtension.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/ServiceDependencyContainer.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/ServiceProviderLoader.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/DI/UnityServiceContainer.cs create mode 100644 AutomobilePlant/AbstractAutoContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/Implements/BackUpInfo.cs create mode 100644 AutomobilePlant/AbstractAutoListImplement/ListImplementationExtension.cs create mode 100644 AutomobilePlant/AutomobilePlant/DataGridViewExtension.cs create mode 100644 AutomobilePlant/AutomobilePlantDataBaseImplements/DBImplementationExtension.cs create mode 100644 AutomobilePlant/AutomobilePlantDataBaseImplements/Implements/BackUpInfo.cs create mode 100644 AutomobilePlant/AutomomilePlantFileImplement/FileImplementationExtension.cs create mode 100644 AutomobilePlant/AutomomilePlantFileImplement/Implements/BackUpInfo.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..87f0123 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ ## files generated by popular Visual Studio add-ons. ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - +ImplementationExtensions/ # User-specific files *.rsuser *.suo diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/BackUpLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..886557c --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,103 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantDataModels; +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 AutomobilePlantBusinessLogic.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(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/Attributes/ColumnAttribute.cs b/AutomobilePlant/AbstractAutoContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..4496c1b --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AbstractAutoContracts/Attributes/GridViewAutoSize.cs b/AutomobilePlant/AbstractAutoContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..c3f06a8 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj index 940430a..9a2fb64 100644 --- a/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj +++ b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/BackUpSaveBinidngModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..25abc8a --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/MessageInfoBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/MessageInfoBindingModel.cs index b290a69..de63096 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/MessageInfoBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace AutomobilePlantContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + + public int Id { get; set; } } } \ No newline at end of file diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IBackUpLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..6285904 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,15 @@ +using AutomobilePlantContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} + diff --git a/AutomobilePlant/AbstractAutoContracts/DI/DependencyManager.cs b/AutomobilePlant/AbstractAutoContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..e61c5f1 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/DI/DependencyManager.cs @@ -0,0 +1,67 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; + +namespace AutomobilePlantContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new UnityServiceContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/DI/IDependencyContainer.cs b/AutomobilePlant/AbstractAutoContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..a57a9c9 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AbstractAutoContracts/DI/IImplementationExtension.cs b/AutomobilePlant/AbstractAutoContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..5c84c48 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/DI/ServiceDependencyContainer.cs b/AutomobilePlant/AbstractAutoContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..111f15e --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/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 AutomobilePlantContracts.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/AutomobilePlant/AbstractAutoContracts/DI/ServiceProviderLoader.cs b/AutomobilePlant/AbstractAutoContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..b961d5e --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/DI/UnityServiceContainer.cs b/AutomobilePlant/AbstractAutoContracts/DI/UnityServiceContainer.cs new file mode 100644 index 0000000..db6764c --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/DI/UnityServiceContainer.cs @@ -0,0 +1,59 @@ +using Microsoft.Extensions.DependencyInjection; +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 AutomobilePlantContracts.DI +{ + public class UnityServiceContainer : IDependencyContainer + { + private UnityContainer? _unityContainer; + + public UnityServiceContainer() + { + _unityContainer = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + + } + + public T Resolve() + { + + return _unityContainer.Resolve()!; + } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IBackUpInfo.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..a4ac209 --- /dev/null +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs index dfd9bb0..d1a6dac 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarViewModel.cs @@ -5,15 +5,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; +using AutomobilePlantContracts.Attributes; + namespace AutomobilePlantContracts.ViewModel { public class CarViewModel : ICarModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column(title: "Название", width: 150)] public string CarName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 50)] public double Price { get; set; } + [Column(visible: false)] public Dictionary CarComponents { get; diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ClientViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ClientViewModel.cs index fe1f056..3979269 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ClientViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ClientViewModel.cs @@ -1,4 +1,5 @@ -using AutomobilePlantDataModels.Models; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace AutomobilePlantContracts.ViewModel { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "Имя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs index efaeb1b..501c7d8 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs @@ -5,14 +5,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; +using AutomobilePlantContracts.Attributes; + namespace AutomobilePlantContracts.ViewModel { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column(title: "Название", width: 150)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ImplementerViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ImplementerViewModel.cs index 4f3810a..97bc3ba 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ImplementerViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using AutomobilePlantDataModels.Models; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace AutomobilePlantContracts.ViewModel { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "Имя", width: 150)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж", width: 100)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 100)] public int Qualification { get; set; } } } diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/MessageInfoViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/MessageInfoViewModel.cs index 6394196..0324d24 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/MessageInfoViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/MessageInfoViewModel.cs @@ -1,24 +1,28 @@ -using AutomobilePlantDataModels.Models; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; using System.ComponentModel; namespace AutomobilePlantContracts.ViewModel { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } } } \ No newline at end of file diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs index cfcd8fd..50a60a2 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs @@ -6,31 +6,35 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel; using AutomobilePlantDataModels.Enums; +using AutomobilePlantContracts.Attributes; namespace AutomobilePlantContracts.ViewModel { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Клиент")] + [Column(title: "Клиент", width: 150)] public string ClientName { get; set; } = string.Empty; + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", width: 150)] public string? ImplementerName { get; set; } = string.Empty; + [Column(visible: false)] public int CarId { get; set; } - [DisplayName("Изделие")] + [Column(title: "Машина", width: 150)] public string CarName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Кол-во", width: 150)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 150)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 150)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 150)] public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 150)] public DateTime? DateImplement { get; set; } } diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IMessageInfoModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IMessageInfoModel.cs index 8c1f2b9..8e6dd78 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IMessageInfoModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AutomobilePlantDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj index 43870e5..50d47ab 100644 --- a/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj +++ b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/BackUpInfo.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ce22c3a --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using AutomobilePlantContracts.StoragesContracts; + +namespace AutomobilePlantListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/AutomobilePlant/AbstractAutoListImplement/ListImplementationExtension.cs b/AutomobilePlant/AbstractAutoListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..3d894b0 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/ListImplementationExtension.cs @@ -0,0 +1,28 @@ +using AbstractShopContracts.StoragesContracts; +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/MessageInfoModel.cs b/AutomobilePlant/AbstractAutoListImplement/Models/MessageInfoModel.cs index 649c408..66ffbfd 100644 --- a/AutomobilePlant/AbstractAutoListImplement/Models/MessageInfoModel.cs +++ b/AutomobilePlant/AbstractAutoListImplement/Models/MessageInfoModel.cs @@ -32,6 +32,7 @@ namespace AutomobilePlantListImplement.Models } return new MessageInfoModel() { + Id = model.Id, MessageId = model.MessageId, ClientId = model.ClientId, SenderName = model.SenderName, @@ -42,6 +43,7 @@ namespace AutomobilePlantListImplement.Models } public MessageInfoViewModel GetViewModel => new() { + Id = Id, MessageId = MessageId, ClientId = ClientId, SenderName = SenderName, @@ -49,6 +51,7 @@ namespace AutomobilePlantListImplement.Models Subject = Subject, Body = Body, }; - + + public int Id { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlant/DataGridViewExtension.cs b/AutomobilePlant/AutomobilePlant/DataGridViewExtension.cs new file mode 100644 index 0000000..fab0519 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using AutomobilePlantContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlant +{ + 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/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs b/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs index 712b213..9d43c43 100644 --- a/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormCar.Designer.cs @@ -53,33 +53,35 @@ // CarNameLabel // this.CarNameLabel.AutoSize = true; - this.CarNameLabel.Location = new System.Drawing.Point(12, 9); - this.CarNameLabel.Name = "PackageNameLabel"; - this.CarNameLabel.Size = new System.Drawing.Size(65, 15); + this.CarNameLabel.Location = new System.Drawing.Point(14, 12); + this.CarNameLabel.Name = "CarNameLabel"; + this.CarNameLabel.Size = new System.Drawing.Size(84, 20); this.CarNameLabel.TabIndex = 0; this.CarNameLabel.Text = "Название: "; // // PriceLabel // this.PriceLabel.AutoSize = true; - this.PriceLabel.Location = new System.Drawing.Point(12, 43); + this.PriceLabel.Location = new System.Drawing.Point(14, 57); this.PriceLabel.Name = "PriceLabel"; - this.PriceLabel.Size = new System.Drawing.Size(73, 15); + this.PriceLabel.Size = new System.Drawing.Size(90, 20); this.PriceLabel.TabIndex = 1; this.PriceLabel.Text = "Стоимость: "; // // CarNameTextBox // - this.CarNameTextBox.Location = new System.Drawing.Point(83, 6); - this.CarNameTextBox.Name = "PackageNameTextBox"; - this.CarNameTextBox.Size = new System.Drawing.Size(283, 23); + this.CarNameTextBox.Location = new System.Drawing.Point(95, 8); + this.CarNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CarNameTextBox.Name = "CarNameTextBox"; + this.CarNameTextBox.Size = new System.Drawing.Size(323, 27); this.CarNameTextBox.TabIndex = 2; // // PriceTextBox // - this.PriceTextBox.Location = new System.Drawing.Point(83, 40); + this.PriceTextBox.Location = new System.Drawing.Point(95, 53); + this.PriceTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.PriceTextBox.Name = "PriceTextBox"; - this.PriceTextBox.Size = new System.Drawing.Size(283, 23); + this.PriceTextBox.Size = new System.Drawing.Size(323, 27); this.PriceTextBox.TabIndex = 3; // // ComponentsGroupBox @@ -89,18 +91,21 @@ this.ComponentsGroupBox.Controls.Add(this.ChangeButton); this.ComponentsGroupBox.Controls.Add(this.AddButton); this.ComponentsGroupBox.Controls.Add(this.DataGridView); - this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 80); + this.ComponentsGroupBox.Location = new System.Drawing.Point(14, 107); + this.ComponentsGroupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ComponentsGroupBox.Name = "ComponentsGroupBox"; - this.ComponentsGroupBox.Size = new System.Drawing.Size(722, 350); + this.ComponentsGroupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ComponentsGroupBox.Size = new System.Drawing.Size(825, 467); this.ComponentsGroupBox.TabIndex = 5; this.ComponentsGroupBox.TabStop = false; this.ComponentsGroupBox.Text = "Компоненты"; // // UpdateButton // - this.UpdateButton.Location = new System.Drawing.Point(590, 203); + this.UpdateButton.Location = new System.Drawing.Point(674, 271); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.UpdateButton.Name = "UpdateButton"; - this.UpdateButton.Size = new System.Drawing.Size(110, 38); + this.UpdateButton.Size = new System.Drawing.Size(126, 51); this.UpdateButton.TabIndex = 4; this.UpdateButton.Text = "Обновить"; this.UpdateButton.UseVisualStyleBackColor = true; @@ -108,9 +113,10 @@ // // DeleteButton // - this.DeleteButton.Location = new System.Drawing.Point(590, 143); + this.DeleteButton.Location = new System.Drawing.Point(674, 191); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.DeleteButton.Name = "DeleteButton"; - this.DeleteButton.Size = new System.Drawing.Size(110, 38); + this.DeleteButton.Size = new System.Drawing.Size(126, 51); this.DeleteButton.TabIndex = 3; this.DeleteButton.Text = "Удалить"; this.DeleteButton.UseVisualStyleBackColor = true; @@ -118,9 +124,10 @@ // // ChangeButton // - this.ChangeButton.Location = new System.Drawing.Point(590, 82); + this.ChangeButton.Location = new System.Drawing.Point(674, 109); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ChangeButton.Name = "ChangeButton"; - this.ChangeButton.Size = new System.Drawing.Size(110, 38); + this.ChangeButton.Size = new System.Drawing.Size(126, 51); this.ChangeButton.TabIndex = 2; this.ChangeButton.Text = "Изменить"; this.ChangeButton.UseVisualStyleBackColor = true; @@ -128,9 +135,10 @@ // // AddButton // - this.AddButton.Location = new System.Drawing.Point(590, 22); + this.AddButton.Location = new System.Drawing.Point(674, 29); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.AddButton.Name = "AddButton"; - this.AddButton.Size = new System.Drawing.Size(110, 38); + this.AddButton.Size = new System.Drawing.Size(126, 51); this.AddButton.TabIndex = 1; this.AddButton.Text = "Добавить"; this.AddButton.UseVisualStyleBackColor = true; @@ -159,7 +167,8 @@ dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2; - this.DataGridView.Location = new System.Drawing.Point(6, 22); + this.DataGridView.Location = new System.Drawing.Point(7, 29); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.DataGridView.Name = "DataGridView"; dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; @@ -169,32 +178,39 @@ dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + this.DataGridView.RowHeadersWidth = 51; this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.Size = new System.Drawing.Size(561, 322); + this.DataGridView.Size = new System.Drawing.Size(641, 429); this.DataGridView.TabIndex = 0; // // ID // this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; this.ID.Name = "ID"; this.ID.Visible = false; + this.ID.Width = 125; // // ComponentNameField // this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.ComponentNameField.HeaderText = "Компонент"; + this.ComponentNameField.MinimumWidth = 6; this.ComponentNameField.Name = "ComponentNameField"; // // CountField // this.CountField.HeaderText = "Количество"; + this.CountField.MinimumWidth = 6; this.CountField.Name = "CountField"; + this.CountField.Width = 125; // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(602, 446); + this.ButtonCancel.Location = new System.Drawing.Point(688, 595); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(110, 34); + this.ButtonCancel.Size = new System.Drawing.Size(126, 45); this.ButtonCancel.TabIndex = 7; this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; @@ -202,9 +218,10 @@ // // SaveButton // - this.SaveButton.Location = new System.Drawing.Point(486, 446); + this.SaveButton.Location = new System.Drawing.Point(555, 595); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.SaveButton.Name = "SaveButton"; - this.SaveButton.Size = new System.Drawing.Size(110, 34); + this.SaveButton.Size = new System.Drawing.Size(126, 45); this.SaveButton.TabIndex = 8; this.SaveButton.Text = "Сохранить"; this.SaveButton.UseVisualStyleBackColor = true; @@ -212,9 +229,9 @@ // // FormCar // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(746, 498); + this.ClientSize = new System.Drawing.Size(853, 664); this.Controls.Add(this.SaveButton); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ComponentsGroupBox); @@ -222,8 +239,10 @@ this.Controls.Add(this.CarNameTextBox); this.Controls.Add(this.PriceLabel); this.Controls.Add(this.CarNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormCar"; this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormCar_Load); this.ComponentsGroupBox.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/AutomobilePlant/AutomobilePlant/FormCar.cs b/AutomobilePlant/AutomobilePlant/FormCar.cs index a6ffb47..7a8d3b2 100644 --- a/AutomobilePlant/AutomobilePlant/FormCar.cs +++ b/AutomobilePlant/AutomobilePlant/FormCar.cs @@ -1,5 +1,6 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using AutomobilePlantContracts.SearchModel; using AutomobilePlantDataModels.Models; using Microsoft.Extensions.Logging; @@ -83,7 +84,7 @@ namespace AutomobilePlant private void AddButton_Click(object sender, EventArgs e) { var service = - Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + DependencyManager.Instance.Resolve(); if (service is FormCarComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -112,7 +113,7 @@ namespace AutomobilePlant if (DataGridView.SelectedRows.Count == 1) { var service = - Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + DependencyManager.Instance.Resolve(); if (service is FormCarComponent form) { int id = diff --git a/AutomobilePlant/AutomobilePlant/FormCar.resx b/AutomobilePlant/AutomobilePlant/FormCar.resx index 1af7de1..f298a7b 100644 --- a/AutomobilePlant/AutomobilePlant/FormCar.resx +++ b/AutomobilePlant/AutomobilePlant/FormCar.resx @@ -1,64 +1,4 @@ - - - + diff --git a/AutomobilePlant/AutomobilePlant/FormCars.cs b/AutomobilePlant/AutomobilePlant/FormCars.cs index 3748c60..c255f24 100644 --- a/AutomobilePlant/AutomobilePlant/FormCars.cs +++ b/AutomobilePlant/AutomobilePlant/FormCars.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using AutomobilePlantContracts.DI; namespace AutomobilePlant { @@ -34,15 +35,7 @@ namespace AutomobilePlant { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["CarComponents"].Visible = false; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); @@ -56,7 +49,7 @@ namespace AutomobilePlant private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCar form) { @@ -70,7 +63,7 @@ namespace AutomobilePlant { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCar form) { diff --git a/AutomobilePlant/AutomobilePlant/FormClients.cs b/AutomobilePlant/AutomobilePlant/FormClients.cs index d89595d..2cfec4f 100644 --- a/AutomobilePlant/AutomobilePlant/FormClients.cs +++ b/AutomobilePlant/AutomobilePlant/FormClients.cs @@ -1,4 +1,5 @@ -using AutomobilePlantContracts.BindingModels; +using AutomobilePlant; +using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; @@ -26,13 +27,7 @@ namespace AbstractShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/AutomobilePlant/AutomobilePlant/FormComponents.cs b/AutomobilePlant/AutomobilePlant/FormComponents.cs index e9b6f67..b601d87 100644 --- a/AutomobilePlant/AutomobilePlant/FormComponents.cs +++ b/AutomobilePlant/AutomobilePlant/FormComponents.cs @@ -1,5 +1,6 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -32,14 +33,7 @@ namespace AutomobilePlant { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -52,7 +46,7 @@ namespace AutomobilePlant private void AddButton_Click(object sender, EventArgs e) { var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -66,7 +60,7 @@ namespace AutomobilePlant if (DataGridView.SelectedRows.Count == 1) { var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + DependencyManager.Instance.Resolve(); if (service is FormComponent form) { form.Id = diff --git a/AutomobilePlant/AutomobilePlant/FormImplementers.cs b/AutomobilePlant/AutomobilePlant/FormImplementers.cs index 9a38047..8d75c7e 100644 --- a/AutomobilePlant/AutomobilePlant/FormImplementers.cs +++ b/AutomobilePlant/AutomobilePlant/FormImplementers.cs @@ -1,5 +1,6 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,7 @@ namespace AutomobilePlant { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -53,7 +47,7 @@ namespace AutomobilePlant private void AddButton_Click(object sender, EventArgs e) { var service = - Program.ServiceProvider?.GetService(typeof(FormImplementer)); + DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -67,7 +61,7 @@ namespace AutomobilePlant if (DataGridView.SelectedRows.Count == 1) { var service = - Program.ServiceProvider?.GetService(typeof(FormImplementer)); + DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs index 9ca7480..49b7638 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.начатьРаботуToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.бекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -57,7 +58,8 @@ this.клиентыToolStripMenuItem, this.исполнителиToolStripMenuItem, this.начатьРаботуToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.бекапToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); @@ -140,6 +142,13 @@ this.начатьРаботуToolStripMenuItem.Text = "Начать работу"; this.начатьРаботуToolStripMenuItem.Click += new System.EventHandler(this.начатьРаботуToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -184,12 +193,12 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // письмаToolStripMenuItem + // бекапToolStripMenuItem // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click); + this.бекапToolStripMenuItem.Name = "бекапToolStripMenuItem"; + this.бекапToolStripMenuItem.Size = new System.Drawing.Size(64, 24); + this.бекапToolStripMenuItem.Text = "Бекап"; + this.бекапToolStripMenuItem.Click += new System.EventHandler(this.бекапToolStripMenuItem_Click); // // FormMain // @@ -232,5 +241,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem начатьРаботуToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem бекапToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.cs b/AutomobilePlant/AutomobilePlant/FormMain.cs index ff247bc..89aa10d 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.cs @@ -1,7 +1,9 @@ using AbstractShopView; using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantBusinessLogic.MailWorker; using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using AutomobilePlantDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -22,14 +24,16 @@ namespace AutomobilePlant private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -43,15 +47,7 @@ namespace AutomobilePlant try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["CarId"].Visible = false; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["ImplementerId"].Visible = false; - } + DataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } @@ -64,7 +60,7 @@ namespace AutomobilePlant private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponents form) { @@ -74,7 +70,7 @@ namespace AutomobilePlant private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCars form) { @@ -84,7 +80,7 @@ namespace AutomobilePlant private void CreateOrderButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { @@ -216,7 +212,7 @@ namespace AutomobilePlant private void ComponentCarsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportCarComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportCarComponents form) { form.ShowDialog(); @@ -225,7 +221,7 @@ namespace AutomobilePlant private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -234,7 +230,7 @@ namespace AutomobilePlant private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -243,7 +239,7 @@ namespace AutomobilePlant private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -252,18 +248,28 @@ namespace AutomobilePlant private void начатьРаботуToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMessages)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMessages form) { form.ShowDialog(); } } + + private void бекапToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new FolderBrowserDialog(); + if (dialog.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel { FolderName = dialog.SelectedPath}); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } } diff --git a/AutomobilePlant/AutomobilePlant/FormMessages.cs b/AutomobilePlant/AutomobilePlant/FormMessages.cs index 1171e82..12ae1a7 100644 --- a/AutomobilePlant/AutomobilePlant/FormMessages.cs +++ b/AutomobilePlant/AutomobilePlant/FormMessages.cs @@ -1,4 +1,5 @@ using AbstractShopView; +using AutomobilePlantBusinessLogic.BusinessLogics; using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; @@ -36,14 +37,7 @@ namespace AutomobilePlant { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["SenderName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index a60cd27..4c68318 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -12,13 +12,13 @@ using AbstractShopView; using AbstractShopContracts.StoragesContracts; using AutomobilePlantBusinessLogic.MailWorker; using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.DI; namespace AutomobilePlant { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -28,13 +28,12 @@ namespace AutomobilePlant // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); + try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -50,56 +49,53 @@ namespace AutomobilePlant } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + + 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(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); - services.AddSingleton(); - services.AddTransient(); + 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(); - 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 diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/AutomobilePlantDataBaseImplements.csproj b/AutomobilePlant/AutomobilePlantDataBaseImplements/AutomobilePlantDataBaseImplements.csproj index 2766c38..459ad26 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/AutomobilePlantDataBaseImplements.csproj +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/AutomobilePlantDataBaseImplements.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/DBImplementationExtension.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/DBImplementationExtension.cs new file mode 100644 index 0000000..cb7f1f9 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/DBImplementationExtension.cs @@ -0,0 +1,28 @@ +using AbstractShopContracts.StoragesContracts; +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantDataBaseImplements.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataBaseImplements +{ + public class DBImplementationExtension : 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/AutomobilePlant/AutomobilePlantDataBaseImplements/Implements/BackUpInfo.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ba16fe8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using AutomobilePlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataBaseImplements.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new AutoPlantDataBase(); + 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/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Car.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Car.cs index 6fa5f51..742e78d 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Car.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Car.cs @@ -8,17 +8,22 @@ using System.Text; using System.Threading.Tasks; using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModel; +using System.Runtime.Serialization; namespace AutomobilePlantDataBaseImplements.Models { + [DataContract] public class Car : ICarModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string CarName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _carComponents = null; diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/CarComponent.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/CarComponent.cs index cddaea7..341f475 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/CarComponent.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/CarComponent.cs @@ -2,22 +2,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace AutomobilePlantDataBaseImplements.Models { + public class CarComponent { + public int Id { get; set; } [Required] + public int CarId { get; set; } [Required] + public int ComponentId { get; set; } [Required] + public int Count { get; set; } public virtual Component Component { get; set; } = new(); diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Client.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Client.cs index 82b5b5b..893d7a2 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Client.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Client.cs @@ -10,20 +10,26 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace AutomobilePlantDataBaseImplements.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ClientFIO { get; set; } = string.Empty; [Required] + [DataMember] public string Email { get; set; } = string.Empty; [Required] + [DataMember] public string Password { get; set; } = string.Empty; diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Component.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Component.cs index 5e17946..9aee9ae 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Component.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Component.cs @@ -8,17 +8,22 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace AutomobilePlantDataBaseImplements.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Implementer.cs index f0de96d..0da7bd4 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Implementer.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Implementer.cs @@ -8,22 +8,29 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace AutomobilePlantDataBaseImplements.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; set; } [Required] + [DataMember] public int Qualification { get; set; } [Required] + [DataMember] public string Password { get; set; } = string.Empty; diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/MessageInfo.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/MessageInfo.cs index 99a602d..fd8aeb9 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/MessageInfo.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/MessageInfo.cs @@ -7,24 +7,28 @@ 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 AutomobilePlantDataBaseImplements.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; set; } = string.Empty; + [DataMember] public int? ClientId { get; set; } public Client? client { get; private set; } - + [DataMember] public string SenderName { get; set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; set; } - + [DataMember] public string Subject { get; set; } = string.Empty; - + [DataMember] public string Body { get; set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel? model) { @@ -33,7 +37,7 @@ namespace AutomobilePlantDataBaseImplements.Models return null; } return new MessageInfo() - { + { Id = model.Id, MessageId = model.MessageId, ClientId = model.ClientId, SenderName = model.SenderName, @@ -43,7 +47,7 @@ namespace AutomobilePlantDataBaseImplements.Models }; } public MessageInfoViewModel GetViewModel => new() - { + { Id = Id, MessageId = MessageId, ClientId = ClientId, SenderName = SenderName, @@ -51,5 +55,7 @@ namespace AutomobilePlantDataBaseImplements.Models Subject = Subject, Body = Body, }; + [NotMapped] + public int Id {get; set;} } } diff --git a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Order.cs b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Order.cs index 036f72a..5b1d949 100644 --- a/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantDataBaseImplements/Models/Order.cs @@ -8,33 +8,48 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace AutomobilePlantDataBaseImplements.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int CarId { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public string ClientName { get; private set; } = string.Empty; + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] public string? ImplementerName { get; private set; } = string.Empty; + [DataMember] public string CarName { get; private set; } = string.Empty; + public Client client { get; private set; } public Car car { get; private set; } public Implementer? implementer { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) diff --git a/AutomobilePlant/AutomomilePlantFileImplement/AutomomilePlantFileImplement.csproj b/AutomobilePlant/AutomomilePlantFileImplement/AutomomilePlantFileImplement.csproj index 43870e5..1c3d933 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/AutomomilePlantFileImplement.csproj +++ b/AutomobilePlant/AutomomilePlantFileImplement/AutomomilePlantFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,8 @@ + + + + diff --git a/AutomobilePlant/AutomomilePlantFileImplement/FileImplementationExtension.cs b/AutomobilePlant/AutomomilePlantFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..11fde5d --- /dev/null +++ b/AutomobilePlant/AutomomilePlantFileImplement/FileImplementationExtension.cs @@ -0,0 +1,28 @@ +using AbstractShopContracts.StoragesContracts; +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomomilePlantFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomomilePlantFileImplement +{ + 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/AutomobilePlant/AutomomilePlantFileImplement/Implements/BackUpInfo.cs b/AutomobilePlant/AutomomilePlantFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..38f2f64 --- /dev/null +++ b/AutomobilePlant/AutomomilePlantFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,47 @@ +using AutomobilePlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace AutomomilePlantFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var context = DataFileSingleton.GetInstance(); + Type myType = typeof(DataFileSingleton); + string property = $"{typeof(T).FullName}"; + string nameList = ""; + foreach (PropertyInfo prop in myType.GetProperties( + BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)) + { + var list = prop.GetValue(context); + var typeList = list.GetType().GetGenericArguments().Single(); + if (property.Equals($"{typeList.FullName}")) + { nameList = prop.Name; break; } + } + var propertyInfo = myType.GetProperty(nameList); + var values = (List)propertyInfo.GetValue(context); + return values; + + } + + 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/AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs index 7c0616c..5721123 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/Car.cs @@ -4,16 +4,21 @@ using AutomobilePlantDataModels.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 AutomomilePlantFileImplement.Models { + [DataContract] public class Car : ICarModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string CarName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _carComponents = diff --git a/AutomobilePlant/AutomomilePlantFileImplement/Models/Client.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/Client.cs index 19c62ff..c2c9dfa 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/Client.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/Client.cs @@ -5,17 +5,23 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace AutomomilePlantFileImplement.Models { + [DataContract] public class Client : IClientModel { + [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/AutomobilePlant/AutomomilePlantFileImplement/Models/Component.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/Component.cs index 86cc04b..50b8ef6 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/Component.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/Component.cs @@ -4,16 +4,21 @@ using AutomobilePlantDataModels.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 AutomomilePlantFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [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/AutomobilePlant/AutomomilePlantFileImplement/Models/Implementer.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/Implementer.cs index 8640bca..7549ecb 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/Implementer.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/Implementer.cs @@ -4,18 +4,25 @@ using AutomobilePlantDataModels.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 AutomomilePlantFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] public int WorkExperience { get; set; } + [DataMember] public int Qualification { get; set; } + [DataMember] public string Password { get; private set; } = string.Empty; public static Implementer? Create(ImplementerBindingModel model) { diff --git a/AutomobilePlant/AutomomilePlantFileImplement/Models/MessageInfo.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/MessageInfo.cs index 8f05ca2..4cd59e1 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/MessageInfo.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/MessageInfo.cs @@ -4,24 +4,27 @@ using AutomobilePlantDataModels.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 AutomomilePlantFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId {get;set;} = string.Empty; public int? ClientId { get; set; } - + [DataMember] public string SenderName { get; set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; set; } - + [DataMember] public string Subject { get; set; } = string.Empty; - + [DataMember] public string Body { get; set;} = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -31,6 +34,7 @@ namespace AutomomilePlantFileImplement.Models } return new MessageInfo() { + Id = model.Id, MessageId = model.MessageId, ClientId = model.ClientId, SenderName = model.SenderName, @@ -47,6 +51,7 @@ namespace AutomomilePlantFileImplement.Models } return new MessageInfo() { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), MessageId =element.Attribute("MessageId")!.Value, ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), SenderName = element.Attribute("SenderName")!.Value, @@ -58,6 +63,7 @@ namespace AutomomilePlantFileImplement.Models public MessageInfoViewModel GetViewModel => new() { + Id = Id, MessageId = MessageId, ClientId = ClientId, SenderName = SenderName, @@ -67,11 +73,14 @@ namespace AutomomilePlantFileImplement.Models }; public XElement GetXElement => new("MessageInfo", new XAttribute("MessageId", MessageId), + new XAttribute("Id", Id), new XElement("ClientId", ClientId.ToString()), new XElement("SenderName", SenderName), new XElement("DateDelivery", DateDelivery.ToString()), new XElement("Subject", Subject), new XElement("Body", Body) ); + + public int Id { get; set; } } } diff --git a/AutomobilePlant/AutomomilePlantFileImplement/Models/Order.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/Order.cs index d26d9c9..ed36d44 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/Models/Order.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/Order.cs @@ -5,29 +5,43 @@ using AutomobilePlantDataModels.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 AutomomilePlantFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int CarId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public string ClientName { get; private set; } = string.Empty; - public string CarName { get; private set; } = string.Empty; + [DataMember] + public string CarName { get; private set; } = string.Empty; + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] public string? ImplementerName { get; private set; } = string.Empty; + [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.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + [DataMember] public DateTime? DateImplement { get; private set; } = null; + [DataMember] public int Id { get; private set; } public static Order? Create(OrderBindingModel model)