From a1496cfc611e66e925d501d926a45cfd83f5d371 Mon Sep 17 00:00:00 2001 From: Anatoliy Date: Sat, 22 Jun 2024 21:11:56 +0400 Subject: [PATCH] PIbd22_Kuznetsov_A.V._lab8 --- .../BusinessLogic/BackUpLogic.cs | 93 ++++++ .../Attributes/ColumnAttribute.cs | 27 ++ .../Attributes/GridViewAutoSize.cs | 20 ++ .../BindingModels/BackUpSaveBindingModel.cs | 7 + .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 8 + .../DI/DependencyContainerUnity.cs | 52 +++ .../DI/DependencyManager.cs | 66 ++++ .../DI/IDependencyContainer.cs | 18 ++ .../DI/IImplementationExtension.cs | 8 + .../DI/ServiceDependencyContainer.cs | 60 ++++ .../DI/ServiceProviderLoader.cs | 46 +++ .../SewingDressesContracts.csproj | 4 +- .../StoragesContracts/IBackUpInfo.cs | 14 + .../ViewModels/ClientViewModel.cs | 8 +- .../ViewModels/ComponentViewModel.cs | 8 +- .../ViewModels/DressViewModel.cs | 7 +- .../ViewModels/ImplementViewModel.cs | 12 +- .../ViewModels/MessageInfoViewModel.cs | 16 +- .../ViewModels/OrderViewModel.cs | 22 +- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 22 ++ .../20240621163736_inmig.Designer.cs | 301 ++++++++++++++++++ .../Migrations/20240621163736_inmig.cs | 215 +++++++++++++ .../SewingDressesDatabaseModelSnapshot.cs | 3 + .../Models/BackUpInfo.cs | 27 ++ .../Models/Client.cs | 6 + .../Models/Component.cs | 5 + .../Models/Dress.cs | 7 +- .../Models/Implement.cs | 7 + .../Models/MessageInfo.cs | 9 + .../Models/Order.cs | 11 + .../SewingDressesDatabase.cs | 2 +- .../SewingDressesDatabaseImplement.csproj | 4 +- .../FileImplementationExtension.cs | 21 ++ .../Implements/BackUpInfo.cs | 45 +++ .../Models/Client.cs | 6 + .../Models/Component.cs | 5 + .../Models/Dress.cs | 6 + .../Models/Implement.cs | 7 + .../Models/MessageInfo.cs | 14 +- .../Models/Order.cs | 11 + .../SewingDressesFileImplement.csproj | 3 + .../Implements/BackUpInfo.cs | 22 ++ .../ListImplementationExtension.cs | 26 ++ .../Models/MessageInfo.cs | 1 + .../SewingDressesListImplement.csproj | 3 + .../SewingDressesView/ClientsForm.cs | 9 +- .../SewingDressesView/ComponentsForm.cs | 31 +- .../DataGridViewExtension.cs | 45 +++ SewingDresses/SewingDressesView/DressForm.cs | 42 ++- .../SewingDressesView/DressesForm.cs | 32 +- .../SewingDressesView/ImplementsForm.cs | 31 +- SewingDresses/SewingDressesView/MailForm.cs | 9 +- .../SewingDressesView/MainForm.Designer.cs | 33 +- SewingDresses/SewingDressesView/MainForm.cs | 104 +++--- SewingDresses/SewingDressesView/Program.cs | 89 +++--- 57 files changed, 1466 insertions(+), 247 deletions(-) create mode 100644 SewingDresses/SewingDressesBusinessLogic/BusinessLogic/BackUpLogic.cs create mode 100644 SewingDresses/SewingDressesContracts/Attributes/ColumnAttribute.cs create mode 100644 SewingDresses/SewingDressesContracts/Attributes/GridViewAutoSize.cs create mode 100644 SewingDresses/SewingDressesContracts/BindingModels/BackUpSaveBindingModel.cs create mode 100644 SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/DependencyContainerUnity.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/DependencyManager.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/IDependencyContainer.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/IImplementationExtension.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/ServiceDependencyContainer.cs create mode 100644 SewingDresses/SewingDressesContracts/DI/ServiceProviderLoader.cs create mode 100644 SewingDresses/SewingDressesContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 SewingDresses/SewingDressesDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.Designer.cs create mode 100644 SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.cs create mode 100644 SewingDresses/SewingDressesDatabaseImplement/Models/BackUpInfo.cs create mode 100644 SewingDresses/SewingDressesFileImplement/FileImplementationExtension.cs create mode 100644 SewingDresses/SewingDressesFileImplement/Implements/BackUpInfo.cs create mode 100644 SewingDresses/SewingDressesListImplement/Implements/BackUpInfo.cs create mode 100644 SewingDresses/SewingDressesListImplement/ListImplementationExtension.cs create mode 100644 SewingDresses/SewingDressesView/DataGridViewExtension.cs diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/BackUpLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..bab2ccf --- /dev/null +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,93 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.StoragesContracts; +using SewingDressesDataModels; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace SewingDressesDatabaseImplement.Implements +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + private readonly IBackUpInfo _backUpInfo; + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + public void CreateBackUp(BackUpSaveBindingModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", + nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) !=null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс - модель для { type.Name }"); + + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + method?.MakeGenericMethod(modelType).Invoke(this, new + object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + ZipFile.CreateFromDirectory(model.FolderName, fileName); + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + + } + } +} diff --git a/SewingDresses/SewingDressesContracts/Attributes/ColumnAttribute.cs b/SewingDresses/SewingDressesContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..f94b787 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + public bool Visible { get; private set; } + public int Width { get; private set; } + public GridViewAutoSize GridViewAutoSize { get; private set; } + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/SewingDresses/SewingDressesContracts/Attributes/GridViewAutoSize.cs b/SewingDresses/SewingDressesContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..f0b38c7 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/SewingDresses/SewingDressesContracts/BindingModels/BackUpSaveBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..4af8796 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,7 @@ +namespace SewingDressesContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/SewingDresses/SewingDressesContracts/BindingModels/MessageInfoBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/MessageInfoBindingModel.cs index fd2907f..a953d5f 100644 --- a/SewingDresses/SewingDressesContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SewingDresses/SewingDressesContracts/BindingModels/MessageInfoBindingModel.cs @@ -4,6 +4,7 @@ namespace SewingDressesContracts.BindingModels { public class MessageInfoBindingModel : IMessageInfoModel { + public int Id { get; set; } public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..3b8c206 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,8 @@ +using SewingDressesContracts.BindingModels; +namespace SewingDressesContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/SewingDresses/SewingDressesContracts/DI/DependencyContainerUnity.cs b/SewingDresses/SewingDressesContracts/DI/DependencyContainerUnity.cs new file mode 100644 index 0000000..d42150c --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/DependencyContainerUnity.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Unity; +using Unity.Microsoft.Logging; + +namespace SewingDressesContracts.DI +{ + public class DependencyContainerUnity : IDependencyContainer + { + private readonly IUnityContainer _container; + + public DependencyContainerUnity() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + ILoggerFactory loggerFactory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(loggerFactory)); + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterType(TypeLifetime.Singleton); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + if (isSingle) + { + _container.RegisterType(TypeLifetime.Singleton); + } + else + { + _container.RegisterType(); + } + } + } +} diff --git a/SewingDresses/SewingDressesContracts/DI/DependencyManager.cs b/SewingDresses/SewingDressesContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..d47268d --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + /// + /// Иницализация библиотек, в которых идут установки зависомстей + /// + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + /// + /// Регистрация логгера + /// + /// + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/SewingDresses/SewingDressesContracts/DI/IDependencyContainer.cs b/SewingDresses/SewingDressesContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..136247b --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/IDependencyContainer.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.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/SewingDresses/SewingDressesContracts/DI/IImplementationExtension.cs b/SewingDresses/SewingDressesContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..e927987 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/IImplementationExtension.cs @@ -0,0 +1,8 @@ +namespace SewingDressesContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/SewingDresses/SewingDressesContracts/DI/ServiceDependencyContainer.cs b/SewingDresses/SewingDressesContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..2bc7924 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,60 @@ +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 SewingDressesContracts.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 T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + } +} diff --git a/SewingDresses/SewingDressesContracts/DI/ServiceProviderLoader.cs b/SewingDresses/SewingDressesContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..4247660 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace SewingDressesContracts.DI +{ + public static partial class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/SewingDresses/SewingDressesContracts/SewingDressesContracts.csproj b/SewingDresses/SewingDressesContracts/SewingDressesContracts.csproj index 6906958..f62cdd5 100644 --- a/SewingDresses/SewingDressesContracts/SewingDressesContracts.csproj +++ b/SewingDresses/SewingDressesContracts/SewingDressesContracts.csproj @@ -4,14 +4,16 @@ net6.0 enable enable - True + + + diff --git a/SewingDresses/SewingDressesContracts/StoragesContracts/IBackUpInfo.cs b/SewingDresses/SewingDressesContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..62be3e3 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ClientViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ClientViewModel.cs index 68bad04..a900ac4 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/ClientViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ using System.ComponentModel; +using SewingDressesContracts.Attributes; using SewingDressesDataModels.Models; namespace SewingDressesContracts.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: "Почта", 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/SewingDresses/SewingDressesContracts/ViewModels/ComponentViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ComponentViewModel.cs index dbfc7d9..a23b001 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/ComponentViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/ComponentViewModel.cs @@ -1,14 +1,16 @@ -using SewingDressesDataModels.Models; +using SewingDressesContracts.Attributes; +using SewingDressesDataModels.Models; using System.ComponentModel; namespace SewingDressesContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 100)] public double Cost { get; set; } } } diff --git a/SewingDresses/SewingDressesContracts/ViewModels/DressViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/DressViewModel.cs index ad1832d..a8a599c 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/DressViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/DressViewModel.cs @@ -1,15 +1,18 @@ using System.ComponentModel; +using SewingDressesContracts.Attributes; using SewingDressesDataModels.Models; namespace SewingDressesContracts.ViewModels { public class DressViewModel : IDressModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название платья")] + [Column(title: "Название платья", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string DressName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width:100)] public double Price { get; set; } + [Column(visible:false)] public Dictionary DressComponents { get; set; } = new(); } } diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs index 41acdec..b18842c 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs @@ -1,4 +1,5 @@ -using SewingDressesDataModels.Models; +using SewingDressesContracts.Attributes; +using SewingDressesDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,15 @@ namespace SewingDressesContracts.ViewModels { public class ImplementViewModel : IImplementModel { + [Column(visible:false)] public int Id { get; set; } - [DisplayName("Имя исполнителя")] + [Column(title: "Имя исполнителя", width: 150)] public string ImplementFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Опыт работы")] + [Column(title: "Опыт работы", width: 150)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 150)] public int Qualification { get; set; } } } diff --git a/SewingDresses/SewingDressesContracts/ViewModels/MessageInfoViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/MessageInfoViewModel.cs index 820cfed..f58ac34 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/MessageInfoViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/MessageInfoViewModel.cs @@ -1,20 +1,24 @@ -using SewingDressesDataModels.Models; +using SewingDressesContracts.Attributes; +using SewingDressesDataModels.Models; using System.ComponentModel; namespace SewingDressesContracts.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(title: "Имя отправителя", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата доставки")] + [Column(title: "Дата доставки", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Тема письма")] + [Column(title: "Тема письма", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Внутренности письма")] + [Column(title: "Внутренности письма", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } } } diff --git a/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs index 7429814..e277f4a 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using SewingDressesContracts.Attributes; using SewingDressesDataModels.Enums; using SewingDressesDataModels.Models; @@ -6,26 +7,29 @@ namespace SewingDressesContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 70)] public int Id { get; set; } + [Column(visible: false)] public int DressId { get; set; } + [Column(visible: false)] public int? ImplementId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("Имя клиента")] + [Column(title: "Имя клиента", width: 150)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Имя исполнителя")] + [Column(title: "Имя исполнителя", width: 150)] public string? ImplementFIO { get; set; } = string.Empty; - [DisplayName("Платье")] + [Column(title: "Платье", width: 150)] public string DressName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title:"Сумма", width: 70)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 100)] public OrderStatus Status { get; set; } - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 150)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 150)] public DateTime? DateImplement { get; set; } } } diff --git a/SewingDresses/SewingDressesDataModels/Models/IMessageInfoModel.cs b/SewingDresses/SewingDressesDataModels/Models/IMessageInfoModel.cs index 9d0eb86..af5945b 100644 --- a/SewingDresses/SewingDressesDataModels/Models/IMessageInfoModel.cs +++ b/SewingDresses/SewingDressesDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace SewingDressesDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/SewingDresses/SewingDressesDatabaseImplement/DatabaseImplementationExtension.cs b/SewingDresses/SewingDressesDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..86057a8 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using SewingDressesContracts.DI; +using SewingDressesDatabaseImplement.Implements; +using SewingDressesDatabaseImplement.Models; +using SewingDressesContracts.StoragesContracts; + +namespace SewingDressesDatabaseImplement +{ + 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/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.Designer.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.Designer.cs new file mode 100644 index 0000000..a77bd6d --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.Designer.cs @@ -0,0 +1,301 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SewingDressesDatabaseImplement; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + [DbContext(typeof(SewingDressesDatabase))] + [Migration("20240621163736_inmig")] + partial class inmig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DressName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Dresses"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DressId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DressId"); + + b.ToTable("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implements"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("Id") + .HasColumnType("int"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DressId") + .HasColumnType("int"); + + b.Property("ImplementId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("DressId"); + + b.HasIndex("ImplementId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component") + .WithMany("DressComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Components") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Dress"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Orders") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement") + .WithMany("Orders") + .HasForeignKey("ImplementId"); + + b.Navigation("Client"); + + b.Navigation("Dress"); + + b.Navigation("Implement"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Navigation("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.cs new file mode 100644 index 0000000..42b51a1 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240621163736_inmig.cs @@ -0,0 +1,215 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + /// + public partial class inmig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Dresses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Dresses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implements", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementFIO = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implements", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + Id = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "DressComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DressComponents", x => x.Id); + table.ForeignKey( + name: "FK_DressComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_DressComponents_Dresses_DressId", + column: x => x.DressId, + principalTable: "Dresses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + ImplementId = table.Column(type: "int", nullable: true), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Dresses_DressId", + column: x => x.DressId, + principalTable: "Dresses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implements_ImplementId", + column: x => x.ImplementId, + principalTable: "Implements", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_DressComponents_ComponentId", + table: "DressComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_DressComponents_DressId", + table: "DressComponents", + column: "DressId"); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_DressId", + table: "Orders", + column: "DressId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementId", + table: "Orders", + column: "ImplementId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DressComponents"); + + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Dresses"); + + migrationBuilder.DropTable( + name: "Implements"); + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs index bc0009e..bd43f19 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs @@ -155,6 +155,9 @@ namespace SewingDressesDatabaseImplement.Migrations b.Property("DateDelivery") .HasColumnType("datetime2"); + b.Property("Id") + .HasColumnType("int"); + b.Property("SenderName") .IsRequired() .HasColumnType("nvarchar(max)"); diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/BackUpInfo.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/BackUpInfo.cs new file mode 100644 index 0000000..94ed868 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/BackUpInfo.cs @@ -0,0 +1,27 @@ +using SewingDressesContracts.StoragesContracts; +using SewingDressesDatabaseImplement.Models; +namespace SewingDressesDatabaseImplement.Models +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SewingDressesDatabase(); + return context.Set().ToList(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Client.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Client.cs index ed0eece..e8f9e23 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Client.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Client.cs @@ -4,17 +4,23 @@ using SewingDressesDatabaseImplement.Models; using SewingDressesDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SewingDressesDatabaseImplement.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/SewingDresses/SewingDressesDatabaseImplement/Models/Component.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Component.cs index 8c51f4b..3b2acd2 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Component.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Component.cs @@ -3,15 +3,20 @@ using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SewingDressesDatabaseImplement.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 DressComponents { get; set; } = new(); diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Dress.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Dress.cs index 82dbf42..562bcf8 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Dress.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Dress.cs @@ -3,19 +3,24 @@ using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; - +using System.Runtime.Serialization; namespace SewingDressesDatabaseImplement.Models { + [DataContract] public class Dress : IDressModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string DressName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _dressComponents = null; [NotMapped] + [DataMember] public Dictionary DressComponents { get diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs index 275bcb3..97b01b0 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs @@ -6,21 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace SewingDressesDatabaseImplement.Models { + [DataContract] public class Implement : IImplementModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ImplementFIO { get; private set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; private set; } [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [Required] + [DataMember] public int Qualification { get; private set; } [ForeignKey("ImplementId")] public virtual List? Orders { get; set; } = new(); diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/MessageInfo.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/MessageInfo.cs index 631b110..3a30aea 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/MessageInfo.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/MessageInfo.cs @@ -2,21 +2,30 @@ using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SewingDressesDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + public int Id { get; set; } [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } [Required] + [DataMember] public string SenderName { get; private set; } = string.Empty; [Required] + [DataMember] public DateTime DateDelivery { get; private set; } [Required] + [DataMember] public string Subject { get; private set; } = string.Empty; [Required] + [DataMember] public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs index f29665e..5491301 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs @@ -4,25 +4,36 @@ using SewingDressesDataModels.Enums; using SewingDressesDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SewingDressesDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public int DressId { get; private set; } [Required] + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementId { get; private set; } [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } public virtual Dress Dress { get; set; } public virtual Client Client { get; set; } diff --git a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs index 0501a31..051c17b 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs @@ -8,7 +8,7 @@ namespace SewingDressesDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-J8AJ26MV\SQLEXPRESS;Initial Catalog=DressAtelierDatabaseFull30;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-J8AJ26MV\SQLEXPRESS;Initial Catalog=DressAtelierDatabaseFull3512345;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj index 34733c4..a82481a 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj +++ b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj @@ -4,7 +4,6 @@ net6.0 enable enable - True @@ -23,4 +22,7 @@ + + + diff --git a/SewingDresses/SewingDressesFileImplement/FileImplementationExtension.cs b/SewingDresses/SewingDressesFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..d0766a7 --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/FileImplementationExtension.cs @@ -0,0 +1,21 @@ +using SewingDressesContracts.DI; +using SewingDressesContracts.StoragesContracts; +using SewingDressesFileImplement.Implements; + +namespace SewingDressesFileImplement +{ + 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/SewingDresses/SewingDressesFileImplement/Implements/BackUpInfo.cs b/SewingDresses/SewingDressesFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..253a051 --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,45 @@ +using SewingDressesContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + List? list = new(); + + var source = DataFileSingleton.GetInstance(); + + Type typeRequired = typeof(T); + Type typeSource = source.GetType(); + + foreach (var property in typeSource.GetProperties()) + { + if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments()[0] == typeRequired) + { + list.Add((T)property.GetValue(source)); + } + } + return list; + } + + 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/SewingDresses/SewingDressesFileImplement/Models/Client.cs b/SewingDresses/SewingDressesFileImplement/Models/Client.cs index b6e13ee..e30a644 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Client.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SewingDressesContracts.BindingModels; using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SewingDressesFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; set; } + [DataMember] public string ClientFIO { get; set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/SewingDresses/SewingDressesFileImplement/Models/Component.cs b/SewingDresses/SewingDressesFileImplement/Models/Component.cs index 8338296..fd8a2a6 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Component.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Component.cs @@ -1,14 +1,19 @@ using SewingDressesContracts.BindingModels; using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SewingDressesFileImplement.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; private set; } public static Component? Create(ComponentBindingModel model) { diff --git a/SewingDresses/SewingDressesFileImplement/Models/Dress.cs b/SewingDresses/SewingDressesFileImplement/Models/Dress.cs index 3315aed..0019868 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Dress.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Dress.cs @@ -1,18 +1,24 @@ using SewingDressesContracts.BindingModels; using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SewingDressesFileImplement.Models { + [DataContract] public class Dress : IDressModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string DressName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _dressComponents = null; + [DataMember] public Dictionary DressComponents { get diff --git a/SewingDresses/SewingDressesFileImplement/Models/Implement.cs b/SewingDresses/SewingDressesFileImplement/Models/Implement.cs index 3401290..aaba3df 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Implement.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Implement.cs @@ -5,18 +5,25 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SewingDressesFileImplement.Models { + [DataContract] public class Implement : IImplementModel { + [DataMember] public int Id { get; set; } + [DataMember] public string ImplementFIO { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; + [DataMember] public int WorkExperience { get; set; } + [DataMember] public int Qualification { get; set; } public static Implement? Create(ImplementBindingModel? model) { diff --git a/SewingDresses/SewingDressesFileImplement/Models/MessageInfo.cs b/SewingDresses/SewingDressesFileImplement/Models/MessageInfo.cs index 44d6836..e476cd0 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/MessageInfo.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/MessageInfo.cs @@ -1,22 +1,26 @@ using SewingDressesContracts.BindingModels; using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SewingDressesFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + public int Id { get; set; } + [DataMember] public string MessageId { get; set; } = string.Empty; - + [DataMember] public int? ClientId { get; set; } - + [DataMember] public string SenderName { get; set; } = string.Empty; - + [DataMember] public DateTime DateDelivery { get; set; } - + [DataMember] public string Subject { get; set; } = string.Empty; - + [DataMember] public string Body { get; set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel? model) diff --git a/SewingDresses/SewingDressesFileImplement/Models/Order.cs b/SewingDresses/SewingDressesFileImplement/Models/Order.cs index 1fc4cfd..98715d9 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Order.cs @@ -3,20 +3,31 @@ using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Enums; using SewingDressesDataModels.Models; using System.Data; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SewingDressesFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int DressId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementId { get; private set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } + [DataMember] public OrderStatus Status { get; private set; } + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set;} public static Order? Create(OrderBindingModel model) diff --git a/SewingDresses/SewingDressesFileImplement/SewingDressesFileImplement.csproj b/SewingDresses/SewingDressesFileImplement/SewingDressesFileImplement.csproj index df23651..3c99fa7 100644 --- a/SewingDresses/SewingDressesFileImplement/SewingDressesFileImplement.csproj +++ b/SewingDresses/SewingDressesFileImplement/SewingDressesFileImplement.csproj @@ -11,4 +11,7 @@ + + + diff --git a/SewingDresses/SewingDressesListImplement/Implements/BackUpInfo.cs b/SewingDresses/SewingDressesListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..b810757 --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using SewingDressesContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesListImplement.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/SewingDresses/SewingDressesListImplement/ListImplementationExtension.cs b/SewingDresses/SewingDressesListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..d9c086f --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/ListImplementationExtension.cs @@ -0,0 +1,26 @@ +using SewingDressesContracts.DI; +using SewingDressesContracts.StoragesContracts; +using SewingDressesListImplement.Implements; +namespace SewingDressesListImplement +{ + 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/SewingDresses/SewingDressesListImplement/Models/MessageInfo.cs b/SewingDresses/SewingDressesListImplement/Models/MessageInfo.cs index f2dbc4e..e13d8b1 100644 --- a/SewingDresses/SewingDressesListImplement/Models/MessageInfo.cs +++ b/SewingDresses/SewingDressesListImplement/Models/MessageInfo.cs @@ -6,6 +6,7 @@ namespace SewingDressesListImplement.Models { public class MessageInfo : IMessageInfoModel { + public int Id { get; set; } public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/SewingDresses/SewingDressesListImplement/SewingDressesListImplement.csproj b/SewingDresses/SewingDressesListImplement/SewingDressesListImplement.csproj index 48b8843..c4790d8 100644 --- a/SewingDresses/SewingDressesListImplement/SewingDressesListImplement.csproj +++ b/SewingDresses/SewingDressesListImplement/SewingDressesListImplement.csproj @@ -12,4 +12,7 @@ + + + diff --git a/SewingDresses/SewingDressesView/ClientsForm.cs b/SewingDresses/SewingDressesView/ClientsForm.cs index bf20bd0..5442195 100644 --- a/SewingDresses/SewingDressesView/ClientsForm.cs +++ b/SewingDresses/SewingDressesView/ClientsForm.cs @@ -58,14 +58,7 @@ namespace SewingDressesView { try { - var list = _clientLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].Visible = false; - } + dataGridView.FillAndConfigGrid(_clientLogic.ReadList(null)); _logger.LogInformation("Load clients"); } catch (Exception ex) diff --git a/SewingDresses/SewingDressesView/ComponentsForm.cs b/SewingDresses/SewingDressesView/ComponentsForm.cs index 5d6b55a..e8aa7a8 100644 --- a/SewingDresses/SewingDressesView/ComponentsForm.cs +++ b/SewingDresses/SewingDressesView/ComponentsForm.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SewingDressesContracts.BindingModels; using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -26,29 +27,25 @@ namespace SewingDressesView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ComponentForm)); - if (service is ComponentForm form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void buttonChange_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(ComponentForm)); - if (service is ComponentForm 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(); } + } } @@ -94,13 +91,7 @@ namespace SewingDressesView { 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("Load components"); } catch (Exception ex) diff --git a/SewingDresses/SewingDressesView/DataGridViewExtension.cs b/SewingDresses/SewingDressesView/DataGridViewExtension.cs new file mode 100644 index 0000000..4adb249 --- /dev/null +++ b/SewingDresses/SewingDressesView/DataGridViewExtension.cs @@ -0,0 +1,45 @@ +using SewingDressesContracts.Attributes; + +namespace SewingDressesView +{ + 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/SewingDresses/SewingDressesView/DressForm.cs b/SewingDresses/SewingDressesView/DressForm.cs index beab79c..3619fbc 100644 --- a/SewingDresses/SewingDressesView/DressForm.cs +++ b/SewingDresses/SewingDressesView/DressForm.cs @@ -4,6 +4,7 @@ using SewingDressesDataModels.Models; using SewingDressesContracts.SearchModels; using Microsoft.Extensions.Logging; using SewingDressesContracts.BindingModels; +using SewingDressesContracts.DI; namespace SewingDressesView { @@ -27,38 +28,33 @@ namespace SewingDressesView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(DressComponentForm)); - if (service is DressComponentForm 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("Add new component: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count); - if (_dressComponents.ContainsKey(form.Id)) - { - _dressComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _dressComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Add new component: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count); + if (_dressComponents.ContainsKey(form.Id)) + { + _dressComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _dressComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } - + } private void buttonChange_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(DressComponentForm)); - if (service is DressComponentForm form) - { + var form = DependencyManager.Instance.Resolve(); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; @@ -73,7 +69,7 @@ namespace SewingDressesView _dressComponents[form.Id] = (form.ComponentModel, form.Count); LoadData(); } - } + } } diff --git a/SewingDresses/SewingDressesView/DressesForm.cs b/SewingDresses/SewingDressesView/DressesForm.cs index 8f8f1be..9898ba3 100644 --- a/SewingDresses/SewingDressesView/DressesForm.cs +++ b/SewingDresses/SewingDressesView/DressesForm.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SewingDressesContracts.BindingModels; using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -26,29 +27,25 @@ namespace SewingDressesView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(DressForm)); - if (service is DressForm form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void buttonChange_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(DressForm)); - if (service is DressForm 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(); } + } } @@ -94,14 +91,7 @@ namespace SewingDressesView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["DressComponents"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Load components"); } catch (Exception ex) diff --git a/SewingDresses/SewingDressesView/ImplementsForm.cs b/SewingDresses/SewingDressesView/ImplementsForm.cs index 2070d6c..e774f46 100644 --- a/SewingDresses/SewingDressesView/ImplementsForm.cs +++ b/SewingDresses/SewingDressesView/ImplementsForm.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using SewingDressesContracts.DI; namespace SewingDressesView { @@ -28,13 +29,7 @@ namespace SewingDressesView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - } - _logger.LogInformation("Loading employees"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); } catch (Exception ex) { @@ -44,14 +39,12 @@ namespace SewingDressesView } private void buttonCreate_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); - if (service is ImplementForm form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } + } private void ImplementsForm_Load(object sender, EventArgs e) @@ -63,15 +56,13 @@ namespace SewingDressesView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); - if (service is ImplementForm 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/SewingDresses/SewingDressesView/MailForm.cs b/SewingDresses/SewingDressesView/MailForm.cs index a3593e5..1b5d063 100644 --- a/SewingDresses/SewingDressesView/MailForm.cs +++ b/SewingDresses/SewingDressesView/MailForm.cs @@ -33,14 +33,7 @@ namespace SewingDressesView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Loading materials"); } catch (Exception ex) diff --git a/SewingDresses/SewingDressesView/MainForm.Designer.cs b/SewingDresses/SewingDressesView/MainForm.Designer.cs index 25b74a5..d62a20d 100644 --- a/SewingDresses/SewingDressesView/MainForm.Designer.cs +++ b/SewingDresses/SewingDressesView/MainForm.Designer.cs @@ -44,6 +44,7 @@ компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem(); + создатьБэкапToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -55,12 +56,12 @@ dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(804, 447); + dataGridView.Size = new Size(1145, 447); dataGridView.TabIndex = 0; // // buttonCreate // - buttonCreate.Location = new Point(854, 62); + buttonCreate.Location = new Point(1183, 44); buttonCreate.Name = "buttonCreate"; buttonCreate.Size = new Size(194, 37); buttonCreate.TabIndex = 1; @@ -70,7 +71,7 @@ // // buttonOrderGive // - buttonOrderGive.Location = new Point(854, 142); + buttonOrderGive.Location = new Point(1183, 124); buttonOrderGive.Name = "buttonOrderGive"; buttonOrderGive.Size = new Size(194, 37); buttonOrderGive.TabIndex = 4; @@ -80,7 +81,7 @@ // // buttonOrderUpdate // - buttonOrderUpdate.Location = new Point(854, 219); + buttonOrderUpdate.Location = new Point(1183, 201); buttonOrderUpdate.Name = "buttonOrderUpdate"; buttonOrderUpdate.Size = new Size(194, 37); buttonOrderUpdate.TabIndex = 5; @@ -91,10 +92,10 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, создатьБэкапToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1096, 28); + menuStrip1.Size = new Size(1389, 28); menuStrip1.TabIndex = 6; menuStrip1.Text = "menuStrip1"; // @@ -108,35 +109,35 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(216, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // платьяToolStripMenuItem // платьяToolStripMenuItem.Name = "платьяToolStripMenuItem"; - платьяToolStripMenuItem.Size = new Size(224, 26); + платьяToolStripMenuItem.Size = new Size(216, 26); платьяToolStripMenuItem.Text = "Платья"; платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click; // // clientsToolStripMenuItem // clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(224, 26); + clientsToolStripMenuItem.Size = new Size(216, 26); clientsToolStripMenuItem.Text = "Клиенты"; clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(224, 26); + исполнителиToolStripMenuItem.Size = new Size(216, 26); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += ImplementToolStripMenuItem_Click; // // почтовыеПисьмаToolStripMenuItem // почтовыеПисьмаToolStripMenuItem.Name = "почтовыеПисьмаToolStripMenuItem"; - почтовыеПисьмаToolStripMenuItem.Size = new Size(224, 26); + почтовыеПисьмаToolStripMenuItem.Size = new Size(216, 26); почтовыеПисьмаToolStripMenuItem.Text = "ПочтовыеПисьма"; почтовыеПисьмаToolStripMenuItem.Click += emailsToolStripMenuItem_Click; // @@ -175,11 +176,18 @@ запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; // + // создатьБэкапToolStripMenuItem + // + создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem"; + создатьБэкапToolStripMenuItem.Size = new Size(122, 24); + создатьБэкапToolStripMenuItem.Text = "Создать бэкап"; + создатьБэкапToolStripMenuItem.Click += СоздатьБекапToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1096, 493); + ClientSize = new Size(1389, 493); Controls.Add(buttonOrderUpdate); Controls.Add(buttonOrderGive); Controls.Add(buttonCreate); @@ -214,5 +222,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem почтовыеПисьмаToolStripMenuItem; + private ToolStripMenuItem создатьБэкапToolStripMenuItem; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index dcb952e..2ecd444 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -3,6 +3,8 @@ using SewingDressesContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using System.Windows.Forms; using SewingDressesBusinessLogic.BusinessLogic; +using SewingDressesDatabaseImplement.Implements; +using SewingDressesContracts.DI; namespace SewingDressesView { @@ -12,26 +14,21 @@ namespace SewingDressesView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void LoadData() { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["DressId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementId"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Load orders"); } catch (Exception ex) @@ -42,30 +39,24 @@ namespace SewingDressesView private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ComponentsForm)); - if (service is ComponentsForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void DressesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(DressesForm)); - if (service is DressesForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void buttonCreate_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(OrderForm)); - if (service is OrderForm form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } @@ -104,19 +95,15 @@ namespace SewingDressesView } private void ComponentProductsToolStripMenuItemReport_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ReportDressComponentsForm)); - if (service is ReportDressComponentsForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void OrdersToolStripMenuItemReport_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ReportOrdersForm)); - if (service is ReportOrdersForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void DressesToolStripMenuItemReport_Click(object sender, EventArgs e) @@ -134,35 +121,54 @@ namespace SewingDressesView private void clientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ClientsForm)); - if (service is ClientsForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void ImplementToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ImplementsForm)); - if (service is ImplementsForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementLogic)) as IImplementLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void emailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(MailForm)); - if (service is MailForm form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + + } + private void СоздатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } + } } diff --git a/SewingDresses/SewingDressesView/Program.cs b/SewingDresses/SewingDressesView/Program.cs index ae4c656..eb6cd76 100644 --- a/SewingDresses/SewingDressesView/Program.cs +++ b/SewingDresses/SewingDressesView/Program.cs @@ -5,27 +5,23 @@ using SewingDressesDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System.Drawing; using SewingDressesBusinessLogic.OfficePackage; using SewingDressesBusinessLogic.OfficePackage.Implements; using SewingDressesBusinessLogic.MailWorker; +using SewingDressesContracts.DI; namespace SewingDressesView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependencies(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new() { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -39,54 +35,51 @@ namespace SewingDressesView } 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) + private static void InitDependencies() { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.InitDependency(); - services.AddTransient(); - 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.AddSingleton(); + DependencyManager.Instance.RegisterType(); + 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(true); - 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(); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file