From 3137295ee0abe60c3b913323652d29febd45ff42 Mon Sep 17 00:00:00 2001 From: sardq Date: Thu, 16 May 2024 17:00:28 +0400 Subject: [PATCH 1/2] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + .../BusinessLogics/BackUpLogic.cs | 98 +++++++++++++++ .../Attributes/ColumnAttribute.cs | 25 ++++ .../Attributes/GridViewAutoSize.cs | 21 ++++ .../BindingModels/BackUpSaveBinidngModel.cs | 7 ++ .../BindingModels/MessageInfoBindingModel.cs | 3 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 9 ++ .../DI/DependencyManager.cs | 61 +++++++++ .../DI/IDependencyContainer.cs | 35 ++++++ .../DI/IImplementationExtension.cs | 11 ++ .../DI/ServiceDependencyContainer.cs | 57 +++++++++ .../DI/ServiceProviderLoader.cs | 50 ++++++++ .../DI/UnityDependencyContainer.cs | 33 +++++ .../PlumbingRepairContracts.csproj | 6 + .../StoragesContracts/IBackUpInfo.cs | 9 ++ .../ViewModels/ClientViewModel.cs | 18 +-- .../ViewModels/ComponentViewModel.cs | 12 +- .../ViewModels/ImplementerViewModel.cs | 20 +-- .../ViewModels/MessageInfoViewModel.cs | 30 +++-- .../ViewModels/OrderViewModel.cs | 53 ++++---- .../ViewModels/WorkViewModel.cs | 18 +-- .../Models/IMessageInfoModel.cs | 3 +- .../DatabaseImplementationExtension.cs | 21 ++++ .../Implements/BackUpInfo.cs | 27 ++++ .../Models/Client.cs | 18 ++- .../Models/Component.cs | 13 +- .../Models/Implementer.cs | 19 ++- .../Models/MessageInfo.cs | 26 ++-- .../Models/Order.cs | 33 +++-- .../Models/Work.cs | 11 +- .../PlumbingRepairDatabaseImplement.csproj | 4 + .../FileImplementationExtension.cs | 21 ++++ .../Implements/BackUpInfo.cs | 29 +++++ .../Models/Client.cs | 16 ++- .../Models/Component.cs | 13 +- .../Models/Implementer.cs | 18 ++- .../Models/MessageInfo.cs | 28 +++-- .../Models/Order.cs | 35 +++--- .../Models/Work.cs | 13 +- .../PlumbingRepairFileImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 16 +++ .../ListImplementationExtension.cs | 22 ++++ .../Models/Client.cs | 17 ++- .../Models/Component.cs | 13 +- .../Models/Implementer.cs | 20 +-- .../Models/MessageInfo.cs | 28 +++-- .../Models/Order.cs | 37 +++--- .../Models/Work.cs | 15 ++- .../PlumbingRepairListImplement.csproj | 4 + .../DataGridViewExtension.cs | 46 +++++++ .../PlumbingRepairView/FormClients.cs | 10 +- .../PlumbingRepairView/FormComponents.cs | 24 ++-- .../PlumbingRepairView/FormImplementers.cs | 37 ++---- .../PlumbingRepairView/FormMails.cs | 11 +- PlumbingRepair/PlumbingRepairView/FormMain.cs | 116 +++++++++--------- PlumbingRepair/PlumbingRepairView/FormWork.cs | 87 +++++++------ .../PlumbingRepairView/FormWorks.cs | 43 +++---- PlumbingRepair/PlumbingRepairView/Program.cs | 106 ++++++++-------- 58 files changed, 1124 insertions(+), 459 deletions(-) create mode 100644 PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/Attributes/GridViewAutoSize.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/IDependencyContainer.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/IImplementationExtension.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/ServiceDependencyContainer.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs create mode 100644 PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 PlumbingRepair/PlumbingRepairDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/FileImplementationExtension.cs create mode 100644 PlumbingRepair/PlumbingRepairFileImplement/Implements/BackUpInfo.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/Implements/BackUpInfo.cs create mode 100644 PlumbingRepair/PlumbingRepairListImplement/ListImplementationExtension.cs create mode 100644 PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..52737dc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll файлы +*.dll + # Mono auto generated files mono_crash.* diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/BackUpLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..4185a42 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,98 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace PlumbingRepairBusinessLogic.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); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..c73044d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace PlumbingRepairContracts.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; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/Attributes/GridViewAutoSize.cs b/PlumbingRepair/PlumbingRepairContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..0ff9a91 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,21 @@ +namespace PlumbingRepairContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/BackUpSaveBinidngModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..f5adf7d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/MessageInfoBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/MessageInfoBindingModel.cs index bcc5cfb..c511fcc 100644 --- a/PlumbingRepair/PlumbingRepairContracts/BindingModels/MessageInfoBindingModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/MessageInfoBindingModel.cs @@ -14,5 +14,6 @@ namespace PlumbingRepairContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; - } + public int Id => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IBackUpLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..8defc76 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using PlumbingRepairContracts.BindingModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs b/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..906def0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/IDependencyContainer.cs b/PlumbingRepair/PlumbingRepairContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..e3c4abf --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairContracts.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(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationExtension.cs b/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..752c5f5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationExtension.cs @@ -0,0 +1,11 @@ +namespace PlumbingRepairContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/ServiceDependencyContainer.cs b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..ec3498c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairContracts.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()!; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..e09daa2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,50 @@ +using System.Reflection; + +namespace PlumbingRepairContracts.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"; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs b/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..9179344 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Logging; +using Unity.Microsoft.Logging; +using Unity; + +namespace PlumbingRepairContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + public T Resolve() + { + return _container.Resolve(); + } + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj index 5c96a30..097430d 100644 --- a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj +++ b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IBackUpInfo.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..e600448 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ClientViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ClientViewModel.cs index 6e710c6..346dc05 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ClientViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ClientViewModel.cs @@ -1,19 +1,21 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.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; } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs index d01ac75..cb9d3ec 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs @@ -1,16 +1,18 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public double Cost { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs index dc637e1..6206d65 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs @@ -1,20 +1,22 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.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("Пароль")] + [Column(title: "Пароль", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(title: "Стаж работы", width: 150)] + public int WorkExperience { get; set; } + [Column(title: "Квалификация", width: 150)] + public int Qualification { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs index 1f2a35c..61b1178 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs @@ -1,20 +1,24 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - - public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата отправления")] - public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } + [Column(title: "Отправитель", width: 150)] + public string SenderName { get; set; } = string.Empty; + [Column(title: "Дата отправления", width: 150)] + public DateTime DateDelivery { get; set; } + [Column(title: "Заголовок", width: 150)] + public string Subject { 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(); + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs index 6bfff35..897ffdb 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using PlumbingRepairDataModels.Enums; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Enums; using PlumbingRepairDataModels.Models; using System.ComponentModel; @@ -6,39 +7,39 @@ namespace PlumbingRepairContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Номер работы")] - public int WorkId { get; set; } + [Column(title: "Номер", width: 100)] + public int Id { get; set; } + [Column(visible: false)] + public int WorkId { get; set; } - [DisplayName("Клиент")] - public int ClientId { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Почта клиента")] + [Column(visible: false)] + public int ClientId { get; set; } + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Почта клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientEmail { get; set; } = string.Empty; - [DisplayName("Исполнитель")] - public int? ImplementerId { get; set; } - [DisplayName("ФИО исполнителя")] - public string? ImplementerFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string? ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Работа")] - public string WorkName { get; set; } = string.Empty; + [Column(title: "Работа", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string WorkName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } + [Column(title: "Количество", width: 150)] + public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } + [Column(title: "Сумма", width: 150)] + public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Статус", width: 150)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата создания", width: 150)] + public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Дата выполнения", width: 150)] + public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs index f367de5..1b4ff09 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs @@ -1,18 +1,20 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.ViewModels { public class WorkViewModel : IWorkModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название работ")] - public string WorkName { get; set; } = string.Empty; + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string WorkName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - [DisplayName("Компоненты")] - public Dictionary WorkComponents { get; set; } = new(); + [Column(title: "Цена", width: 150)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary WorkComponents { get; set; } = new(); } } diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IMessageInfoModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IMessageInfoModel.cs index 2c512f1..a1af6b3 100644 --- a/PlumbingRepair/PlumbingRepairDataModels/Models/IMessageInfoModel.cs +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IMessageInfoModel.cs @@ -1,7 +1,7 @@  namespace PlumbingRepairDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } @@ -9,5 +9,6 @@ namespace PlumbingRepairDataModels.Models DateTime DateDelivery { get; } string Subject { get; } string Body { get; } + } } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/DatabaseImplementationExtension.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..35a7e3f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.DI; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairDatabaseImplement.Implements; + +namespace PlumbingRepairDatabaseImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/BackUpInfo.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..845e30c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using PlumbingRepairContracts.StoragesContracts; + +namespace PlumbingRepairDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new PlumbingRepairDatabase(); + 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; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs index 74b6e79..6deb321 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs @@ -3,23 +3,31 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.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(); + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Component.cs index 2dd9c29..72ef209 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Component.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Component.cs @@ -3,18 +3,23 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.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 WorkComponents { get; set; } = new(); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs index ea0fb22..6f29ab2 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs @@ -3,23 +3,30 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; [Required] - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } [Required] - 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/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs index b4d86cd..c43bc5e 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs @@ -3,22 +3,31 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { [Key] - public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [DataMember] + public string MessageId { get; set; } = string.Empty; + [DataMember] + public int? ClientId { get; set; } [Required] - public string SenderName { get; set; } = string.Empty; + [DataMember] + public string SenderName { get; set; } = string.Empty; [Required] - public DateTime DateDelivery { get; set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; set; } = DateTime.Now; [Required] - public string Subject { get; set; } = string.Empty; + [DataMember] + public string Subject { get; set; } = string.Empty; [Required] - public string Body { get; set; } = string.Empty; + [DataMember] + public string Body { get; set; } = string.Empty; + public virtual Client? Client { get; set; } public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -45,5 +54,6 @@ namespace PlumbingRepairDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs index 7b9e643..cc401f4 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs @@ -3,28 +3,36 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Enums; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { [Required] - public int WorkId { get; set; } + [DataMember] + public int WorkId { get; set; } [Required] - public int ClientId { get; set; } - public int? ImplementerId { get; set; } - + [DataMember] + public int ClientId { get; set; } + [DataMember] + public int? ImplementerId { get; 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; } - - public DateTime? DateImplement { get; set; } + [DataMember] + public DateTime DateCreate { get; set; } + [DataMember] + public DateTime? DateImplement { get; set; } public int Id { get; set; } @@ -69,8 +77,7 @@ namespace PlumbingRepairDatabaseImplement.Models ImplementerId= ImplementerId, ImplementerFIO = Implementer == null ? null : Implementer.ImplementerFIO, Count = Count, - ClientEmail = Client.Email, - Sum = Sum, + Sum = Sum, DateCreate = DateCreate, DateImplement = DateImplement, Id = Id, diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs index 06dab3e..bb9420a 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs @@ -3,18 +3,23 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.Models { + [DataContract] public class Work : IWorkModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string WorkName { get; set; } = string.Empty; + [DataMember] + public string WorkName { get; set; } = string.Empty; [Required] - public double Price { get; set; } + [DataMember] + public double Price { get; set; } private Dictionary? _workComponents = null; diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabaseImplement.csproj b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabaseImplement.csproj index 56b65e0..d5944d4 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabaseImplement.csproj +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabaseImplement.csproj @@ -24,4 +24,8 @@ + + + + diff --git a/PlumbingRepair/PlumbingRepairFileImplement/FileImplementationExtension.cs b/PlumbingRepair/PlumbingRepairFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..0cfbfa7 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/FileImplementationExtension.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.DI; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairFileImplement.Implements; + +namespace BlacksmithWorkshopFileImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Implements/BackUpInfo.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..432fa1c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,29 @@ +using PlumbingRepairContracts.StoragesContracts; + +namespace PlumbingRepairFileImplement.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; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Client.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Client.cs index 9ec3da8..dbd728e 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Client.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Client.cs @@ -1,18 +1,22 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { - internal class Client : IClientModel + [DataContract] + internal class Client : IClientModel { + [DataMember] 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 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/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs index 18ff700..834bb71 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Component.cs @@ -1,17 +1,20 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] internal 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/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs index 6bff04e..ff99806 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs @@ -1,18 +1,24 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] internal 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 Qualification { get; private set; } - public int WorkExperience { 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 Qualification { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } public static Implementer? Create(ImplementerBindingModel model) { diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/MessageInfo.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/MessageInfo.cs index 0a2e934..00a9a92 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/MessageInfo.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/MessageInfo.cs @@ -1,23 +1,26 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] internal class MessageInfo : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -74,5 +77,6 @@ namespace PlumbingRepairFileImplement.Models new XAttribute("DateDelivery", DateDelivery) ); - } + public int Id => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs index c0c5d63..01f8caa 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs @@ -3,27 +3,32 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Enums; using PlumbingRepairDataModels.Models; using System.Reflection; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] internal class Order : IOrderModel { - public int WorkId { 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; } - - public int Id { get; private set; } + [DataMember] + public int WorkId { 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; } + [DataMember] + public int Id { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs index 8bee2d4..01e3282 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs @@ -1,17 +1,20 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] internal class Work : IWorkModel { - public int Id { get; private set; } - - public string WorkName { get; private set; } = string.Empty; - - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string WorkName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); diff --git a/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj index 05f8377..e4c7070 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj +++ b/PlumbingRepair/PlumbingRepairFileImplement/PlumbingRepairFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/BackUpInfo.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..fc345c9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,16 @@ +using PlumbingRepairContracts.StoragesContracts; + +namespace PlumbingRepairListImplement.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/PlumbingRepair/PlumbingRepairListImplement/ListImplementationExtension.cs b/PlumbingRepair/PlumbingRepairListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..3e4edb4 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using PlumbingRepairContracts.DI; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairListImplement.Implements; + +namespace PlumbingRepairListImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Client.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Client.cs index 9283613..d251d7b 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Client.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Client.cs @@ -1,16 +1,21 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - internal class Client : IClientModel + [DataContract] + internal 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/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs index 0e39dd5..4b40b04 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs @@ -1,16 +1,19 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { + [DataContract] internal 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/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs index 1c3dd9e..2814f8f 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs @@ -1,17 +1,23 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - internal class Implementer : IImplementerModel + [DataContract] + internal 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 Qualification { get; private set; } - public int WorkExperience { 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 Qualification { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } public static Implementer? Create(ImplementerBindingModel? model) { if (model == null) diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/MessageInfo.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/MessageInfo.cs index f4129c9..2a9bb04 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/MessageInfo.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/MessageInfo.cs @@ -1,22 +1,25 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -45,5 +48,6 @@ namespace PlumbingRepairListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs index a4d3af6..8899016 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs @@ -2,26 +2,31 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Enums; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - internal class Order : IOrderModel + [DataContract] + internal class Order : IOrderModel { - public int WorkId { 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; } - - public DateTime DateCreate { get; private set; } - - public DateTime? DateImplement { get; private set; } - - public int Id { get; private set; } + [DataMember] + public int WorkId { 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; } + [DataMember] + public DateTime DateCreate { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs index c2f717a..ce957f9 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs @@ -1,16 +1,19 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - internal class Work : IWorkModel + [DataContract] + internal class Work : IWorkModel { - public int Id { get; private set; } - - public string WorkName { get; private set; } = string.Empty; - - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string WorkName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary WorkComponents { get; private set; } = new Dictionary(); diff --git a/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj index 05f8377..e4c7070 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj +++ b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs b/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs new file mode 100644 index 0000000..7e9ef05 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using PlumbingRepairContracts.Attributes; + +namespace PlumbingRepairView +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + // ищем нужный нам атрибут + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormClients.cs b/PlumbingRepair/PlumbingRepairView/FormClients.cs index 048d006..c3f597b 100644 --- a/PlumbingRepair/PlumbingRepairView/FormClients.cs +++ b/PlumbingRepair/PlumbingRepairView/FormClients.cs @@ -28,14 +28,8 @@ namespace PlumbingRepairView { 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/PlumbingRepair/PlumbingRepairView/FormComponents.cs b/PlumbingRepair/PlumbingRepairView/FormComponents.cs index 78b92a7..e4cd304 100644 --- a/PlumbingRepair/PlumbingRepairView/FormComponents.cs +++ b/PlumbingRepair/PlumbingRepairView/FormComponents.cs @@ -1,6 +1,7 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.DI; namespace PlumbingRepairView { @@ -26,14 +27,8 @@ namespace PlumbingRepairView { 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) { @@ -44,13 +39,10 @@ namespace PlumbingRepairView 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) - { + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { LoadData(); - } } } @@ -58,8 +50,8 @@ namespace PlumbingRepairView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponent form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementers.cs b/PlumbingRepair/PlumbingRepairView/FormImplementers.cs index 2d1e250..6f47d0d 100644 --- a/PlumbingRepair/PlumbingRepairView/FormImplementers.cs +++ b/PlumbingRepair/PlumbingRepairView/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; namespace PlumbingRepairView { @@ -25,14 +26,8 @@ namespace PlumbingRepairView { 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) { @@ -43,28 +38,22 @@ namespace PlumbingRepairView 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) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/PlumbingRepair/PlumbingRepairView/FormMails.cs b/PlumbingRepair/PlumbingRepairView/FormMails.cs index 719feec..67bd796 100644 --- a/PlumbingRepair/PlumbingRepairView/FormMails.cs +++ b/PlumbingRepair/PlumbingRepairView/FormMails.cs @@ -17,16 +17,7 @@ namespace PlumbingRepairView { 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("Loading mails"); } catch (Exception ex) diff --git a/PlumbingRepair/PlumbingRepairView/FormMain.cs b/PlumbingRepair/PlumbingRepairView/FormMain.cs index 96787f0..b7ede5a 100644 --- a/PlumbingRepair/PlumbingRepairView/FormMain.cs +++ b/PlumbingRepair/PlumbingRepairView/FormMain.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.Logging; using PlumbingRepairBusinessLogic.BusinessLogics; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; +using System.Windows.Forms; namespace PlumbingRepairView { @@ -13,14 +15,15 @@ namespace PlumbingRepairView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + 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) @@ -32,16 +35,8 @@ namespace PlumbingRepairView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["WorkId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } - _logger.LogInformation("Загрузка заказов"); + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { @@ -52,21 +47,15 @@ namespace PlumbingRepairView private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void РаботыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); - if (service is FormWorks form) - { - form.ShowDialog(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { @@ -84,33 +73,22 @@ e) private void ComponentWorksToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents)); - if (service is FormReportWorkComponents form) - { - form.ShowDialog(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + 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 ButtonIssuedOrder_Click(object sender, EventArgs e) { @@ -143,36 +121,52 @@ e) private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); - } + } private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork((DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void backupToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бэкап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } diff --git a/PlumbingRepair/PlumbingRepairView/FormWork.cs b/PlumbingRepair/PlumbingRepairView/FormWork.cs index 5ee9720..3513b73 100644 --- a/PlumbingRepair/PlumbingRepairView/FormWork.cs +++ b/PlumbingRepair/PlumbingRepairView/FormWork.cs @@ -3,6 +3,7 @@ using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.SearchModels; using PlumbingRepairDataModels.Models; using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.DI; namespace PlumbingRepairView { @@ -30,7 +31,7 @@ namespace PlumbingRepairView { if (_id.HasValue) { - _logger.LogInformation("Загрузка работы"); + _logger.LogInformation("Загрузка изделия"); try { var view = _logic.ReadElement(new WorkSearchModel { Id = _id.Value }); @@ -44,7 +45,7 @@ namespace PlumbingRepairView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки работы"); + _logger.LogError(ex, "Ошибка загрузки изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -52,7 +53,7 @@ namespace PlumbingRepairView private void LoadData() { - _logger.LogInformation("Загрузка компонент работы"); + _logger.LogInformation("Загрузка компонент изделия"); try { if (_workComponents != null) @@ -67,57 +68,53 @@ namespace PlumbingRepairView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент работы"); + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); - if (service is FormWorkComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - if (_workComponents.ContainsKey(form.Id)) - { - _workComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _workComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_workComponents.ContainsKey(form.Id)) + { + _workComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _workComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + + } + } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); - if (service is FormWorkComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _workComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - _workComponents[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 = _workComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _workComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + + } } } @@ -163,7 +160,7 @@ namespace PlumbingRepairView MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение работы"); + _logger.LogInformation("Сохранение изделия"); try { var model = new WorkBindingModel @@ -184,7 +181,7 @@ namespace PlumbingRepairView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения работы"); + _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/PlumbingRepair/PlumbingRepairView/FormWorks.cs b/PlumbingRepair/PlumbingRepairView/FormWorks.cs index cdb76cc..1954c23 100644 --- a/PlumbingRepair/PlumbingRepairView/FormWorks.cs +++ b/PlumbingRepair/PlumbingRepairView/FormWorks.cs @@ -1,6 +1,7 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.DI; namespace PlumbingRepairView { @@ -26,16 +27,8 @@ namespace PlumbingRepairView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["WorkComponents"].Visible = false; - dataGridView.Columns["WorkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - - } - _logger.LogInformation("Загрузка Работ"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка Работ"); } catch (Exception ex) { @@ -46,29 +39,23 @@ namespace PlumbingRepairView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormWork)); - if (service is FormWork 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(FormWork)); - if (service is FormWork 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/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs index 1811d37..58c344c 100644 --- a/PlumbingRepair/PlumbingRepairView/Program.cs +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -5,18 +5,17 @@ using NLog.Extensions.Logging; using PlumbingRepairBusinessLogic.BusinessLogics; using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.StoragesContracts; -using PlumbingRepairDatabaseImplement.Implements; +using PlumbingRepairFileImplement.Implements; using PlumbingRepairBusinessLogic.OfficePackage; using PlumbingRepairBusinessLogic.OfficePackage.Implements; using PlumbingRepairBusinessLogic.MailWorker; using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.DI; namespace PlumbingRepairView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. @@ -27,12 +26,10 @@ namespace PlumbingRepairView // 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, @@ -47,54 +44,51 @@ namespace PlumbingRepairView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Error during work with mail"); + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.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(); + Application.Run(DependencyManager.Instance.Resolve()); } - } -} \ No newline at end of file + private static void InitDependency() + { + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + } +} + -- 2.25.1 From 9de45e4b4352e9788ed2c659f770d0f28c5dd17b Mon Sep 17 00:00:00 2001 From: sardq Date: Thu, 16 May 2024 17:03:39 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BC=D0=B8=D0=BA=D1=80=D0=BE=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlumbingRepairView/FormMain.Designer.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs index 3347a2d..8ffcbe3 100644 --- a/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs @@ -44,6 +44,7 @@ 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(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -111,7 +112,8 @@ this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.выполнениеРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.созданиеБэкапаToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1548, 33); @@ -132,28 +134,28 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(220, 34); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // РаботыToolStripMenuItem // this.РаботыToolStripMenuItem.Name = "РаботыToolStripMenuItem"; - this.РаботыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.РаботыToolStripMenuItem.Size = new System.Drawing.Size(220, 34); this.РаботыToolStripMenuItem.Text = "Работы"; this.РаботыToolStripMenuItem.Click += new System.EventHandler(this.РаботыToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(220, 34); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // // исполнителиToolStripMenuItem // this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(220, 34); this.исполнителиToolStripMenuItem.Text = "Исполнители"; this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); // @@ -202,6 +204,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(166, 29); + this.созданиеБэкапаToolStripMenuItem.Text = "Создание бэкапа"; + this.созданиеБэкапаToolStripMenuItem.Click += new System.EventHandler(this.backupToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -242,5 +251,6 @@ private ToolStripMenuItem выполнениеРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem созданиеБэкапаToolStripMenuItem; } } \ No newline at end of file -- 2.25.1