From 9ef3c65cbcc48e5e99d884204b1743a16f437e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Fri, 17 May 2024 16:30:55 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=BE=20=D1=80=D0=B5?= =?UTF-8?q?=D1=88=D0=B8=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D1=83=20=D1=81=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8,=20=D0=B0=20=D1=82=D0=B0=D0=BA=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/BackUpLogic.cs | 95 ++++++++ .../Attributes/ColumnAttribute.cs | 26 ++ .../Attributes/GridViewAutoSize.cs | 20 ++ .../BindingModels/BackUpSaveBinidngModel.cs | 13 + .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 14 ++ TypographyContracts/DI/DependencyManager.cs | 68 ++++++ .../DI/IDependencyContainer.cs | 43 ++++ .../DI/IImplementationExtension.cs | 20 ++ .../DI/ServiceDependencyContainer.cs | 62 +++++ .../DI/ServiceProviderLoader.cs | 58 +++++ .../DI/UnityDependencyContainer.cs | 38 +++ .../StoragesContracts/IBackUpInfo.cs | 14 ++ .../TypographyContracts.csproj | 6 + .../ViewModels/ClientViewModel.cs | 8 +- .../ViewModels/ComponentViewModel.cs | 6 +- .../ViewModels/ImplementerViewModel.cs | 10 +- .../ViewModels/MessageInfoViewModel.cs | 18 +- .../ViewModels/OrderViewModel.cs | 23 +- .../ViewModels/PrintedViewModel.cs | 7 +- .../Models/IMessageInfoModel.cs | 2 +- .../FileImplementationExtension.cs | 22 ++ .../Implements/BackUpInfo.cs | 33 +++ .../Implements/MessageInfoStorage.cs | 11 +- TypographyFileImplement/Models/Client.cs | 11 +- TypographyFileImplement/Models/Component.cs | 5 + TypographyFileImplement/Models/Implementer.cs | 11 +- TypographyFileImplement/Models/MessageInfo.cs | 14 +- TypographyFileImplement/Models/Order.cs | 12 + TypographyFileImplement/Models/Printed.cs | 18 +- .../Implements/BackUpInfo.cs | 22 ++ .../ListImplementationExtension.cs | 27 ++ TypographyListImplement/Models/MessageInfo.cs | 2 + .../DatabaseImplementationExtension.cs | 27 ++ .../Implements/BackUpInfo.cs | 32 +++ .../Models/Client.cs | 6 + .../Models/Component.cs | 5 + .../Models/Implementer.cs | 11 +- .../Models/MessageInfo.cs | 14 +- .../Models/Order.cs | 12 +- .../Models/Printed.cs | 6 + TypographyView/DataGridViewExtension.cs | 52 ++++ TypographyView/FormClients.cs | 8 +- TypographyView/FormComponents.cs | 42 +--- TypographyView/FormImplementers.cs | 38 +-- TypographyView/FormMails.cs | 9 +- TypographyView/FormMain.Designer.cs | 43 ++-- TypographyView/FormMain.cs | 230 ++++++++---------- TypographyView/FormPrinted.cs | 55 ++--- TypographyView/FormPrinteds.cs | 45 +--- TypographyView/Program.cs | 84 +++---- 51 files changed, 1068 insertions(+), 391 deletions(-) create mode 100644 TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 TypographyContracts/Attributes/ColumnAttribute.cs create mode 100644 TypographyContracts/Attributes/GridViewAutoSize.cs create mode 100644 TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 TypographyContracts/DI/DependencyManager.cs create mode 100644 TypographyContracts/DI/IDependencyContainer.cs create mode 100644 TypographyContracts/DI/IImplementationExtension.cs create mode 100644 TypographyContracts/DI/ServiceDependencyContainer.cs create mode 100644 TypographyContracts/DI/ServiceProviderLoader.cs create mode 100644 TypographyContracts/DI/UnityDependencyContainer.cs create mode 100644 TypographyContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 TypographyFileImplement/FileImplementationExtension.cs create mode 100644 TypographyFileImplement/Implements/BackUpInfo.cs create mode 100644 TypographyListImplement/Implements/BackUpInfo.cs create mode 100644 TypographyListImplement/ListImplementationExtension.cs create mode 100644 TypographyShopDatabaseImplements/DatabaseImplementationExtension.cs create mode 100644 TypographyShopDatabaseImplements/Implements/BackUpInfo.cs create mode 100644 TypographyView/DataGridViewExtension.cs diff --git a/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs b/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..b647ff6 --- /dev/null +++ b/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,95 @@ +using Microsoft.Extensions.Logging; +using System.Reflection; +using System.Runtime.Serialization.Json; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.StoragesContracts; +using TypographyDataModels; +using System.IO.Compression; + +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); + } + } +} diff --git a/TypographyContracts/Attributes/ColumnAttribute.cs b/TypographyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..f72bd2d --- /dev/null +++ b/TypographyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + 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; + } + 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; } + } +} diff --git a/TypographyContracts/Attributes/GridViewAutoSize.cs b/TypographyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..726716d --- /dev/null +++ b/TypographyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs b/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..1b617a9 --- /dev/null +++ b/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/TypographyContracts/BindingModels/MessageInfoBindingModel.cs b/TypographyContracts/BindingModels/MessageInfoBindingModel.cs index f909b6c..59c841d 100644 --- a/TypographyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/TypographyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace TypographyContracts.BindingModels public DateTime DateDelivery { get; set; } public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + public int Id => throw new NotImplementedException(); } } diff --git a/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..cb8817f --- /dev/null +++ b/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/TypographyContracts/DI/DependencyManager.cs b/TypographyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..bbc5b5f --- /dev/null +++ b/TypographyContracts/DI/DependencyManager.cs @@ -0,0 +1,68 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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(); + } +} diff --git a/TypographyContracts/DI/IDependencyContainer.cs b/TypographyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..9d399c5 --- /dev/null +++ b/TypographyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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(); + } +} diff --git a/TypographyContracts/DI/IImplementationExtension.cs b/TypographyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..634871d --- /dev/null +++ b/TypographyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.DI +{ + /// + /// Интерфейс для регистрации зависимостей в модулях + /// + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/TypographyContracts/DI/ServiceDependencyContainer.cs b/TypographyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..c7ec320 --- /dev/null +++ b/TypographyContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 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()!; + } + } +} diff --git a/TypographyContracts/DI/ServiceProviderLoader.cs b/TypographyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..bc572ac --- /dev/null +++ b/TypographyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.DI +{ + /// + /// Загрузчик данных + /// + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/TypographyContracts/DI/UnityDependencyContainer.cs b/TypographyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..568acb4 --- /dev/null +++ b/TypographyContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace TypographyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/TypographyContracts/StoragesContracts/IBackUpInfo.cs b/TypographyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..0368615 --- /dev/null +++ b/TypographyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/TypographyContracts/TypographyContracts.csproj b/TypographyContracts/TypographyContracts.csproj index 30c2576..70e95ff 100644 --- a/TypographyContracts/TypographyContracts.csproj +++ b/TypographyContracts/TypographyContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/TypographyContracts/ViewModels/ClientViewModel.cs b/TypographyContracts/ViewModels/ClientViewModel.cs index 61918a6..efe7294 100644 --- a/TypographyContracts/ViewModels/ClientViewModel.cs +++ b/TypographyContracts/ViewModels/ClientViewModel.cs @@ -4,18 +4,20 @@ 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 { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "ФИО клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (Email)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/TypographyContracts/ViewModels/ComponentViewModel.cs b/TypographyContracts/ViewModels/ComponentViewModel.cs index 40a6a67..80d619d 100644 --- a/TypographyContracts/ViewModels/ComponentViewModel.cs +++ b/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -5,15 +5,17 @@ using System.Text; using System.Threading.Tasks; using TypographyDataModels.Models; using System.ComponentModel; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Cost { get; set; } } } diff --git a/TypographyContracts/ViewModels/ImplementerViewModel.cs b/TypographyContracts/ViewModels/ImplementerViewModel.cs index 737f44e..f1b62e6 100644 --- a/TypographyContracts/ViewModels/ImplementerViewModel.cs +++ b/TypographyContracts/ViewModels/ImplementerViewModel.cs @@ -4,24 +4,26 @@ 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 { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФМО")] + [Column("ФИО", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", width: 150)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", width: 150)] public int Qualification { get; set; } } } diff --git a/TypographyContracts/ViewModels/MessageInfoViewModel.cs b/TypographyContracts/ViewModels/MessageInfoViewModel.cs index 72d2b58..2ece99a 100644 --- a/TypographyContracts/ViewModels/MessageInfoViewModel.cs +++ b/TypographyContracts/ViewModels/MessageInfoViewModel.cs @@ -4,26 +4,26 @@ 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 { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - - [DisplayName("Отправитель")] + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - - [DisplayName("Дата отправки")] + [Column("Дата отправки", width: 100)] public DateTime DateDelivery { get; set; } - - [DisplayName("Предмет")] + [Column("Subject", width: 150)] public string Subject { get; set; } = string.Empty; - - [DisplayName("Тело")] + [Column("Тело", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/TypographyContracts/ViewModels/OrderViewModel.cs b/TypographyContracts/ViewModels/OrderViewModel.cs index 7649073..ebca86f 100644 --- a/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/TypographyContracts/ViewModels/OrderViewModel.cs @@ -6,32 +6,37 @@ using System.Threading.Tasks; using TypographyDataModels.Enums; using TypographyDataModels.Models; using System.ComponentModel; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + + [Column(visible: false)] public int PrintedId { get; set; } - [DisplayName("Изделие")] + [Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string PrintedName { get; set; } = string.Empty; + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("ФИО Клиента")] + [Column("ФИО Клиента", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("ФИО работника")] + [Column("ФИО работника", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } } diff --git a/TypographyContracts/ViewModels/PrintedViewModel.cs b/TypographyContracts/ViewModels/PrintedViewModel.cs index 90bd2f7..3c40c73 100644 --- a/TypographyContracts/ViewModels/PrintedViewModel.cs +++ b/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -5,16 +5,19 @@ using System.Text; using System.Threading.Tasks; using TypographyDataModels.Models; using System.ComponentModel; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class PrintedViewModel : IPrintedModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PrintedName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] public Dictionary PrintedComponents { get; set; } = new(); } diff --git a/TypographyDataModels/Models/IMessageInfoModel.cs b/TypographyDataModels/Models/IMessageInfoModel.cs index 6d319eb..d814e63 100644 --- a/TypographyDataModels/Models/IMessageInfoModel.cs +++ b/TypographyDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace TypographyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/TypographyFileImplement/FileImplementationExtension.cs b/TypographyFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..331e6a5 --- /dev/null +++ b/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(); + } + } +} diff --git a/TypographyFileImplement/Implements/BackUpInfo.cs b/TypographyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..8d88da9 --- /dev/null +++ b/TypographyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.StoragesContracts; + +namespace TypographyFileImplement.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/TypographyFileImplement/Implements/MessageInfoStorage.cs b/TypographyFileImplement/Implements/MessageInfoStorage.cs index cbac29a..4dadcbd 100644 --- a/TypographyFileImplement/Implements/MessageInfoStorage.cs +++ b/TypographyFileImplement/Implements/MessageInfoStorage.cs @@ -1,16 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; using TypographyContracts.ViewModels; using TypographyFileImplement.Models; namespace TypographyFileImplement.Implements { - public class MessageInfoStorage + public class MessageInfoStorage : IMessageInfoStorage { private readonly DataFileSingleton _source; public MessageInfoStorage() @@ -55,4 +51,3 @@ namespace TypographyFileImplement.Implements } } } - diff --git a/TypographyFileImplement/Models/Client.cs b/TypographyFileImplement/Models/Client.cs index 96ebcec..501c020 100644 --- a/TypographyFileImplement/Models/Client.cs +++ b/TypographyFileImplement/Models/Client.cs @@ -1,18 +1,21 @@ -using System.Xml.Linq; +using System.Runtime.Serialization; +using System.Xml.Linq; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; namespace TypographyFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ClientFIO { get; private set; } = string.Empty; - + [DataMember] public string Email { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) diff --git a/TypographyFileImplement/Models/Component.cs b/TypographyFileImplement/Models/Component.cs index bfc5292..fe0e3f1 100644 --- a/TypographyFileImplement/Models/Component.cs +++ b/TypographyFileImplement/Models/Component.cs @@ -7,13 +7,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { diff --git a/TypographyFileImplement/Models/Implementer.cs b/TypographyFileImplement/Models/Implementer.cs index f03e591..901dbb2 100644 --- a/TypographyFileImplement/Models/Implementer.cs +++ b/TypographyFileImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -10,16 +11,18 @@ using TypographyDataModels.Models; 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(XElement element) diff --git a/TypographyFileImplement/Models/MessageInfo.cs b/TypographyFileImplement/Models/MessageInfo.cs index fa79870..2b7cdb5 100644 --- a/TypographyFileImplement/Models/MessageInfo.cs +++ b/TypographyFileImplement/Models/MessageInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -10,18 +11,20 @@ using TypographyDataModels.Models; 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; } = 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 TypographyFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + public int Id => throw new NotImplementedException(); } } diff --git a/TypographyFileImplement/Models/Order.cs b/TypographyFileImplement/Models/Order.cs index ff43ad8..e734fbe 100644 --- a/TypographyFileImplement/Models/Order.cs +++ b/TypographyFileImplement/Models/Order.cs @@ -8,20 +8,32 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int PrintedId { get; private set; } + [DataMember] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; 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) { if (model == null) diff --git a/TypographyFileImplement/Models/Printed.cs b/TypographyFileImplement/Models/Printed.cs index 7ee8404..6ff5464 100644 --- a/TypographyFileImplement/Models/Printed.cs +++ b/TypographyFileImplement/Models/Printed.cs @@ -2,27 +2,35 @@ using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { + [DataContract] public class Printed : IPrintedModel { + [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? _srintedComponents = null; + + private Dictionary? _printedComponents = null; + [DataMember] public Dictionary PrintedComponents { get { - if (_srintedComponents == null) + if (_printedComponents == null) { var source = DataFileSingleton.GetInstance(); - _srintedComponents = Components.ToDictionary(x => x.Key, y => + _printedComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); } - return _srintedComponents; + return _printedComponents; } } public static Printed? Create(PrintedBindingModel model) @@ -63,7 +71,7 @@ namespace TypographyFileImplement.Models PrintedName = model.PrintedName; Price = model.Price; Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2); - _srintedComponents = null; + _printedComponents = null; } public PrintedViewModel GetViewModel => new() { diff --git a/TypographyListImplement/Implements/BackUpInfo.cs b/TypographyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..204a74a --- /dev/null +++ b/TypographyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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(); + } + } +} diff --git a/TypographyListImplement/ListImplementationExtension.cs b/TypographyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..0d76ad7 --- /dev/null +++ b/TypographyListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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(); + } + } +} diff --git a/TypographyListImplement/Models/MessageInfo.cs b/TypographyListImplement/Models/MessageInfo.cs index a0300c6..4ba406f 100644 --- a/TypographyListImplement/Models/MessageInfo.cs +++ b/TypographyListImplement/Models/MessageInfo.cs @@ -49,5 +49,7 @@ namespace TypographyListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/TypographyShopDatabaseImplements/DatabaseImplementationExtension.cs b/TypographyShopDatabaseImplements/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..75bea2e --- /dev/null +++ b/TypographyShopDatabaseImplements/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyDatabaseImplements.Implements; + +namespace TypographyDatabaseImplements +{ + 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/TypographyShopDatabaseImplements/Implements/BackUpInfo.cs b/TypographyShopDatabaseImplements/Implements/BackUpInfo.cs new file mode 100644 index 0000000..4768f98 --- /dev/null +++ b/TypographyShopDatabaseImplements/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.StoragesContracts; + +namespace TypographyDatabaseImplements.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/TypographyShopDatabaseImplements/Models/Client.cs b/TypographyShopDatabaseImplements/Models/Client.cs index 9515f8f..bf61f8d 100644 --- a/TypographyShopDatabaseImplements/Models/Client.cs +++ b/TypographyShopDatabaseImplements/Models/Client.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TypographyContracts.BindingModels; @@ -13,17 +14,22 @@ using TypographyDataModels.Models; namespace TypographyDatabaseImplements.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/TypographyShopDatabaseImplements/Models/Component.cs b/TypographyShopDatabaseImplements/Models/Component.cs index e3454c3..7818c8a 100644 --- a/TypographyShopDatabaseImplements/Models/Component.cs +++ b/TypographyShopDatabaseImplements/Models/Component.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDatabaseImplements.Models; @@ -7,12 +8,16 @@ using TypographyDataModels.Models; namespace TypographyDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List PrintedComponents { get; set; } = new(); diff --git a/TypographyShopDatabaseImplements/Models/Implementer.cs b/TypographyShopDatabaseImplements/Models/Implementer.cs index 6f2a03c..4007f4b 100644 --- a/TypographyShopDatabaseImplements/Models/Implementer.cs +++ b/TypographyShopDatabaseImplements/Models/Implementer.cs @@ -8,19 +8,22 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using TypographyDatabaseImplement.Models; +using System.Runtime.Serialization; namespace TypographyDatabaseImplements.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; } [ForeignKey("ImplementerId")] diff --git a/TypographyShopDatabaseImplements/Models/MessageInfo.cs b/TypographyShopDatabaseImplements/Models/MessageInfo.cs index c963287..7ef3d34 100644 --- a/TypographyShopDatabaseImplements/Models/MessageInfo.cs +++ b/TypographyShopDatabaseImplements/Models/MessageInfo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TypographyContracts.BindingModels; @@ -10,19 +11,21 @@ using TypographyDataModels.Models; namespace TypographyDatabaseImplements.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [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 virtual Client? Client { get; private set; } @@ -53,5 +56,6 @@ namespace TypographyDatabaseImplements.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + public int Id => throw new NotImplementedException(); } } diff --git a/TypographyShopDatabaseImplements/Models/Order.cs b/TypographyShopDatabaseImplements/Models/Order.cs index 2af41f0..1e96510 100644 --- a/TypographyShopDatabaseImplements/Models/Order.cs +++ b/TypographyShopDatabaseImplements/Models/Order.cs @@ -5,31 +5,41 @@ using System.ComponentModel.DataAnnotations; using TypographyDatabaseImplements.Models; using System.ComponentModel.DataAnnotations.Schema; using TypographyDataModels.Models; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public int PrintedId { get; set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int Count { get; set; } [Required] + [DataMember] public double Sum { get; set; } [Required] + [DataMember] public OrderStatus Status { get; set; } [Required] + [DataMember] public DateTime DateCreate { get; set; } - + [DataMember] public DateTime? DateImplement { get; set; } public virtual Printed? Printed { get; set; } diff --git a/TypographyShopDatabaseImplements/Models/Printed.cs b/TypographyShopDatabaseImplements/Models/Printed.cs index 70b3abd..6b0f569 100644 --- a/TypographyShopDatabaseImplements/Models/Printed.cs +++ b/TypographyShopDatabaseImplements/Models/Printed.cs @@ -4,18 +4,24 @@ using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using System.ComponentModel.DataAnnotations.Schema; using TypographyDatabaseImplement.Models; +using System.Runtime.Serialization; namespace TypographyDatabaseImplements.Models { + [DataContract] public class Printed : IPrintedModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string PrintedName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _printedComponents = null; [NotMapped] + [DataMember] public Dictionary PrintedComponents { get diff --git a/TypographyView/DataGridViewExtension.cs b/TypographyView/DataGridViewExtension.cs new file mode 100644 index 0000000..00a2ff7 --- /dev/null +++ b/TypographyView/DataGridViewExtension.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.Attributes; + +namespace TypographyView +{ + 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/TypographyView/FormClients.cs b/TypographyView/FormClients.cs index dc26e4b..9886b54 100644 --- a/TypographyView/FormClients.cs +++ b/TypographyView/FormClients.cs @@ -24,13 +24,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/TypographyView/FormComponents.cs b/TypographyView/FormComponents.cs index bcc56dc..1e2738d 100644 --- a/TypographyView/FormComponents.cs +++ b/TypographyView/FormComponents.cs @@ -1,16 +1,7 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -32,13 +23,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -49,27 +34,21 @@ 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(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - } + LoadData(); } } } @@ -104,6 +83,5 @@ namespace TypographyView { LoadData(); } - } } diff --git a/TypographyView/FormImplementers.cs b/TypographyView/FormImplementers.cs index 6da5c48..e0e5747 100644 --- a/TypographyView/FormImplementers.cs +++ b/TypographyView/FormImplementers.cs @@ -1,15 +1,7 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -32,13 +24,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -51,13 +37,10 @@ namespace TypographyView private void buttonCreate_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(); } } @@ -65,14 +48,11 @@ namespace TypographyView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TypographyView/FormMails.cs b/TypographyView/FormMails.cs index 0684000..989da6c 100644 --- a/TypographyView/FormMails.cs +++ b/TypographyView/FormMails.cs @@ -19,14 +19,7 @@ namespace TypographyView { 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/TypographyView/FormMain.Designer.cs b/TypographyView/FormMain.Designer.cs index 42bd8b1..4193e1e 100644 --- a/TypographyView/FormMain.Designer.cs +++ b/TypographyView/FormMain.Designer.cs @@ -34,18 +34,19 @@ изделиеToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem(); сотрудникиToolStripMenuItem = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); началоРаботыToolStripMenuItem = new ToolStripMenuItem(); + создатьBackupToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonUpd = new Button(); - почтаToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -53,7 +54,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, началоРаботыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, началоРаботыToolStripMenuItem, создатьBackupToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1146, 28); @@ -72,28 +73,35 @@ компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // изделиеToolStripMenuItem // изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; изделиеToolStripMenuItem.Size = new Size(224, 26); изделиеToolStripMenuItem.Text = "Изделие"; - изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click; + изделиеToolStripMenuItem.Click += PrintedsToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; клиентыToolStripMenuItem.Size = new Size(224, 26); клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + клиентыToolStripMenuItem.Click += clientsToolStripMenuItem_Click; // // сотрудникиToolStripMenuItem // сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; сотрудникиToolStripMenuItem.Size = new Size(224, 26); сотрудникиToolStripMenuItem.Text = "Сотрудники"; - сотрудникиToolStripMenuItem.Click += РаботникиToolStripMenuItem_Click; + сотрудникиToolStripMenuItem.Click += implementersToolStripMenuItem_Click; + // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(224, 26); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += mailsToolStripMenuItem_Click; // // отчётыToolStripMenuItem // @@ -114,21 +122,28 @@ компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; компонентыПоИзделиямToolStripMenuItem.Size = new Size(276, 26); компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; - компонентыПоИзделиямToolStripMenuItem.Click += ComponentProductsToolStripMenuItem_Click; + компонентыПоИзделиямToolStripMenuItem.Click += componentsByPrintedsToolStripMenuItem_Click; // // списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; списокЗаказовToolStripMenuItem.Size = new Size(276, 26); списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + списокЗаказовToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; // // началоРаботыToolStripMenuItem // началоРаботыToolStripMenuItem.Name = "началоРаботыToolStripMenuItem"; началоРаботыToolStripMenuItem.Size = new Size(131, 24); началоРаботыToolStripMenuItem.Text = "Начало работы"; - началоРаботыToolStripMenuItem.Click += НачалоРаботыToolStripMenuItem_Click; + началоРаботыToolStripMenuItem.Click += startWorkingsToolStripMenuItem_Click; + // + // создатьBackupToolStripMenuItem + // + создатьBackupToolStripMenuItem.Name = "создатьBackupToolStripMenuItem"; + создатьBackupToolStripMenuItem.Size = new Size(130, 24); + создатьBackupToolStripMenuItem.Text = "Создать backup"; + создатьBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click; // // dataGridView // @@ -190,14 +205,7 @@ buttonUpd.TabIndex = 6; buttonUpd.Text = "Обновить список"; buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += ButtonUpd_Click; - // - // почтаToolStripMenuItem - // - почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - почтаToolStripMenuItem.Size = new Size(224, 26); - почтаToolStripMenuItem.Text = "Почта"; - почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + buttonUpd.Click += ButtonRef_Click; // // FormMain // @@ -242,5 +250,6 @@ private ToolStripMenuItem сотрудникиToolStripMenuItem; private ToolStripMenuItem началоРаботыToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьBackupToolStripMenuItem; } } \ No newline at end of file diff --git a/TypographyView/FormMain.cs b/TypographyView/FormMain.cs index 936cb7f..5bd7c9b 100644 --- a/TypographyView/FormMain.cs +++ b/TypographyView/FormMain.cs @@ -1,18 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using TypographyDataModels.Enums; using AbstractShopView; -using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.DI; namespace TypographyView { @@ -22,97 +13,143 @@ namespace TypographyView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } - private void FormMain_Load(object sender, EventArgs e) { LoadData(); } - private void LoadData() { + _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["PrintedId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Orders loading"); + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { - _logger.LogError(ex, "Orders loading error"); + _logger.LogError(ex, "Ошибка загрузки заказов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void РаботникиToolStripMenuItem_Click(object sender, EventArgs e) + + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void PrintedsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void clientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void implementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void mailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void printedsListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) { - form.ShowDialog(); + _reportLogic.SavePrintedsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } - private void НачалоРаботыToolStripMenuItem_Click(object sender, EventArgs e) + + private void componentsByPrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void ordersListToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } - private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) + + private void createBackupToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Backup created", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - - private void ЗакускаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); - if (service is FormPrinteds form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } + private OrderBindingModel CreateBindingModel(int id) + { + return new OrderBindingModel + { + Id = id, + PrintedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PrintedId"].Value), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + }; + } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Status changes to 'В работе'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); @@ -124,18 +161,18 @@ namespace TypographyView } catch (Exception ex) { - _logger.LogError(ex, "Error taking an order to work"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } - private void ButtonOrderReady_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Status changes to 'Готов'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); @@ -147,49 +184,18 @@ namespace TypographyView } catch (Exception ex) { - _logger.LogError(ex, "Order readiness marking error"); + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs -e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SavePrintedsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - } - private void ComponentProductsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPrintedComponents)); - if (service is FormReportPrintedComponents form) - { - form.ShowDialog(); - } - } - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Status changes to 'Выдан'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); @@ -197,41 +203,21 @@ e) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Order №{id} issued", id); + _logger.LogInformation("Заказ №{id} выдан", id); LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "Order issue marking error"); + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - private void ButtonUpd_Click(object sender, EventArgs e) + private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); } - private OrderBindingModel CreateBindingModel(int id) - { - return new OrderBindingModel - { - Id = id, - PrintedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PrintedId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = (System.DateTime)dataGridView.SelectedRows[0].Cells["DateCreate"].Value, - }; - } - - private void почтаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } + } } diff --git a/TypographyView/FormPrinted.cs b/TypographyView/FormPrinted.cs index b41844f..b50c596 100644 --- a/TypographyView/FormPrinted.cs +++ b/TypographyView/FormPrinted.cs @@ -14,6 +14,7 @@ using TypographyDataModels.Models; using Microsoft.Extensions.Logging; using Microsoft.VisualBasic.Logging; using NLog.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -85,26 +86,23 @@ 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("Adding new component: {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(); } } @@ -112,22 +110,19 @@ namespace TypographyView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.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("Component editing: {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/TypographyView/FormPrinteds.cs b/TypographyView/FormPrinteds.cs index 2a5a2d6..8a1f4e1 100644 --- a/TypographyView/FormPrinteds.cs +++ b/TypographyView/FormPrinteds.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using TypographyContracts.BindingModels; +using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -35,32 +27,22 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["PrintedComponents"].Visible = false; - } - _logger.LogInformation("Ice creams loading"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка Машин"); } catch (Exception ex) { - _logger.LogError(ex, "Ice creams loading error"); + _logger.LogError(ex, "Ошибка загрузки Машин"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -68,14 +50,11 @@ namespace TypographyView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TypographyView/Program.cs b/TypographyView/Program.cs index 2dbc18b..9050369 100644 --- a/TypographyView/Program.cs +++ b/TypographyView/Program.cs @@ -10,14 +10,14 @@ using TypographyBusinessLogic.OfficePackage; using AbstractShopView; using TypographyBusinessLogic.MailWorker; using TypographyContracts.BindingModels; +using TypographyContracts.DI; +using DocumentFormat.OpenXml.Spreadsheet; namespace TypographyView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -27,12 +27,10 @@ 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,55 +45,47 @@ 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 MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - private static void ConfigureServices(ServiceCollection services) + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - 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(); + 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(); + 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(); } } } \ No newline at end of file -- 2.25.1 From ecebe2f1a15545ba2dbab4437170affee6df1c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Sat, 18 May 2024 02:29:35 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BD=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BD=D1=8F=D0=BB=20,=20=D0=BD=D0=B0=D0=B4=D0=BE=20?= =?UTF-8?q?=D0=B4=D1=83=D0=BC=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TypographyView/TypographyView.sln | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TypographyView/TypographyView.sln b/TypographyView/TypographyView.sln index f007842..8d34c86 100644 --- a/TypographyView/TypographyView.sln +++ b/TypographyView/TypographyView.sln @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyRestApi", "..\Typ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyClientApp", "..\TypographyClientApp\TypographyClientApp.csproj", "{2A9DA290-8A05-4524-A37C-5F19A66371FA}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ImplementationExtensions", "ImplementationExtensions", "{A6806C98-7F85-4C86-A8C1-00AEFB154001}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU -- 2.25.1 From 0ce1839aee9d5a87731d7e1c68a0afa9073016a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Sun, 19 May 2024 03:04:49 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D1=8F=20=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0=D1=8E,=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20?= =?UTF-8?q?=D0=BA=D1=82=D0=BE-=D1=82=D0=BE=20=D0=BF=D0=BE=D0=BD=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=D0=B5=D1=82,=20=D0=BD=D0=BE=20=D1=8F=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=BD=D0=B8=D0=BC=D0=B0=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ TypographyFileImplement/TypographyFileImplement.csproj | 8 +++++++- TypographyListImplement/TypographyListImplement.csproj | 6 +++++- .../TypographyDatabaseImplements.csproj | 4 ++++ TypographyView/TypographyView.sln | 2 -- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ca1c7a3..fd1bc54 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ *.userosscache *.sln.docstates +# dll files +*.dll + # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/TypographyFileImplement/TypographyFileImplement.csproj b/TypographyFileImplement/TypographyFileImplement.csproj index 95efe1f..6a3ed9c 100644 --- a/TypographyFileImplement/TypographyFileImplement.csproj +++ b/TypographyFileImplement/TypographyFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,10 @@ + + + + + + diff --git a/TypographyListImplement/TypographyListImplement.csproj b/TypographyListImplement/TypographyListImplement.csproj index 95efe1f..0870c01 100644 --- a/TypographyListImplement/TypographyListImplement.csproj +++ b/TypographyListImplement/TypographyListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,8 @@ + + + + diff --git a/TypographyShopDatabaseImplements/TypographyDatabaseImplements.csproj b/TypographyShopDatabaseImplements/TypographyDatabaseImplements.csproj index 30ea109..db8df79 100644 --- a/TypographyShopDatabaseImplements/TypographyDatabaseImplements.csproj +++ b/TypographyShopDatabaseImplements/TypographyDatabaseImplements.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/TypographyView/TypographyView.sln b/TypographyView/TypographyView.sln index 8d34c86..f007842 100644 --- a/TypographyView/TypographyView.sln +++ b/TypographyView/TypographyView.sln @@ -21,8 +21,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyRestApi", "..\Typ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyClientApp", "..\TypographyClientApp\TypographyClientApp.csproj", "{2A9DA290-8A05-4524-A37C-5F19A66371FA}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ImplementationExtensions", "ImplementationExtensions", "{A6806C98-7F85-4C86-A8C1-00AEFB154001}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU -- 2.25.1 From 094146aa0f3de997f45e4a0f0a664e35cef3fcbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Sun, 16 Jun 2024 19:02:16 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TypographyFileImplement/TypographyFileImplement.csproj | 7 +++---- TypographyListImplement/TypographyListImplement.csproj | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/TypographyFileImplement/TypographyFileImplement.csproj b/TypographyFileImplement/TypographyFileImplement.csproj index 6a3ed9c..62b320f 100644 --- a/TypographyFileImplement/TypographyFileImplement.csproj +++ b/TypographyFileImplement/TypographyFileImplement.csproj @@ -11,10 +11,9 @@ - - - - + + + diff --git a/TypographyListImplement/TypographyListImplement.csproj b/TypographyListImplement/TypographyListImplement.csproj index 0870c01..b841db0 100644 --- a/TypographyListImplement/TypographyListImplement.csproj +++ b/TypographyListImplement/TypographyListImplement.csproj @@ -11,8 +11,7 @@ - - - - + + + -- 2.25.1 From 62e756697766b3ffa5b13bfeef2ce3175cd29589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Tue, 18 Jun 2024 01:43:40 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D1=82=D0=B0=D0=B1=D1=83=D0=BB=D1=8F=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20+=20=D1=80=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=B2=20=D1=87=D0=B5=D0=BC=20=D0=B1=D1=8B?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TypographyFileImplement/TypographyFileImplement.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TypographyFileImplement/TypographyFileImplement.csproj b/TypographyFileImplement/TypographyFileImplement.csproj index 62b320f..4d8585a 100644 --- a/TypographyFileImplement/TypographyFileImplement.csproj +++ b/TypographyFileImplement/TypographyFileImplement.csproj @@ -12,8 +12,8 @@ - - + + -- 2.25.1