diff --git a/.gitignore b/.gitignore index 9422752..06e5834 100644 --- a/.gitignore +++ b/.gitignore @@ -398,6 +398,7 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/Typography/ImplementationExtensions # ---> Java # Compiled class file *.class diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..acf9ed4 --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,94 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.StoragesContracts; +using TypographyDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace TypographyBusinessLogic.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/Typography/TypographyContracts/Attributes/ColumnAttribute.cs b/Typography/TypographyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..d3dee9e --- /dev/null +++ b/Typography/TypographyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace TypographyContracts.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/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs b/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..f82c727 --- /dev/null +++ b/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace TypographyContracts.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/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs b/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..5e6b703 --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace TypographyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs index 52bab9e..0571b81 100644 --- a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,6 @@ namespace TypographyContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id { get; set; } + } } diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..231da6b --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using TypographyContracts.BindingModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/DependencyManager.cs b/Typography/TypographyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..eaa8f9f --- /dev/null +++ b/Typography/TypographyContracts/DI/DependencyManager.cs @@ -0,0 +1,51 @@ +using Microsoft.Extensions.Logging; + +namespace TypographyContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new UnityDependencyContainer(); + } + + 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/Typography/TypographyContracts/DI/IDependencyContainer.cs b/Typography/TypographyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..2045c88 --- /dev/null +++ b/Typography/TypographyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.Logging; + +namespace TypographyContracts.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/Typography/TypographyContracts/DI/IImplementationExtension.cs b/Typography/TypographyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..9e26239 --- /dev/null +++ b/Typography/TypographyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,9 @@ +namespace TypographyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs b/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..e2ff45a --- /dev/null +++ b/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace TypographyContracts.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/Typography/TypographyContracts/DI/ServiceProviderLoader.cs b/Typography/TypographyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..d758a5f --- /dev/null +++ b/Typography/TypographyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace TypographyContracts.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"; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/UnityDependencyContainer.cs b/Typography/TypographyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..a43085d --- /dev/null +++ b/Typography/TypographyContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace TypographyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _unityContainer; + + public UnityDependencyContainer() + { + _unityContainer = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + } + + public T Resolve() + { + return _unityContainer.Resolve(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/Properties/launchSettings.json b/Typography/TypographyContracts/Properties/launchSettings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/Typography/TypographyContracts/Properties/launchSettings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs b/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..4b29eb0 --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace TypographyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/TypographyContracts.csproj b/Typography/TypographyContracts/TypographyContracts.csproj index 30c2576..70e95ff 100644 --- a/Typography/TypographyContracts/TypographyContracts.csproj +++ b/Typography/TypographyContracts/TypographyContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs index e239de1..f721d00 100644 --- a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs @@ -1,24 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs index 5e43a62..357d478 100644 --- a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -1,21 +1,17 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } + [Column(title: "Цена", width: 100)] + public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs index ba792fb..95bf0b7 100644 --- a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs @@ -1,27 +1,23 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", width: 80)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(title: "Квалификация", width: 120)] + public int Qualification { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs index 39fd046..e24d6d0 100644 --- a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs @@ -1,30 +1,29 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { - public class MessageInfoViewModel : IMessageInfoModel + public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [Column(visible: false)] + public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [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: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; - } -} + [Column(visible: false)] + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs index 7463b45..1d85d3f 100644 --- a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Enums; using TypographyDataModels.Models; @@ -11,40 +6,43 @@ namespace TypographyContracts.ViewModels { public class OrderViewModel : IOrderModel { - - [DisplayName("Номер")] + [Column(title: "Номер", width: 80)] public int Id { get; set; } - public int ClientId { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Клиент", width: 150)] + 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("Исполнитель")] - public string? ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Исполнитель", width: 150)] + public string? ImplementerFIO { get; set; } = string.Empty; - public int PrintedId { get; set; } + [Column(visible: false)] + public int PrintedId { get; set; } - [DisplayName("Изделие")] - public string PrintedName { get; set; } = string.Empty; + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 100)] public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Статус", width: 150)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 120)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 120)] public DateTime? DateImplement { get; set; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs index d31efdc..2c40863 100644 --- a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -1,22 +1,20 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class PrintedViewModel : IPrintedModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название изделия")] - public string PrintedName { get; set; } = string.Empty; + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 100)] public double Price { get; set; } - public Dictionary PrintedComponents { get; set; } = new(); + + [Column(visible: false)] + public Dictionary PrintedComponents { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs index 83e91bd..9d0f3e0 100644 --- a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs +++ b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace TypographyDataModels.Models { - public interface IMessageInfoModel - { + public interface IMessageInfoModel : IId + { string MessageId { get; } int? ClientId { get; } diff --git a/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs b/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..aad27dd --- /dev/null +++ b/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyDatabaseImplement.Implements; + +namespace TypographyDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs b/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..04c8afe --- /dev/null +++ b/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using TypographyContracts.StoragesContracts; + +namespace TypographyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new TypographyDatabase(); + 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/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs index f2058cb..a1e48fe 100644 --- a/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs +++ b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs @@ -216,7 +216,7 @@ namespace TypographyDatabaseImplement.Migrations modelBuilder.Entity("TypographyDatabaseImplement.Models.MessageInfo", b => { b.HasOne("TypographyDatabaseImplement.Models.Client", "Client") - .WithMany() + .WithMany("ClientMessages") .HasForeignKey("ClientId"); b.Navigation("Client"); @@ -268,6 +268,8 @@ namespace TypographyDatabaseImplement.Migrations modelBuilder.Entity("TypographyDatabaseImplement.Models.Client", b => { + b.Navigation("ClientMessages"); + b.Navigation("ClientOrders"); }); diff --git a/Typography/TypographyDatabaseImplement/Models/Client.cs b/Typography/TypographyDatabaseImplement/Models/Client.cs index 2fc0571..25c4273 100644 --- a/Typography/TypographyDatabaseImplement/Models/Client.cs +++ b/Typography/TypographyDatabaseImplement/Models/Client.cs @@ -1,27 +1,28 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } - [Required] + [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")] @@ -31,7 +32,7 @@ namespace TypographyDatabaseImplement.Models public virtual List ClientMessages { get; set; } = new(); public static Client? Create(ClientBindingModel model) - { + { if (model == null) { return null; @@ -64,4 +65,4 @@ namespace TypographyDatabaseImplement.Models Password = Password }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Component.cs b/Typography/TypographyDatabaseImplement/Models/Component.cs index 0b0359d..a6069bc 100644 --- a/Typography/TypographyDatabaseImplement/Models/Component.cs +++ b/Typography/TypographyDatabaseImplement/Models/Component.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyDataModels.Models; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.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")] @@ -65,4 +65,4 @@ namespace TypographyDatabaseImplement.Models Cost = Cost }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Implementer.cs b/Typography/TypographyDatabaseImplement/Models/Implementer.cs index 739965e..ea766e6 100644 --- a/Typography/TypographyDatabaseImplement/Models/Implementer.cs +++ b/Typography/TypographyDatabaseImplement/Models/Implementer.cs @@ -1,71 +1,72 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Implementer : IImplementerModel - { - public int Id { get; set; } + [DataContract] + public class Implementer : IImplementerModel + { + [DataMember] + public int Id { get; set; } - [Required] - public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] + [Required] + public string ImplementerFIO { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + [Required] + public string Password { get; set; } = string.Empty; - [Required] - public int WorkExperience { get; set; } + [DataMember] + [Required] + public int WorkExperience { get; set; } - [Required] - public int Qualification { get; set; } + [DataMember] + [Required] + public int Qualification { get; set; } - [ForeignKey("ImplementerId")] - public virtual List ImplementerOrders { get; set; } = new(); + [ForeignKey("ImplementerId")] + public virtual List ImplementerOrders { get; set; } = new(); - public static Implementer? Create(ImplementerBindingModel model) - { - if (model == null) - { - return null; - } - return new Implementer() - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } - public void Update(ImplementerBindingModel model) - { - if (model == null) - { - return; - } - ImplementerFIO = model.ImplementerFIO; - Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; - } - - public ImplementerViewModel GetViewModel => new() - { - Id = Id, - ImplementerFIO = ImplementerFIO, - Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification - }; - } -} + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs index a3ffa8f..4e474d9 100644 --- a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs +++ b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs @@ -2,56 +2,68 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using System.ComponentModel.DataAnnotations.Schema; namespace TypographyDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel - { - [Key] - public string MessageId { get; private set; } = string.Empty; + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + [Key] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public virtual Client? Client { get; private set; } + public virtual Client? Client { get; private set; } - [Required] - public string SenderName { get; private set; } = string.Empty; + [DataMember] + [Required] + public string SenderName { get; private set; } = string.Empty; - [Required] - public DateTime DateDelivery { get; private set; } + [DataMember] + [Required] + public DateTime DateDelivery { get; private set; } - [Required] - public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Subject { get; private set; } = string.Empty; - [Required] - public string Body { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Body { get; private set; } = string.Empty; - public static MessageInfo? Create(MessageInfoBindingModel? model) - { - if (model == null) - { - return null; - } - return new MessageInfo() - { - MessageId = model.MessageId, - ClientId = model.ClientId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - Subject = model.Subject, - Body = model.Body - }; - } + [NotMapped] + public int Id { get; private set; } + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } - public MessageInfoViewModel GetViewModel => new() - { - MessageId = MessageId, - ClientId = ClientId, - SenderName = SenderName, - DateDelivery = DateDelivery, - Subject = Subject, - Body = Body - }; - } -} + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Order.cs b/Typography/TypographyDatabaseImplement/Models/Order.cs index 5c1ef5d..651081d 100644 --- a/Typography/TypographyDatabaseImplement/Models/Order.cs +++ b/Typography/TypographyDatabaseImplement/Models/Order.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Enums; @@ -11,37 +7,47 @@ using TypographyDataModels.Models; namespace TypographyDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - [Required] - public int ClientId { get; private set; } + [DataMember] + [Required] + public int ClientId { get; private set; } - public virtual Client Client { get; set; } = new(); + public virtual Client Client { get; set; } = new(); - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } - public virtual Implementer? Implementer { get; set; } = new(); + public virtual Implementer? Implementer { get; set; } = new(); - [Required] + [DataMember] + [Required] public int PrintedId { get; private set; } public virtual Printed Printed { get; set; } = new(); - [Required] + [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; } + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model, TypographyDatabase context) { @@ -52,11 +58,11 @@ namespace TypographyDatabaseImplement.Models return new Order() { Id = model.Id, - ClientId = model.ClientId, - Client = context.Clients.First(x => model.ClientId == x.Id), - ImplementerId = model.ImplementerId, - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null, - PrintedId = model.PrintedId, + ClientId = model.ClientId, + Client = context.Clients.First(x => model.ClientId == x.Id), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null, + PrintedId = model.PrintedId, Printed = context.Printeds.First(x => model.PrintedId == x.Id), Count = model.Count, Sum = model.Sum, @@ -72,21 +78,21 @@ namespace TypographyDatabaseImplement.Models { return; } - ImplementerId = model.ImplementerId; - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null; - Status = model.Status; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null; + Status = model.Status; DateImplement = model.DateImplement; - } + } public OrderViewModel GetViewModel => new() { Id = Id, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - ClientEmail = Client.Email, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, + ClientEmail = Client.Email, ImplementerId = ImplementerId, - ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, - PrintedId = PrintedId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, + PrintedId = PrintedId, PrintedName = Printed.PrintedName, Count = Count, Sum = Sum, @@ -95,4 +101,4 @@ namespace TypographyDatabaseImplement.Models DateImplement = DateImplement }; } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Printed.cs b/Typography/TypographyDatabaseImplement/Models/Printed.cs index 63d1a17..9bedcd5 100644 --- a/Typography/TypographyDatabaseImplement/Models/Printed.cs +++ b/Typography/TypographyDatabaseImplement/Models/Printed.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } - [Required] + [DataMember] + [Required] public string PrintedName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _printedComponents = null; @@ -76,7 +76,7 @@ namespace TypographyDatabaseImplement.Models { var printedComponents = context.PrintedComponents.Where(rec => rec.PrintedId == model.Id).ToList(); if (printedComponents != null && printedComponents.Count > 0) - { + { context.PrintedComponents.RemoveRange(printedComponents.Where(rec => !model.PrintedComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); @@ -101,4 +101,4 @@ namespace TypographyDatabaseImplement.Models _printedComponents = null; } } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs index 3230de1..a4b9982 100644 --- a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs +++ b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class PrintedComponent + public class PrintedComponent { public int Id { get; set; } @@ -24,4 +20,4 @@ namespace TypographyDatabaseImplement.Models public virtual Printed Printed { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj b/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj index 1ce9597..f3ebf98 100644 --- a/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj +++ b/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Typography/TypographyFileImplement/FileImplementationExtension.cs b/Typography/TypographyFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..5847dcb --- /dev/null +++ b/Typography/TypographyFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyFileImplement.Implements; + +namespace TypographyFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Implements/BackUpInfo.cs b/Typography/TypographyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..aa8e209 --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using TypographyContracts.StoragesContracts; + +namespace TypographyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProps; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProps = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + return (List?)sourceProps + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))? + .GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Client.cs b/Typography/TypographyFileImplement/Models/Client.cs index 6fb9b7e..40f6ecb 100644 --- a/Typography/TypographyFileImplement/Models/Client.cs +++ b/Typography/TypographyFileImplement/Models/Client.cs @@ -1,76 +1,79 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } - public static Client? Create(ClientBindingModel model) - { - if (model == null) - { - return null; - } - return new Client() - { - Id = model.Id, - ClientFIO = model.ClientFIO, - Email = model.Email, - Password = model.Password - }; - } + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; - public static Client? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Client() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ClientFIO = element.Element("ClientFIO")!.Value, - Email = element.Element("Email")!.Value, - Password = element.Element("Password")!.Value - }; - } + [DataMember] + public string Email { get; private set; } = string.Empty; - public void Update(ClientBindingModel model) - { - if (model == null) - { - return; - } - ClientFIO = model.ClientFIO; - Email = model.Email; - Password = model.Password; - } + [DataMember] + public string Password { get; private set; } = string.Empty; - public ClientViewModel GetViewModel => new() - { - Id = Id, - ClientFIO = ClientFIO, - Email = Email, - Password = Password - }; + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } - public XElement GetXElement => new("Client", - new XAttribute("Id", Id), - new XElement("ClientFIO", ClientFIO), - new XElement("Email", Email), - new XElement("Password", Password)); - } -} + public static Client? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Client() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ClientFIO = element.Element("ClientFIO")!.Value, + Email = element.Element("Email")!.Value, + Password = element.Element("Password")!.Value + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("ClientFIO", ClientFIO), + new XElement("Email", Email), + new XElement("Password", Password)); + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Component.cs b/Typography/TypographyFileImplement/Models/Component.cs index d07ae16..76edde8 100644 --- a/Typography/TypographyFileImplement/Models/Component.cs +++ b/Typography/TypographyFileImplement/Models/Component.cs @@ -2,14 +2,21 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { @@ -61,5 +68,4 @@ namespace TypographyFileImplement.Models new XElement("ComponentName", ComponentName), new XElement("Cost", Cost.ToString())); } - -} +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Implementer.cs b/Typography/TypographyFileImplement/Models/Implementer.cs index 693358c..89575f3 100644 --- a/Typography/TypographyFileImplement/Models/Implementer.cs +++ b/Typography/TypographyFileImplement/Models/Implementer.cs @@ -3,19 +3,26 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; using System.Reflection; +using System.Runtime.Serialization; namespace TypographyFileImplement.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(ImplementerBindingModel model) diff --git a/Typography/TypographyFileImplement/Models/MessageInfo.cs b/Typography/TypographyFileImplement/Models/MessageInfo.cs index 02c1b24..42272e3 100644 --- a/Typography/TypographyFileImplement/Models/MessageInfo.cs +++ b/Typography/TypographyFileImplement/Models/MessageInfo.cs @@ -2,23 +2,33 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.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; } + [DataMember] public string Subject { get; private set; } = string.Empty; + [DataMember] public string Body { get; private set; } = string.Empty; + public int Id { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Order.cs b/Typography/TypographyFileImplement/Models/Order.cs index 8399283..7b10d56 100644 --- a/Typography/TypographyFileImplement/Models/Order.cs +++ b/Typography/TypographyFileImplement/Models/Order.cs @@ -1,28 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; using System.Xml.Linq; using TypographyDataModels.Enums; -using TypographyDataModels.Models; -using TypographyContracts.BindingModels; -using TypographyContracts.ViewModels; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - + [DataMember] public int Id { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } - public int PrintedId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + + [DataMember] + public int ClientId { get; private set; } + + [DataMember] + public int? ImplementerId { get; private set; } + + [DataMember] + public int PrintedId { get; private set; } + + [DataMember] + public int Count { get; private set; } + + [DataMember] + public double Sum { get; private set; } + + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) { @@ -33,9 +46,9 @@ namespace TypographyFileImplement.Models return new Order() { Id = model.Id, - ClientId = model.ClientId, - ImplementerId = model.ImplementerId, - PrintedId = model.PrintedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + PrintedId = model.PrintedId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,9 +66,9 @@ namespace TypographyFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), - PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -71,17 +84,17 @@ namespace TypographyFileImplement.Models { return; } - ImplementerId = model.ImplementerId; - Status = model.Status; + ImplementerId = model.ImplementerId; + Status = model.Status; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, - ClientId = ClientId, - ImplementerId = ImplementerId, - PrintedId = PrintedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + PrintedId = PrintedId, Count = Count, Sum = Sum, Status = Status, @@ -91,14 +104,13 @@ namespace TypographyFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XElement("ClientId", ClientId), - new XElement("ImplementerId", ImplementerId), - new XElement("PrintedId", PrintedId), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), + new XElement("PrintedId", PrintedId), new XElement("Count", Count), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); } -} - +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Printed.cs b/Typography/TypographyFileImplement/Models/Printed.cs index 7a5ff47..51db7f7 100644 --- a/Typography/TypographyFileImplement/Models/Printed.cs +++ b/Typography/TypographyFileImplement/Models/Printed.cs @@ -1,20 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; private set; } - public string PrintedName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string PrintedName { get; private set; } = string.Empty; + + [DataMember] + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); private Dictionary? _productComponents = null; @@ -26,12 +29,13 @@ namespace TypographyFileImplement.Models if (_productComponents == null) { var source = DataFileSingleton.GetInstance(); - _productComponents = Components.ToDictionary(x => x.Key, y => - ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + _productComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,y.Value)); } return _productComponents; } } + public static Printed? Create(PrintedBindingModel model) { if (model == null) @@ -46,6 +50,7 @@ namespace TypographyFileImplement.Models Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2) }; } + public static Printed? Create(XElement element) { if (element == null) @@ -58,10 +63,11 @@ namespace TypographyFileImplement.Models PrintedName = element.Element("ProductName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), Components = element.Element("ProductComponents")!.Elements("ProductComponent").ToDictionary(x => - Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; } + public void Update(PrintedBindingModel model) { if (model == null) @@ -70,9 +76,10 @@ namespace TypographyFileImplement.Models } PrintedName = model.PrintedName; Price = model.Price; - Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + Components = model.PrintedComponents.ToDictionary(x => x.Key, x =>x.Value.Item2); _productComponents = null; } + public PrintedViewModel GetViewModel => new() { Id = Id, @@ -80,6 +87,7 @@ namespace TypographyFileImplement.Models Price = Price, PrintedComponents = PrintedComponents }; + public XElement GetXElement => new("Product", new XAttribute("Id", Id), new XElement("ProductName", PrintedName), @@ -90,4 +98,4 @@ namespace TypographyFileImplement.Models new XElement("Value", x.Value))) .ToArray())); } -} +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/TypographyFileImplement.csproj b/Typography/TypographyFileImplement/TypographyFileImplement.csproj index 96adc37..cfb0043 100644 --- a/Typography/TypographyFileImplement/TypographyFileImplement.csproj +++ b/Typography/TypographyFileImplement/TypographyFileImplement.csproj @@ -13,5 +13,8 @@ - + + + + diff --git a/Typography/TypographyListImplement/Implements/BackUpInfo.cs b/Typography/TypographyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f8b4d9f --- /dev/null +++ b/Typography/TypographyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using TypographyContracts.StoragesContracts; + +namespace TypographyListImplement.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/Typography/TypographyListImplement/ListImplementationExtension.cs b/Typography/TypographyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..4bda5aa --- /dev/null +++ b/Typography/TypographyListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyListImplement.Implements; + +namespace TypographyListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Models/MessageInfo .cs b/Typography/TypographyListImplement/Models/MessageInfo .cs deleted file mode 100644 index af0d76c..0000000 --- a/Typography/TypographyListImplement/Models/MessageInfo .cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; -using TypographyContracts.ViewModels; -using TypographyDataModels.Models; - -namespace TypographyListImplement.Models -{ - public class MessageInfo : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; - - public static MessageInfo? Create(MessageInfoBindingModel? model) - { - if (model == null) - { - return null; - } - return new MessageInfo() - { - MessageId = model.MessageId, - ClientId = model.ClientId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - Subject = model.Subject, - Body = model.Body - }; - } - - public MessageInfoViewModel GetViewModel => new() - { - MessageId = MessageId, - ClientId = ClientId, - SenderName = SenderName, - DateDelivery = DateDelivery, - Subject = Subject, - Body = Body - }; - } -} diff --git a/Typography/TypographyListImplement/Models/MessageInfo.cs b/Typography/TypographyListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..46b57e3 --- /dev/null +++ b/Typography/TypographyListImplement/Models/MessageInfo.cs @@ -0,0 +1,50 @@ +using TypographyDataModels.Models; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; + +namespace TypographyListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public int Id { get; private set; } + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/TypographyListImplement.csproj b/Typography/TypographyListImplement/TypographyListImplement.csproj index db73c6b..e6874e0 100644 --- a/Typography/TypographyListImplement/TypographyListImplement.csproj +++ b/Typography/TypographyListImplement/TypographyListImplement.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/Typography/TypographyView/DataGridViewExtension.cs b/Typography/TypographyView/DataGridViewExtension.cs new file mode 100644 index 0000000..f7cc8d1 --- /dev/null +++ b/Typography/TypographyView/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using TypographyContracts.Attributes; + +namespace TypographyView +{ + 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/Typography/TypographyView/FormClients.cs b/Typography/TypographyView/FormClients.cs index d5019d9..a20a2ef 100644 --- a/Typography/TypographyView/FormClients.cs +++ b/Typography/TypographyView/FormClients.cs @@ -1,6 +1,7 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace TypographyView { @@ -25,13 +26,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewClients.DataSource = list; - dataGridViewClients.Columns["Id"].Visible = false; - dataGridViewClients.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewClients.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/Typography/TypographyView/FormComponents.cs b/Typography/TypographyView/FormComponents.cs index 85d0784..c035e5f 100644 --- a/Typography/TypographyView/FormComponents.cs +++ b/Typography/TypographyView/FormComponents.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -23,16 +25,10 @@ namespace TypographyView private void LoadData() { - try + try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewComponents.DataSource = list; - dataGridViewComponents.Columns["Id"].Visible = false; - dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridViewComponents.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { @@ -43,13 +39,10 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -57,14 +50,11 @@ namespace TypographyView { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/FormImplementers.cs b/Typography/TypographyView/FormImplementers.cs index a159582..03f11c6 100644 --- a/Typography/TypographyView/FormImplementers.cs +++ b/Typography/TypographyView/FormImplementers.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -25,13 +27,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewImplementers.DataSource = list; - dataGridViewImplementers.Columns["Id"].Visible = false; - dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewImplementers.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -43,13 +39,10 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -57,14 +50,11 @@ namespace TypographyView { if (dataGridViewImplementers.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/FormMain.Designer.cs b/Typography/TypographyView/FormMain.Designer.cs index c756755..4d2efd6 100644 --- a/Typography/TypographyView/FormMain.Designer.cs +++ b/Typography/TypographyView/FormMain.Designer.cs @@ -44,6 +44,7 @@ ordersListToolStripMenuItem = new ToolStripMenuItem(); workLaunchToolStripMenuItem = new ToolStripMenuItem(); messagesToolStripMenuItem = new ToolStripMenuItem(); + createBackUpToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -94,7 +95,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem, createBackUpToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1482, 28); @@ -178,6 +179,13 @@ messagesToolStripMenuItem.Text = "Письма"; messagesToolStripMenuItem.Click += MessagesToolStripMenuItem_Click; // + // createBackUpToolStripMenuItem + // + createBackUpToolStripMenuItem.Name = "createBackUpToolStripMenuItem"; + createBackUpToolStripMenuItem.Size = new Size(123, 24); + createBackUpToolStripMenuItem.Text = "Создать бекап"; + createBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -218,5 +226,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem workLaunchToolStripMenuItem; private ToolStripMenuItem messagesToolStripMenuItem; + private ToolStripMenuItem createBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.cs b/Typography/TypographyView/FormMain.cs index 1e5d7df..d3aa5f1 100644 --- a/Typography/TypographyView/FormMain.cs +++ b/Typography/TypographyView/FormMain.cs @@ -1,6 +1,9 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.DI; namespace TypographyView { @@ -10,14 +13,17 @@ namespace TypographyView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, + IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -29,16 +35,7 @@ namespace TypographyView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridViewOrders.DataSource = list; - dataGridViewOrders.Columns["ClientId"].Visible = false; - dataGridViewOrders.Columns["ClientEmail"].Visible = false; - dataGridViewOrders.Columns["ImplementerId"].Visible = false; - dataGridViewOrders.Columns["PrintedId"].Visible = false; - dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewOrders.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -50,38 +47,26 @@ namespace TypographyView private void ComponentsToolStripMenuItem_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 PrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); - if (service is FormPrinteds form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ImplementersToolStripMenuItem_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 PrintedsListToolStripMenuItem_Click(object sender, EventArgs e) @@ -96,45 +81,58 @@ namespace TypographyView private void ComponentPrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPrintedComponents)); - if (service is FormReportPrintedComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersListToolStripMenuItem_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 WorkLaunchToolStripMenuItem_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 MessagesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMessages)); - if (service is FormMessages 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); } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void ButtonIssuedOrder_Click(object sender, EventArgs e) diff --git a/Typography/TypographyView/FormMessages.cs b/Typography/TypographyView/FormMessages.cs index fe66a35..46d91ff 100644 --- a/Typography/TypographyView/FormMessages.cs +++ b/Typography/TypographyView/FormMessages.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; +using System.Windows.Forms; using TypographyContracts.BusinessLogicsContracts; namespace TypographyView @@ -25,14 +26,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewMessages.DataSource = list; - dataGridViewMessages.Columns["MessageId"].Visible = false; - dataGridViewMessages.Columns["ClientId"].Visible = false; - dataGridViewMessages.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewMessages.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка входящих писем"); } catch (Exception ex) diff --git a/Typography/TypographyView/FormPrinted.cs b/Typography/TypographyView/FormPrinted.cs index ddb1c5d..ea9cf0e 100644 --- a/Typography/TypographyView/FormPrinted.cs +++ b/Typography/TypographyView/FormPrinted.cs @@ -3,6 +3,7 @@ using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.SearchModels; using TypographyDataModels.Models; using Microsoft.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -14,6 +15,7 @@ namespace TypographyView private Dictionary _printedComponents; public int Id { set { _id = value; } } + public FormPrinted(ILogger logger, IPrintedLogic logic) { InitializeComponent(); @@ -81,27 +83,24 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", - form.ComponentModel.ComponentName, form.Count); - if (_printedComponents.ContainsKey(form.Id)) - { - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + if (_printedComponents.ContainsKey(form.Id)) + { + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } @@ -109,23 +108,20 @@ namespace TypographyView { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _printedComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", - form.ComponentModel.ComponentName, form.Count); - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/Typography/TypographyView/FormPrinteds.cs b/Typography/TypographyView/FormPrinteds.cs index 50fead6..be674ed 100644 --- a/Typography/TypographyView/FormPrinteds.cs +++ b/Typography/TypographyView/FormPrinteds.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -23,17 +25,10 @@ namespace TypographyView private void LoadData() { - try + try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewPrinteds.DataSource = list; - dataGridViewPrinteds.Columns["Id"].Visible = false; - dataGridViewPrinteds.Columns["PrintedComponents"].Visible = false; - dataGridViewPrinteds.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка печатной продукции"); + dataGridViewPrinteds.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка печатной продукции"); } catch (Exception ex) { @@ -44,13 +39,10 @@ namespace TypographyView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -58,14 +50,11 @@ namespace TypographyView { if (dataGridViewPrinteds.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/TypographyView/Program.cs b/Typography/TypographyView/Program.cs index 2e799a9..b7e26e0 100644 --- a/Typography/TypographyView/Program.cs +++ b/Typography/TypographyView/Program.cs @@ -1,22 +1,17 @@ using TypographyBusinessLogic.BusinessLogics; using TypographyContracts.BusinessLogicsContracts; -using TypographyContracts.StoragesContracts; -using TypographyDatabaseImplement.Implements; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; using TypographyBusinessLogic.OfficePackage.Implements; using TypographyBusinessLogic.OfficePackage; using TypographyBusinessLogic.MailWorker; using TypographyContracts.BindingModels; +using TypographyContracts.DI; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace TypographyView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// /// The main entry point for the application. /// @@ -26,13 +21,11 @@ namespace TypographyView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,57 +40,54 @@ namespace TypographyView } 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 => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + private static void InitDependency() + { + DependencyManager.InitDependency(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + 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) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file