From 7fab31cf54b745371cd85ab219973435e65596de Mon Sep 17 00:00:00 2001 From: Leozillo73 <76777036+Leozillo73@users.noreply.github.com> Date: Wed, 15 May 2024 23:45:29 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/BackUpLogic.cs | 97 ++++++++++++++++ .../Attributes/ColumnAttribute.cs | 31 +++++ .../Attributes/GridViewAutoSize.cs | 20 ++++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 +++ .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 +++ .../DI/DependencyManager.cs | 66 +++++++++++ .../DI/IDependencyContainer.cs | 40 +++++++ .../DI/IImplementationExtension.cs | 17 +++ .../DI/ServiceDependencyContainer.cs | 63 ++++++++++ .../DI/ServiceProviderLoader.cs | 55 +++++++++ .../FishFactoryContracts.csproj | 6 +- .../StoragesContracts/IBackUpInfo.cs | 15 +++ .../ViewModels/CannedViewModel.cs | 17 +-- .../ViewModels/ClientViewModel.cs | 15 +-- .../ViewModels/ComponentViewModel.cs | 11 +- .../ViewModels/ImplementerViewModel.cs | 8 +- .../ViewModels/MessageInfoViewModel.cs | 16 ++- .../ViewModels/OrderViewModel.cs | 43 ++++--- .../FishFactoryDataModels.csproj | 2 +- .../Models/IMessageInfoModel.cs | 2 +- .../FishFactoryDatabaseImplement.csproj | 6 +- .../Implements/BackUpInfo.cs | 32 ++++++ .../Implements/ImplementationExtension.cs | 26 +++++ .../Models/Canned.cs | 19 ++- .../Models/Client.cs | 18 ++- .../Models/Component.cs | 14 ++- .../Models/Implementer.cs | 11 +- .../Models/MessageInfo.cs | 14 ++- .../Models/Order.cs | 32 +++--- .../FishFactoryFileImplement.csproj | 5 + .../ImplementationExtension.cs | 27 +++++ .../Implements/BackUpInfo.cs | 44 +++++++ .../FishFactoryFileImplement/Models/Canned.cs | 18 ++- .../FishFactoryFileImplement/Models/Client.cs | 6 + .../Models/Component.cs | 15 ++- .../Models/Implementer.cs | 11 +- .../Models/MessageInfo.cs | 16 ++- .../FishFactoryFileImplement/Models/Order.cs | 31 +++-- .../FishFactoryListImplement.csproj | 5 + .../ImplementationExtension.cs | 27 +++++ .../Implements/BackUpInfo.cs | 22 ++++ .../Models/MessageInfo.cs | 2 +- FishFactory/FishFactoryRestApi/Program.cs | 4 +- .../FishFactoryView/DataGridViewExtension.cs | 51 +++++++++ FishFactory/FishFactoryView/FormCanned.cs | 84 +++++++------- FishFactory/FishFactoryView/FormCanneds.cs | 52 +++------ FishFactory/FishFactoryView/FormClients.cs | 10 +- FishFactory/FishFactoryView/FormComponents.cs | 31 +++-- .../FishFactoryView/FormImplementers.cs | 11 +- FishFactory/FishFactoryView/FormMail.cs | 12 +- .../FishFactoryView/FormMain.Designer.cs | 31 +++-- FishFactory/FishFactoryView/FormMain.cs | 98 ++++++++-------- FishFactory/FishFactoryView/Program.cs | 108 +++++++++--------- 54 files changed, 1076 insertions(+), 369 deletions(-) create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs create mode 100644 FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 FishFactory/FishFactoryContracts/DI/DependencyManager.cs create mode 100644 FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs create mode 100644 FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs create mode 100644 FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs create mode 100644 FishFactory/FishFactoryContracts/DI/ServiceProviderLoader.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Implements/ImplementationExtension.cs create mode 100644 FishFactory/FishFactoryFileImplement/ImplementationExtension.cs create mode 100644 FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryListImplement/ImplementationExtension.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryView/DataGridViewExtension.cs diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..cb79d7c --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,97 @@ +using FishFactoryDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; + +namespace FishFactoryBusinessLogic.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/FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs b/FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..27bd5ad --- /dev/null +++ b/FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs b/FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..d356369 --- /dev/null +++ b/FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBinidngModel.cs b/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..a594055 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs index 8056b9c..54e458e 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace FishFactoryContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + public int Id => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..6d89f54 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using FishFactoryContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/DI/DependencyManager.cs b/FishFactory/FishFactoryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..456a855 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs b/FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..07c8f41 --- /dev/null +++ b/FishFactory/FishFactoryContracts/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 FishFactoryContracts.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/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs b/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..727e11a --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs b/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..8fba88c --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/DI/ServiceProviderLoader.cs b/FishFactory/FishFactoryContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..7282cbb --- /dev/null +++ b/FishFactory/FishFactoryContracts/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 FishFactoryContracts.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/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj index 4a17316..637cbab 100644 --- a/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj +++ b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,6 +6,10 @@ enable + + + + diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..e80e2c2 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs index 049cb09..4e8d78e 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs @@ -1,15 +1,18 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System.ComponentModel; namespace FishFactoryContracts.ViewModels { public class CannedViewModel : ICannedModel { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string CannedName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary CannedComponents + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название консервы", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string CannedName { get; set; } = string.Empty; + [Column(title: "Цена", width: 70)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary CannedComponents { get; set; diff --git a/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs index ea81bb2..37830c2 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System.ComponentModel; namespace FishFactoryContracts.ViewModels @@ -6,12 +7,12 @@ namespace FishFactoryContracts.ViewModels public class ClientViewModel : IClientModel { public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs index ff1dca1..d4ee064 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs @@ -1,14 +1,15 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System.ComponentModel; namespace FishFactoryContracts.ViewModels { public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(title: "Название ингридиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column(title: "Цена", width: 150)] + public double Cost { get; set; } } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs index 5981d4d..048d9f6 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace FishFactoryContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; [DisplayName("Стаж работы")] diff --git a/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs index 074c950..bc11932 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,23 @@ namespace FishFactoryContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] + public int Id { get; set; } + [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: 120)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 120)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs index 0c2423c..af47438 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Enums; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Enums; using FishFactoryDataModels.Models; using System.ComponentModel; @@ -6,29 +7,33 @@ namespace FishFactoryContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int ClientId { get; set; } + [Column(title: "Номер", width: 90)] + public int Id { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Имя клиента", width: 190)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", width: 150)] public string? ImplementerFIO { get; set; } = null; + [Column(visible: false)] public int CannedId { get; set; } - [DisplayName("Изделие")] - public string CannedName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Консерва", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string CannedName { get; set; } = string.Empty; + [Column(title: "Количество", width: 100)] + public int Count { get; set; } + [Column(title: "Сумма", width: 120)] + public double Sum { get; set; } + [Column(title: "Статус", width: 70)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 120)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 120)] + public DateTime? DateImplement { get; set; } } } diff --git a/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj index 132c02c..27ac386 100644 --- a/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj +++ b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs b/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs index cf3b1cc..f3c7a16 100644 --- a/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs +++ b/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FishFactoryDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj index 2cb4489..f17b4a6 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -24,4 +24,8 @@ + + + + diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f5d5338 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using FishFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new FishFactoryDatabase(); + 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/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementationExtension.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementationExtension.cs new file mode 100644 index 0000000..4f053ac --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementationExtension.cs @@ -0,0 +1,26 @@ +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 3; + + 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/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs index 95623b6..f8251c4 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs @@ -3,18 +3,25 @@ using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + namespace FishFactoryDatabaseImplement.Models { - public class Canned : ICannedModel - { - public int Id { get; set; } - [Required] + [DataContract] + public class Canned : ICannedModel + { + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string CannedName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _cannedComponents = null; - [NotMapped] + [DataMember] + [NotMapped] public Dictionary CannedComponents { get diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs index 3e02694..cdb4fc0 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs @@ -7,20 +7,26 @@ 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 FishFactoryDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs index 6ace3fc..ac5e14f 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs @@ -3,14 +3,20 @@ using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + namespace FishFactoryDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ComponentName { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List CannedComponents { get; set; } = diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs index 160f7c4..668d003 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -8,22 +8,25 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace FishFactoryDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } - + [DataMember] [Required] public string ImplementerFIO { get; set; } = string.Empty; - + [DataMember] [Required] public string Password { get; set; } = string.Empty; - + [DataMember] [Required] public int WorkExperience { get; set; } - + [DataMember] [Required] public int Qualification { get; set; } diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs index 1f74155..53f9553 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs @@ -8,28 +8,34 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace FishFactoryDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { + [NotMapped] + public int Id { get; private set; } + + [DataMember] [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; set; } = string.Empty; + [DataMember] public int? ClientId { get; set; } public virtual Client? Client { get; set; } - + [DataMember] [Required] public string SenderName { get; set; } = string.Empty; - + [DataMember] [Required] public DateTime DateDelivery { get; set; } - + [DataMember] [Required] public string Subject { get; set; } = string.Empty; - + [DataMember] [Required] public string Body { get; set; } = string.Empty; diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs index 343c8a3..2ff6eaf 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs @@ -3,36 +3,40 @@ using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Enums; using FishFactoryDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace FishFactoryDatabaseImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - - [Required] + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public int ClientId { get; private set; } public virtual Client Client { get; private set; } = new(); - - [Required] + [DataMember] + [Required] public int CannedId { get; private set; } public virtual Canned Canned { get; set; } = new(); + [DataMember] public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } = new(); - + [DataMember] [Required] public int Count { get; private set; } - - [Required] + [DataMember] + [Required] public double Sum { get; private set; } - - [Required] + [DataMember] + [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } diff --git a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj index 35ac74e..00b3ad9 100644 --- a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj +++ b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj @@ -11,4 +11,9 @@ + + + + + diff --git a/FishFactory/FishFactoryFileImplement/ImplementationExtension.cs b/FishFactory/FishFactoryFileImplement/ImplementationExtension.cs new file mode 100644 index 0000000..3935dc1 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/ImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using FishFactoryFileImplement.Implements; + +namespace FishFactoryFileImplement +{ + public class ImplementationExtension : 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/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..45b7ee9 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,44 @@ +using FishFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.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/FishFactory/FishFactoryFileImplement/Models/Canned.cs b/FishFactory/FishFactoryFileImplement/Models/Canned.cs index 3c2509e..7bfd10e 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Canned.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Canned.cs @@ -1,18 +1,24 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FishFactoryFileImplement.Models { - public class Canned : ICannedModel - { - public int Id { get; private set; } - public string CannedName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataContract] + public class Canned : ICannedModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public string CannedName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _cannedComponents = null; - public Dictionary CannedComponents + [DataMember] + public Dictionary CannedComponents { get { diff --git a/FishFactory/FishFactoryFileImplement/Models/Client.cs b/FishFactory/FishFactoryFileImplement/Models/Client.cs index a6aefb7..26aff1a 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Client.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FishFactoryFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; set; } + [DataMember] public string ClientFIO { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) diff --git a/FishFactory/FishFactoryFileImplement/Models/Component.cs b/FishFactory/FishFactoryFileImplement/Models/Component.cs index 4150f8c..a9cfea5 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Component.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Component.cs @@ -1,14 +1,19 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace FishFactoryFileImplement.Models { - public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [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) { if (model == null) diff --git a/FishFactory/FishFactoryFileImplement/Models/Implementer.cs b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs index 73c959e..af65ddb 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Implementer.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs @@ -4,22 +4,25 @@ using FishFactoryDataModels.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 FishFactoryFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(XElement element) diff --git a/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs index 8fe9aa3..eb00df3 100644 --- a/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs @@ -4,24 +4,30 @@ using FishFactoryDataModels.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 FishFactoryFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] + public int Id { get; private set; } + + [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) diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index 8bbac29..eeb357e 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -1,4 +1,5 @@ -using System.Xml.Linq; +using System.Runtime.Serialization; +using System.Xml.Linq; using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModels.Enums; @@ -6,17 +7,27 @@ using FishFactoryDataModels.Models; namespace FishFactoryFileImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int CannedId { get; private set; } - public int Count { get; private set; } - public int ClientId { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public int CannedId { get; private set; } + [DataMember] + public int Count { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; set; } + [DataMember] public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj index 35ac74e..00b3ad9 100644 --- a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj +++ b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj @@ -11,4 +11,9 @@ + + + + + diff --git a/FishFactory/FishFactoryListImplement/ImplementationExtension.cs b/FishFactory/FishFactoryListImplement/ImplementationExtension.cs new file mode 100644 index 0000000..20c07bb --- /dev/null +++ b/FishFactory/FishFactoryListImplement/ImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using FishFactoryListImplement.Implements; + +namespace FishFactoryListImplement +{ + internal class ImplementationExtension : 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/FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ef27faf --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using FishFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.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/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs index ed4f15f..07949a5 100644 --- a/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs @@ -22,7 +22,7 @@ namespace FishFactoryListImplement.Models public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; - + public int Id => throw new NotImplementedException(); public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/FishFactory/FishFactoryRestApi/Program.cs b/FishFactory/FishFactoryRestApi/Program.cs index 8424bf9..f652ba8 100644 --- a/FishFactory/FishFactoryRestApi/Program.cs +++ b/FishFactory/FishFactoryRestApi/Program.cs @@ -5,7 +5,6 @@ using FishFactoryDatabaseImplement.Implements; using FishFactoryBusinessLogic.MailWorker; using FishFactoryContracts.BindingModels; using Microsoft.OpenApi.Models; -using FishFactoryBusinessLogic.MailWorker; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); @@ -24,8 +23,7 @@ builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at -https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { diff --git a/FishFactory/FishFactoryView/DataGridViewExtension.cs b/FishFactory/FishFactoryView/DataGridViewExtension.cs new file mode 100644 index 0000000..36f990d --- /dev/null +++ b/FishFactory/FishFactoryView/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using FishFactoryContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryView +{ + 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/FishFactory/FishFactoryView/FormCanned.cs b/FishFactory/FishFactoryView/FormCanned.cs index b58b24d..151c2c9 100644 --- a/FishFactory/FishFactoryView/FormCanned.cs +++ b/FishFactory/FishFactoryView/FormCanned.cs @@ -3,6 +3,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; using FishFactoryContracts.SearchModels; using FishFactoryDataModels.Models; +using FishFactoryContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -81,53 +82,46 @@ namespace FishFactoryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); - if (service is FormCannedComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - if (_CannedComponents.ContainsKey(form.Id)) - { - _CannedComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _CannedComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + return; + } + _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_CannedComponents.ContainsKey(form.Id)) + { + _CannedComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _CannedComponents.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(FormCannedComponent)); - if (service is FormCannedComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _CannedComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - _CannedComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _CannedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _CannedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + + } private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) diff --git a/FishFactory/FishFactoryView/FormCanneds.cs b/FishFactory/FishFactoryView/FormCanneds.cs index 01fddb3..a2be0eb 100644 --- a/FishFactory/FishFactoryView/FormCanneds.cs +++ b/FishFactory/FishFactoryView/FormCanneds.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -31,16 +32,8 @@ namespace FishFactoryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["CannedComponents"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка изделий"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { @@ -50,14 +43,11 @@ namespace FishFactoryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); - if (service is FormCanned 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) { @@ -78,29 +68,15 @@ namespace FishFactoryView { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление изделия"); - try - { - if (!_logic.Delete(new CannedBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + LoadData(); } } - } + + } private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); diff --git a/FishFactory/FishFactoryView/FormClients.cs b/FishFactory/FishFactoryView/FormClients.cs index 6b3405f..445b751 100644 --- a/FishFactory/FishFactoryView/FormClients.cs +++ b/FishFactory/FishFactoryView/FormClients.cs @@ -26,14 +26,8 @@ namespace FishFactoryView { 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/FishFactory/FishFactoryView/FormComponents.cs b/FishFactory/FishFactoryView/FormComponents.cs index 18bafdc..f5bfeb6 100644 --- a/FishFactory/FishFactoryView/FormComponents.cs +++ b/FishFactory/FishFactoryView/FormComponents.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using FishFactoryContracts.DI; namespace FishFactoryView { @@ -50,29 +51,23 @@ namespace FishFactoryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } private void ButtonDel_Click(object sender, EventArgs e) diff --git a/FishFactory/FishFactoryView/FormImplementers.cs b/FishFactory/FishFactoryView/FormImplementers.cs index 295d927..0897b28 100644 --- a/FishFactory/FishFactoryView/FormImplementers.cs +++ b/FishFactory/FishFactoryView/FormImplementers.cs @@ -29,15 +29,8 @@ namespace FishFactoryView { 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) { diff --git a/FishFactory/FishFactoryView/FormMail.cs b/FishFactory/FishFactoryView/FormMail.cs index b3f973b..7a382ca 100644 --- a/FishFactory/FishFactoryView/FormMail.cs +++ b/FishFactory/FishFactoryView/FormMail.cs @@ -28,16 +28,8 @@ namespace FishFactoryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка почтовых собщений"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка почтовых собщений"); } catch (Exception ex) { diff --git a/FishFactory/FishFactoryView/FormMain.Designer.cs b/FishFactory/FishFactoryView/FormMain.Designer.cs index 4423a2a..a6ba0e6 100644 --- a/FishFactory/FishFactoryView/FormMain.Designer.cs +++ b/FishFactory/FishFactoryView/FormMain.Designer.cs @@ -39,13 +39,14 @@ componentCannedToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem(); startWorkToolStripMenuItem = new ToolStripMenuItem(); + MailsToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - MailsToolStripMenuItem = new ToolStripMenuItem(); + createbackupToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -53,7 +54,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem, reportsToolStripMenuItem, startWorkToolStripMenuItem, MailsToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem, reportsToolStripMenuItem, startWorkToolStripMenuItem, MailsToolStripMenuItem, createbackupToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(5, 2, 0, 2); @@ -71,28 +72,28 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Size = new Size(145, 22); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // изделияToolStripMenuItem // изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(180, 22); + изделияToolStripMenuItem.Size = new Size(145, 22); изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // // ClientToolStripMenuItem // ClientToolStripMenuItem.Name = "ClientToolStripMenuItem"; - ClientToolStripMenuItem.Size = new Size(180, 22); + ClientToolStripMenuItem.Size = new Size(145, 22); ClientToolStripMenuItem.Text = "Клиент"; ClientToolStripMenuItem.Click += ClientToolStripMenuItem_Click; // // employersToolStripMenuItem // employersToolStripMenuItem.Name = "employersToolStripMenuItem"; - employersToolStripMenuItem.Size = new Size(180, 22); + employersToolStripMenuItem.Size = new Size(145, 22); employersToolStripMenuItem.Text = "Сотрудники"; employersToolStripMenuItem.Click += employersToolStripMenuItem_Click; // @@ -131,6 +132,13 @@ startWorkToolStripMenuItem.Text = "Старт работ"; startWorkToolStripMenuItem.Click += startWorkToolStripMenuItem_Click; // + // MailsToolStripMenuItem + // + MailsToolStripMenuItem.Name = "MailsToolStripMenuItem"; + MailsToolStripMenuItem.Size = new Size(53, 20); + MailsToolStripMenuItem.Text = "Почта"; + MailsToolStripMenuItem.Click += MailsToolStripMenuItem_Click; + // // dataGridView // dataGridView.AllowUserToAddRows = false; @@ -201,12 +209,12 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += ButtonRef_Click; // - // MailsToolStripMenuItem + // createbackupToolStripMenuItem // - MailsToolStripMenuItem.Name = "MailsToolStripMenuItem"; - MailsToolStripMenuItem.Size = new Size(53, 20); - MailsToolStripMenuItem.Text = "Почта"; - MailsToolStripMenuItem.Click += MailsToolStripMenuItem_Click; + createbackupToolStripMenuItem.Name = "createbackupToolStripMenuItem"; + createbackupToolStripMenuItem.Size = new Size(97, 20); + createbackupToolStripMenuItem.Text = "Создать бекап"; + createbackupToolStripMenuItem.Click += createbackupToolStripMenuItem_Click; // // FormMain // @@ -252,5 +260,6 @@ private ToolStripMenuItem startWorkToolStripMenuItem; private ToolStripMenuItem employersToolStripMenuItem; private ToolStripMenuItem MailsToolStripMenuItem; + private ToolStripMenuItem createbackupToolStripMenuItem; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.cs b/FishFactory/FishFactoryView/FormMain.cs index dcce12a..ee911dd 100644 --- a/FishFactory/FishFactoryView/FormMain.cs +++ b/FishFactory/FishFactoryView/FormMain.cs @@ -10,6 +10,7 @@ using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using FishFactoryContracts.DI; using System.Windows.Forms; namespace FishFactoryView @@ -20,13 +21,15 @@ namespace FishFactoryView 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) { @@ -36,17 +39,7 @@ namespace FishFactoryView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["CannedId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientEmail"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -57,28 +50,19 @@ namespace FishFactoryView } 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(FormCanneds)); - if (service is FormCanneds 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 ButtonTakeOrderInWork_Click(object sender, EventArgs e) { @@ -173,52 +157,62 @@ namespace FishFactoryView private void componentCannedToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportCannedComponents)); - if (service is FormReportCannedComponents 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 ClientToolStripMenuItem_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 startWorkToolStripMenuItem_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 employersToolStripMenuItem_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 MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); - if (service is FormMail form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void createbackupToolStripMenuItem_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/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 1bc2b46..a292850 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -11,6 +11,7 @@ using FishFactoryContracts.StoragesContracts; using FishFactoryDatabaseImplement.Implements; using System; using Microsoft.EntityFrameworkCore.Design; +using FishFactoryContracts.DI; namespace FishFactoryView { @@ -22,17 +23,15 @@ namespace FishFactoryView /// The main entry point for the application. /// [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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 +46,53 @@ namespace FishFactoryView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Mails Problem"); } - Application.Run(_serviceProvider.GetRequiredService()); - } - 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(); - services.AddTransient(); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + + 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(); } } \ No newline at end of file -- 2.25.1 From 1e39addf8099c6ff0e0a5efbd78ba3466dc4f635 Mon Sep 17 00:00:00 2001 From: Leozillo73 <76777036+Leozillo73@users.noreply.github.com> Date: Wed, 15 May 2024 23:56:38 +0400 Subject: [PATCH 2/2] fix --- .../FishFactoryDatabaseImplement.csproj | 2 +- .../FishFactoryFileImplement/FishFactoryFileImplement.csproj | 2 +- .../FishFactoryListImplement/FishFactoryListImplement.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj index f17b4a6..c0e78cd 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj @@ -25,7 +25,7 @@ - + diff --git a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj index 00b3ad9..85f10b8 100644 --- a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj +++ b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj @@ -12,7 +12,7 @@ - + diff --git a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj index 00b3ad9..85f10b8 100644 --- a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj +++ b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj @@ -12,7 +12,7 @@ - + -- 2.25.1