From 46dc0fbc6d3b313b80deaa7e2fca41284c821411 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Thu, 16 May 2024 22:56:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + .../BusinessLogics/BackUpLogic.cs | 98 +++++++++++++++++++ .../Attributes/ColumnAttribute.cs | 31 ++++++ .../Attributes/GridViewAutoSize.cs | 20 ++++ .../BindingModels/BackUpSaveBindingModel.cs | 13 +++ .../BindingModels/MessageInfoBindingModel.cs | 4 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 14 +++ .../DI/DependencyManager.cs | 38 +++++++ .../DI/IDependencyContainer.cs | 17 ++++ .../DI/IImplementationExtension.cs | 14 +++ .../DI/ServiceDependencyContainer.cs | 51 ++++++++++ .../DI/ServiceProviderLoader.cs | 53 ++++++++++ .../DI/UnityDependencyContainer.cs | 55 +++++++++++ .../FishFactoryContracts.csproj | 8 ++ .../StoragesContracts/IBackUpInfo.cs | 14 +++ .../ViewModels/CannedViewModel.cs | 17 ++-- .../ViewModels/ClientViewModel.cs | 18 ++-- .../ViewModels/ComponentViewModel.cs | 14 +-- .../ViewModels/ImplementerViewModel.cs | 12 ++- .../ViewModels/MessageInfoViewModel.cs | 29 +++--- .../ViewModels/OrderViewModel.cs | 46 +++++---- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 27 +++++ .../FishFactoryDatabaseImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 32 ++++++ .../Models/Canned.cs | 16 ++- .../Models/Client.cs | 18 ++-- .../Models/Component.cs | 13 ++- .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 13 +++ .../Models/Order.cs | 27 +++-- .../FileImplementationExtension.cs | 27 +++++ .../FishFactoryFileImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 34 +++++++ .../FishFactoryFileImplement/Models/Canned.cs | 16 ++- .../FishFactoryFileImplement/Models/Client.cs | 16 ++- .../Models/Component.cs | 13 ++- .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 14 ++- .../FishFactoryFileImplement/Models/Order.cs | 31 ++++-- .../FishFactoryListImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 22 +++++ .../ListImplementationExtension.cs | 27 +++++ .../Models/MessageInfo.cs | 2 +- .../FishFactoryView/DataGridViewExtension.cs | 50 ++++++++++ FishFactory/FishFactoryView/FormCanned.cs | 11 +-- FishFactory/FishFactoryView/FormCanneds.cs | 16 +-- FishFactory/FishFactoryView/FormClients.cs | 11 +-- FishFactory/FishFactoryView/FormComponents.cs | 18 +--- .../FishFactoryView/FormImplementers.cs | 21 +--- FishFactory/FishFactoryView/FormViewMail.cs | 9 +- .../FishFactoryView/MainForm.Designer.cs | 62 ++++++------ FishFactory/FishFactoryView/MainForm.cs | 60 +++++++----- FishFactory/FishFactoryView/Program.cs | 86 ++++++++-------- 54 files changed, 1011 insertions(+), 277 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/BackUpSaveBindingModel.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/DI/UnityDependencyContainer.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryFileImplement/FileImplementationExtension.cs create mode 100644 FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs create mode 100644 FishFactory/FishFactoryListImplement/ListImplementationExtension.cs create mode 100644 FishFactory/FishFactoryView/DataGridViewExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..359c4db 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +ImplementationExtensions +BusinessLogicExtensions # Mono auto generated files mono_crash.* diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..01c346e --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,98 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; +using FishFactoryDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace 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(BackUpSaveBindingModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + ZipFile.CreateFromDirectory(model.FolderName, fileName); + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs b/FishFactory/FishFactoryContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..1c101b6 --- /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; + } + } +} diff --git a/FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs b/FishFactory/FishFactoryContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..eec0d25 --- /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 + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..726be1e --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/BackUpSaveBindingModel.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 BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs index 3ae0bfa..9f1071b 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ 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(); + } } diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..752495b --- /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(BackUpSaveBindingModel model); + } +} diff --git a/FishFactory/FishFactoryContracts/DI/DependencyManager.cs b/FishFactory/FishFactoryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..2d7d648 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/DependencyManager.cs @@ -0,0 +1,38 @@ +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(); + } +} diff --git a/FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs b/FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..69bc8af --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/IDependencyContainer.cs @@ -0,0 +1,17 @@ +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(); + } +} diff --git a/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs b/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..4f12794 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +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(); + } +} diff --git a/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs b/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..1732dc6 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,51 @@ +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..ea8ecc8 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,53 @@ +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 + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = + (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + private static string TryGetImplementationExtensionsFolder() + { + var directory = new + DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/FishFactory/FishFactoryContracts/DI/UnityDependencyContainer.cs b/FishFactory/FishFactoryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..4c2d4f1 --- /dev/null +++ b/FishFactory/FishFactoryContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; + +namespace FishFactoryContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _container.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj index 41afc59..271c7bf 100644 --- a/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj +++ b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj @@ -6,6 +6,14 @@ enable + + + + + + + + diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..578682b --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +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); + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs index e8b8840..00ae315 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,13 @@ 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 { get; set; } = new(); + [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: 150)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary CannedComponents { get; set; } = new(); } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ClientViewModel.cs index ea77785..84fc7de 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; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ 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(visible: false)] + public int Id { get; set; } + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", width: 150)] + 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 8836d4e..c971be7 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using FishFactoryDataModels.Models; +using FishFactoryContracts.Attributes; +using FishFactoryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ 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(visible: false)] + public int Id { 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 e086a24..3444e66 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,14 +11,15 @@ 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: 50)] public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 50)] public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/MessageInfoViewModel.cs index e1cf599..fe4cb7e 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,15 +11,19 @@ namespace FishFactoryContracts.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; + + public int Id => throw new NotImplementedException(); + } } diff --git a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs index d7fc040..44e721a 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; using System.Collections.Generic; @@ -11,26 +12,29 @@ namespace FishFactoryContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int ClientId { get; set; } - public int? ImplementerId { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - public int CannedId { get; set; } - [DisplayName("Консерва")] - public string CannedName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(title: "Номер", width: 50)] + public int Id { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int CannedId { get; set; } + [Column(title: "Консерва", width: 100)] + public string CannedName { get; set; } = string.Empty; + [Column(title: "Исполнитель", width: 130)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Количество", width: 100)] + public int Count { get; set; } + [Column(title: "Сумма", width: 50)] + public double Sum { get; set; } + [Column(title: "Статус", width: 50)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } } } diff --git a/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs b/FishFactory/FishFactoryDataModels/Models/IMessageInfoModel.cs index 5732ac9..33d5e8b 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/DatabaseImplementationExtension.cs b/FishFactory/FishFactoryDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..9788c4b --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using FishFactoryDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj index 93e3987..a6aa08e 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..1841688 --- /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; + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs index 3012215..53fabcf 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs @@ -8,19 +8,25 @@ using System.Text; using System.Threading.Tasks; using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; +using System.Runtime.Serialization; namespace FishFactoryDatabaseImplement.Models { - public class Canned : ICannedModel + [DataContract] + public class Canned : ICannedModel { - public int Id { get; set; } - [Required] + [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 a8c58b5..585976e 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Client.cs @@ -8,20 +8,24 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; 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")] public virtual List Orders { get; set; } = new(); [ForeignKey("ClientId")] diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs index 6c53e49..dcb64fe 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Component.cs @@ -8,15 +8,20 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +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 c237337..e86cad8 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -8,18 +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; private set; } + [DataMember] [Required] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public int Qualification { get; set; } = 0; + [DataMember] [Required] public int WorkExperience { get; set; } = 0; [ForeignKey("ImplementerId")] diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs index 71f0062..1032b42 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/MessageInfo.cs @@ -5,19 +5,31 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace FishFactoryDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] [Key] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] + [Required] public string SenderName { get; private set; } = string.Empty; + [DataMember] + [Required] public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + [Required] public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) @@ -46,5 +58,6 @@ namespace FishFactoryDatabaseImplement.Models DateDelivery = DateDelivery, Subject = Subject, }; + public int Id => throw new NotImplementedException(); } } diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs index 92f1d21..0a3b9d9 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs @@ -6,27 +6,38 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace FishFactoryDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } + [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; } - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } - [Required] + [DataMember] + public DateTime? DateImplement { get; private set; } + [DataMember] + [Required] public int CannedId { get; private set; } public virtual Canned Canned { get; set; } public virtual Client Client { get; set; } diff --git a/FishFactory/FishFactoryFileImplement/FileImplementationExtension.cs b/FishFactory/FishFactoryFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..ff0596a --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using FishFactoryFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj index f802d25..b9b731d 100644 --- a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj +++ b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..9a8020a --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,34 @@ +using FishFactoryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryFileImplement/Models/Canned.cs b/FishFactory/FishFactoryFileImplement/Models/Canned.cs index 625e9c2..bf9402e 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Canned.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Canned.cs @@ -7,17 +7,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace FishFactoryFileImplement.Models { - public class Canned : ICannedModel + [DataContract] + public class Canned : ICannedModel { - public int Id { get; private set; } - public string CannedName { get; private set; } = string.Empty; - public double Price { get; private set; } + [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 8ba38e0..4e1bbd2 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Client.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Client.cs @@ -4,18 +4,24 @@ 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 { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; set; } - public string ClientFIO { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + [DataMember] + public int Id { get; set; } + [DataMember] + public string ClientFIO { get; set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) { if (model == null) diff --git a/FishFactory/FishFactoryFileImplement/Models/Component.cs b/FishFactory/FishFactoryFileImplement/Models/Component.cs index 3d4516d..05d9ec8 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Component.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Component.cs @@ -7,14 +7,19 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace FishFactoryFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; private 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 ca8fcbd..11c58a6 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Implementer.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs @@ -4,18 +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; set; } = string.Empty; + [DataMember] public int Qualification { get; set; } = 0; + [DataMember] public int WorkExperience { get; set; } = 0; public static Implementer? Create(ImplementerBindingModel model) { diff --git a/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs index d476504..ad9231a 100644 --- a/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryFileImplement/Models/MessageInfo.cs @@ -4,24 +4,27 @@ 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 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) @@ -76,5 +79,6 @@ namespace FishFactoryFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + public int Id => throw new NotImplementedException(); } } diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index 8742d6e..3b77b68 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -9,20 +9,31 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace FishFactoryFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - public int CannedId { 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; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public int CannedId { 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; } = 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 b2c107f..1e98352 100644 --- a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj +++ b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs b/FishFactory/FishFactoryListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..7a907fe --- /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(); + } + } +} diff --git a/FishFactory/FishFactoryListImplement/ListImplementationExtension.cs b/FishFactory/FishFactoryListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..bd60b08 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using FishFactoryContracts.DI; +using FishFactoryContracts.StoragesContracts; +using FishFactoryListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs b/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs index b30888c..0547851 100644 --- a/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs +++ b/FishFactory/FishFactoryListImplement/Models/MessageInfo.cs @@ -47,6 +47,6 @@ namespace FishFactoryListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - + public int Id => throw new NotImplementedException(); } } diff --git a/FishFactory/FishFactoryView/DataGridViewExtension.cs b/FishFactory/FishFactoryView/DataGridViewExtension.cs new file mode 100644 index 0000000..53bcca8 --- /dev/null +++ b/FishFactory/FishFactoryView/DataGridViewExtension.cs @@ -0,0 +1,50 @@ +using FishFactoryContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryView +{ + public static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/FishFactory/FishFactoryView/FormCanned.cs b/FishFactory/FishFactoryView/FormCanned.cs index f2b79e5..e78b62f 100644 --- a/FishFactory/FishFactoryView/FormCanned.cs +++ b/FishFactory/FishFactoryView/FormCanned.cs @@ -1,5 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.DI; using FishFactoryContracts.SearchModels; using FishFactoryDataModels.Models; using Microsoft.Extensions.Logging; @@ -78,9 +79,8 @@ namespace FishFactoryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); - if (service is FormCannedComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormCannedComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -107,9 +107,8 @@ namespace FishFactoryView { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); - if (service is FormCannedComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormCannedComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/FishFactory/FishFactoryView/FormCanneds.cs b/FishFactory/FishFactoryView/FormCanneds.cs index b9f762b..dd6eada 100644 --- a/FishFactory/FishFactoryView/FormCanneds.cs +++ b/FishFactory/FishFactoryView/FormCanneds.cs @@ -1,5 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -31,15 +32,8 @@ namespace FishFactoryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["CannedComponents"].Visible = false; - } - _logger.LogInformation("Загрузка консервы"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка консервы"); } catch (Exception ex) { @@ -49,7 +43,7 @@ namespace FishFactoryView } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCanned form) { if (form.ShowDialog() == DialogResult.OK) @@ -63,7 +57,7 @@ namespace FishFactoryView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCanned form) { var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/FishFactory/FishFactoryView/FormClients.cs b/FishFactory/FishFactoryView/FormClients.cs index 25e174f..29747c1 100644 --- a/FishFactory/FishFactoryView/FormClients.cs +++ b/FishFactory/FishFactoryView/FormClients.cs @@ -30,15 +30,8 @@ namespace FishFactoryView { try { - var list = _clientLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].Visible = false; - } - _logger.LogInformation("Load clients"); + dataGridView.FillAndConfigGrid(_clientLogic.ReadList(null)); + _logger.LogInformation("Load clients"); } catch (Exception ex) { diff --git a/FishFactory/FishFactoryView/FormComponents.cs b/FishFactory/FishFactoryView/FormComponents.cs index 4089fa0..700f82e 100644 --- a/FishFactory/FishFactoryView/FormComponents.cs +++ b/FishFactory/FishFactoryView/FormComponents.cs @@ -1,5 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -32,15 +33,8 @@ namespace FishFactoryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { @@ -51,8 +45,7 @@ namespace FishFactoryView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -65,8 +58,7 @@ namespace FishFactoryView { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { form.Id = diff --git a/FishFactory/FishFactoryView/FormImplementers.cs b/FishFactory/FishFactoryView/FormImplementers.cs index 0ef3f47..96085eb 100644 --- a/FishFactory/FishFactoryView/FormImplementers.cs +++ b/FishFactory/FishFactoryView/FormImplementers.cs @@ -1,5 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,20 +34,7 @@ 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; - dataGridView.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -58,7 +46,7 @@ namespace FishFactoryView } private void buttonCreate_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -72,8 +60,7 @@ namespace FishFactoryView { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = diff --git a/FishFactory/FishFactoryView/FormViewMail.cs b/FishFactory/FishFactoryView/FormViewMail.cs index d53566c..8fcd1c0 100644 --- a/FishFactory/FishFactoryView/FormViewMail.cs +++ b/FishFactory/FishFactoryView/FormViewMail.cs @@ -27,14 +27,7 @@ namespace FishFactoryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) diff --git a/FishFactory/FishFactoryView/MainForm.Designer.cs b/FishFactory/FishFactoryView/MainForm.Designer.cs index 88cbfd8..7046ce0 100644 --- a/FishFactory/FishFactoryView/MainForm.Designer.cs +++ b/FishFactory/FishFactoryView/MainForm.Designer.cs @@ -44,6 +44,7 @@ OrdersToolStripMenuItem = new ToolStripMenuItem(); StartingWorkToolStripMenuItem = new ToolStripMenuItem(); mailToolStripMenuItem = new ToolStripMenuItem(); + CreateBackUpToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -51,20 +52,18 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(-1, 22); - dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Location = new Point(-1, 29); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(762, 343); + dataGridView.Size = new Size(871, 457); dataGridView.TabIndex = 1; // // button1 // - button1.Location = new Point(774, 41); - button1.Margin = new Padding(3, 2, 3, 2); + button1.Location = new Point(885, 55); button1.Name = "button1"; - button1.Size = new Size(157, 22); + button1.Size = new Size(179, 29); button1.TabIndex = 2; button1.Text = "Создать заказ"; button1.UseVisualStyleBackColor = true; @@ -72,10 +71,9 @@ // // button4 // - button4.Location = new Point(774, 100); - button4.Margin = new Padding(3, 2, 3, 2); + button4.Location = new Point(885, 133); button4.Name = "button4"; - button4.Size = new Size(157, 22); + button4.Size = new Size(179, 29); button4.TabIndex = 5; button4.Text = "Заказ выдан"; button4.UseVisualStyleBackColor = true; @@ -83,10 +81,9 @@ // // button5 // - button5.Location = new Point(774, 154); - button5.Margin = new Padding(3, 2, 3, 2); + button5.Location = new Point(885, 205); button5.Name = "button5"; - button5.Size = new Size(157, 22); + button5.Size = new Size(179, 29); button5.TabIndex = 6; button5.Text = "Обновить список"; button5.UseVisualStyleBackColor = true; @@ -95,11 +92,11 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { spravochnikToolStripMenuItem, otchetToolStripMenuItem, StartingWorkToolStripMenuItem, mailToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { spravochnikToolStripMenuItem, otchetToolStripMenuItem, StartingWorkToolStripMenuItem, mailToolStripMenuItem, CreateBackUpToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(5, 2, 0, 2); - menuStrip1.Size = new Size(942, 24); + menuStrip1.Padding = new Padding(6, 3, 0, 3); + menuStrip1.Size = new Size(1077, 30); menuStrip1.TabIndex = 7; menuStrip1.Text = "menuStrip1"; // @@ -107,34 +104,34 @@ // spravochnikToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, ClientsToolStripMenuItem, ImplementerToolStripMenuItem }); spravochnikToolStripMenuItem.Name = "spravochnikToolStripMenuItem"; - spravochnikToolStripMenuItem.Size = new Size(94, 20); + spravochnikToolStripMenuItem.Size = new Size(117, 24); spravochnikToolStripMenuItem.Text = "Справочники"; // // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(149, 22); + компонентыToolStripMenuItem.Size = new Size(185, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; // // консервыToolStripMenuItem // консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; - консервыToolStripMenuItem.Size = new Size(149, 22); + консервыToolStripMenuItem.Size = new Size(185, 26); консервыToolStripMenuItem.Text = "Консервы"; консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click; // // ClientsToolStripMenuItem // ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(149, 22); + ClientsToolStripMenuItem.Size = new Size(185, 26); ClientsToolStripMenuItem.Text = "Клиенты"; ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // // ImplementerToolStripMenuItem // ImplementerToolStripMenuItem.Name = "ImplementerToolStripMenuItem"; - ImplementerToolStripMenuItem.Size = new Size(149, 22); + ImplementerToolStripMenuItem.Size = new Size(185, 26); ImplementerToolStripMenuItem.Text = "Исполнители"; ImplementerToolStripMenuItem.Click += ImplementerToolStripMenuItem_Click; // @@ -142,56 +139,62 @@ // otchetToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentCannedToolStripMenuItem, OrdersToolStripMenuItem }); otchetToolStripMenuItem.Name = "otchetToolStripMenuItem"; - otchetToolStripMenuItem.Size = new Size(60, 20); + otchetToolStripMenuItem.Size = new Size(73, 24); otchetToolStripMenuItem.Text = "Отчёты"; // // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(218, 22); + ComponentsToolStripMenuItem.Size = new Size(276, 26); ComponentsToolStripMenuItem.Text = "Список компонентов"; ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // ComponentCannedToolStripMenuItem // ComponentCannedToolStripMenuItem.Name = "ComponentCannedToolStripMenuItem"; - ComponentCannedToolStripMenuItem.Size = new Size(218, 22); + ComponentCannedToolStripMenuItem.Size = new Size(276, 26); ComponentCannedToolStripMenuItem.Text = "Компоненты по изделиям"; ComponentCannedToolStripMenuItem.Click += ComponentCannedToolStripMenuItem_Click; // // OrdersToolStripMenuItem // OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; - OrdersToolStripMenuItem.Size = new Size(218, 22); + OrdersToolStripMenuItem.Size = new Size(276, 26); OrdersToolStripMenuItem.Text = "Список заказов"; OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // StartingWorkToolStripMenuItem // StartingWorkToolStripMenuItem.Name = "StartingWorkToolStripMenuItem"; - StartingWorkToolStripMenuItem.Size = new Size(92, 20); + StartingWorkToolStripMenuItem.Size = new Size(114, 24); StartingWorkToolStripMenuItem.Text = "Запуск работ"; StartingWorkToolStripMenuItem.Click += StartingWorkToolStripMenuItem_Click; // // mailToolStripMenuItem // mailToolStripMenuItem.Name = "mailToolStripMenuItem"; - mailToolStripMenuItem.Size = new Size(102, 20); + mailToolStripMenuItem.Size = new Size(126, 24); mailToolStripMenuItem.Text = "Отчет на почту"; mailToolStripMenuItem.Click += mailToolStripMenuItem_Click; // + // CreateBackUpToolStripMenuItem + // + CreateBackUpToolStripMenuItem.Name = "CreateBackUpToolStripMenuItem"; + CreateBackUpToolStripMenuItem.Size = new Size(63, 24); + CreateBackUpToolStripMenuItem.Text = "Бэкап"; + CreateBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // MainForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(942, 365); + ClientSize = new Size(1077, 487); Controls.Add(button5); Controls.Add(button4); Controls.Add(button1); Controls.Add(dataGridView); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; - Margin = new Padding(3, 2, 3, 2); Name = "MainForm"; Text = "Рыбный завод"; Load += FormMain_Load; @@ -219,5 +222,6 @@ private ToolStripMenuItem StartingWorkToolStripMenuItem; private ToolStripMenuItem ImplementerToolStripMenuItem; private ToolStripMenuItem mailToolStripMenuItem; + private ToolStripMenuItem CreateBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/MainForm.cs b/FishFactory/FishFactoryView/MainForm.cs index 4acf0e3..e43933d 100644 --- a/FishFactory/FishFactoryView/MainForm.cs +++ b/FishFactory/FishFactoryView/MainForm.cs @@ -2,7 +2,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; using FishFactoryDataModels.Enums; using Microsoft.Extensions.Logging; -using System.Windows.Forms; +using FishFactoryContracts.DI; namespace FishFactoryView { @@ -12,13 +12,15 @@ namespace FishFactoryView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public MainForm(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) { @@ -29,14 +31,7 @@ namespace FishFactoryView _logger.LogInformation(" "); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["CannedId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation(" "); } catch (Exception ex) @@ -48,8 +43,7 @@ namespace FishFactoryView private void ComponentToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponents form) { form.ShowDialog(); @@ -57,7 +51,7 @@ namespace FishFactoryView } private void CannedToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCanneds)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCanneds form) { form.ShowDialog(); @@ -65,8 +59,7 @@ namespace FishFactoryView } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -126,7 +119,7 @@ namespace FishFactoryView private void ComponentCannedToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportCannedComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportCannedComponents form) { form.ShowDialog(); @@ -135,7 +128,7 @@ namespace FishFactoryView private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -143,7 +136,7 @@ namespace FishFactoryView } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -151,7 +144,7 @@ namespace FishFactoryView } private void ImplementerToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -159,18 +152,41 @@ namespace FishFactoryView } private void StartingWorkToolStripMenuItem_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 mailToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); + var service = DependencyManager.Instance.Resolve(); if (service is FormViewMail form) { form.ShowDialog(); } } + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 20019a3..c8e5b39 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -9,28 +9,22 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using FishFactoryBusinessLogic.MailWorker; using FishFactoryContracts.BindingModels; +using FishFactoryContracts.DI; namespace FishFactoryView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin =System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -44,51 +38,49 @@ namespace FishFactoryView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Ошибка работы с почтой"); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { + private static void InitDependency() + { + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => + { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file