diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index 271ef21..bfeea10 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantFileImplemen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDatabaseImplement", "AutomobilePlantDatabaseImplement\AutomobilePlantDatabaseImplement.csproj", "{D727258B-7717-45AF-B438-B3BE3105E207}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantRestApi", "AutomobilePlantRestApi\AutomobilePlantRestApi.csproj", "{C4C82240-E531-4C99-B519-74DDDBD79326}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantRestApi", "AutomobilePlantRestApi\AutomobilePlantRestApi.csproj", "{C4C82240-E531-4C99-B519-74DDDBD79326}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantClientApp", "AutomobilePlantClientApp\AutomobilePlantClientApp.csproj", "{E72BF12B-595D-42B8-B994-B9740A392B02}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantClientApp", "AutomobilePlantClientApp\AutomobilePlantClientApp.csproj", "{E72BF12B-595D-42B8-B994-B9740A392B02}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/BackUpLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..2ffea61 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,95 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace AutomobilePlantBusinessLogic.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/AutomobilePlant/AutomobilePlantContracts/Attributes/ColumnAttribute.cs b/AutomobilePlant/AutomobilePlantContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..35a910c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,20 @@ +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/Attributes/GridViewAutoSize.cs b/AutomobilePlant/AutomobilePlantContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..7ee81db --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace AutomobilePlantContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj b/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj index 743e9bf..1d6431f 100644 --- a/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj +++ b/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/BackUpSaveBinidngModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..3c9314e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace AutomobilePlantContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/MessageInfoBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/MessageInfoBindingModel.cs index 7ded981..04265cc 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BindingModels/MessageInfoBindingModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace AutomobilePlantContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..339c283 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using AutomobilePlantContracts.BindingModels; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/DI/DependencyManager.cs b/AutomobilePlant/AutomobilePlantContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..71eb0f3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/DependencyManager.cs @@ -0,0 +1,63 @@ +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/DI/IDependencyContainer.cs b/AutomobilePlant/AutomobilePlantContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..c091adf --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/IDependencyContainer.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/DI/IImplementationExtension.cs b/AutomobilePlant/AutomobilePlantContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..8fd7841 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +namespace AutomobilePlantContracts.DI +{ + /// + /// Интерфейс для регистрации зависимостей в модулях + /// + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/DI/ServiceDependencyContainer.cs b/AutomobilePlant/AutomobilePlantContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..511bcc9 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/DI/ServiceProviderLoader.cs b/AutomobilePlant/AutomobilePlantContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..b586666 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,53 @@ +using System.Reflection; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/DI/UnityDependencyContainer.cs b/AutomobilePlant/AutomobilePlantContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..8b962a0 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IBackUpInfo.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..9b20de6 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs index 0629033..d1a98f0 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs @@ -1,25 +1,18 @@ -using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.ViewModels { public class CarViewModel : ICarModel { - public int Id { get; set; } - [DisplayName("Car's name")] - public string CarName { get; set; } = string.Empty; - [DisplayName("Price")] - public double Price { get; set; } - public Dictionary CarComponents - { - get; - set; - } = new(); - } + [Column(visible: false)] + public int Id { get; set; } + [Column("Car's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string CarName { get; set; } = string.Empty; + [Column("Price", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary CarComponents { get; set; } = new(); + } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ClientViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ClientViewModel.cs index 827e394..a4244ea 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ClientViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,17 @@ -using AutomobilePlantDataModels.Models; -using System.ComponentModel; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("Client's FIO")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Login (Email)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Password")] - public string Password { get; set; } = string.Empty; - } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Client's FIO", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Login (Email)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Password", width: 150)] + public string Password { get; set; } = string.Empty; + } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs index f5bf1a9..3216116 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs @@ -1,19 +1,15 @@ -using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } - [DisplayName("Component's name")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Cost")] - public double Cost { get; set; } - } + [Column(visible: false)] + public int Id { get; set; } + [Column("Component's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column("Cost", width: 100)] + public double Cost { get; set; } + } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs index 238ea6b..0a27451 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs @@ -1,22 +1,23 @@ -using AutomobilePlantDataModels.Models; -using System.ComponentModel; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("FIO")] - public string ImplementerFIO { get; set; } = string.Empty; + [Column("FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Password")] - public string Password { get; set; } = string.Empty; + [Column("Password", width: 150)] + public string Password { get; set; } = string.Empty; - [DisplayName("Work expirience")] - public int WorkExperience { get; set; } + [Column("Work expirience", width: 150)] + public int WorkExperience { get; set; } - [DisplayName("Qualification")] - public int Qualification { get; set; } + [Column("Qualification", width: 150)] + public int Qualification { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/MessageInfoViewModel .cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/MessageInfoViewModel .cs index 93c9422..1799bbd 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/MessageInfoViewModel .cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/MessageInfoViewModel .cs @@ -1,20 +1,24 @@ -using AutomobilePlantDataModels.Models; -using System.ComponentModel; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Models; namespace AutomobilePlantContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } + [Column("Sender", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; + [Column("Delivery Date", width: 100)] + public DateTime DateDelivery { get; set; } + [Column("Subject", width: 150)] + public string Subject { get; set; } = string.Empty; + [Column("Body", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; - public int? ClientId { get; set; } - [DisplayName("Sender")] - public string SenderName { get; set; } = string.Empty; - [DisplayName("Delivery Date")] - public DateTime DateDelivery { get; set; } - [DisplayName("Subject")] - public string Subject { get; set; } = string.Empty; - [DisplayName("Body")] - public string Body { get; set; } = string.Empty; - } + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs index 9f86e8c..2bfe54a 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs @@ -1,36 +1,34 @@ -using AutomobilePlantDataModels.Enums; +using AutomobilePlantContracts.Attributes; +using AutomobilePlantDataModels.Enums; using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AutomobilePlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Number")] - public int Id { get; set; } - public int CarId { get; set; } - [DisplayName("Car's name")] - public string CarName { get; set; } = string.Empty; - public int ClientId { get; set; } - [DisplayName("Client's FIO")] - public string ClientFIO { get; set; } = string.Empty; - public int? ImplementerId { get; set; } - [DisplayName("Implementer's FIO")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Count")] - public int Count { get; set; } - [DisplayName("Sum")] - public double Sum { get; set; } - [DisplayName("Status")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Date of creation")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Date of completion")] - public DateTime? DateImplement { get; set; } - } + [Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + [Column(visible: false)] + public int CarId { get; set; } + [Column("Car's name", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string CarName { get; set; } = string.Empty; + [Column(visible: false)] + public int ClientId { get; set; } + [Column("Client's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int? ImplementerId { get; set; } + [Column("Implementer's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column("Count", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column("Sum", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column("Status", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column("Date of creation", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column("Date of completion", width: 100)] + public DateTime? DateImplement { get; set; } + } } diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IMessageInfoModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IMessageInfoModel.cs index ca34e78..5f4f91a 100644 --- a/AutomobilePlant/AutomobilePlantDataModels/Models/IMessageInfoModel.cs +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IMessageInfoModel.cs @@ -1,7 +1,7 @@ namespace AutomobilePlantDataModels.Models { - public interface IMessageInfoModel - { + public interface IMessageInfoModel : IId + { string MessageId { get; } int? ClientId { get; } string SenderName { get; } diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabaseImplement.csproj b/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabaseImplement.csproj index 8837474..4f6d377 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabaseImplement.csproj +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabaseImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -20,4 +20,8 @@ + + + + diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/DatabaseImplementationExtension.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..edad610 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantDatabaseImplement.Implements; + +namespace AutomobilePlantDatabaseImplement +{ + 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/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/BackUpInfo.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..7909404 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using AutomobilePlantContracts.StoragesContracts; + +namespace AutomobilePlantDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new AutomobilePlantDatabase(); + 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/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Car.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Car.cs index 6129ac1..f646942 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Car.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Car.cs @@ -3,20 +3,26 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace AutomobilePlantDatabaseImplement.Models { - public class Car : ICarModel - { - public int Id { get; private set; } + [DataContract] + public class Car : ICarModel + { + [DataMember] + public int Id { get; private set; } [Required] - public string CarName { get; private set; } = string.Empty; + [DataMember] + public string CarName { get; private set; } = string.Empty; [Required] - public double Price { get; private set; } + [DataMember] + public double Price { get; private set; } private Dictionary? _carComponents = null; [NotMapped] - public Dictionary CarComponents + [DataMember] + public Dictionary CarComponents { get { diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Client.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Client.cs index fb52417..67e9d14 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Client.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Client.cs @@ -3,21 +3,27 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace AutomobilePlantDatabaseImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] - public string Email { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Component.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Component.cs index 4793485..0dbefbc 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Component.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Component.cs @@ -3,17 +3,22 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace AutomobilePlantDatabaseImplement.Models { - public class Component : IComponentModel - { - public int Id { get; private set; } + [DataContract] + public class Component : IComponentModel + { + [DataMember] + public int Id { get; private set; } [Required] - public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public string ComponentName { get; private set; } = string.Empty; [Required] - public double Cost { get; set; } + [DataMember] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List CarComponents { get; set; } = new(); diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs index 4094b75..bb89136 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs @@ -2,22 +2,25 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace AutomobilePlantDatabaseImplement.Models { - public class Implementer : IImplementerModel - { - public int Id { get; private set; } + [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 string ImplementerFIO { get; private set; } = string.Empty; - - public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } - - public int Qualification { get; private set; } - - [ForeignKey("ImplementerId")] + [ForeignKey("ImplementerId")] public virtual List Orders { get; private set; } = new(); public static Implementer? Create(ImplementerBindingModel model) diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/MessageInfo.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/MessageInfo.cs index 804ddec..b26f7fa 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/MessageInfo.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/MessageInfo.cs @@ -2,23 +2,31 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace AutomobilePlantDatabaseImplement.Models { - public class MessageInfo : IMessageInfoModel + [DataContract] + public class MessageInfo : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; + [DataMember] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; private set; } @@ -48,5 +56,7 @@ namespace AutomobilePlantDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs index 4ce3118..30eda21 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs @@ -7,29 +7,40 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.ConstrainedExecution; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace AutomobilePlantDatabaseImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } [Required] - public int CarId { get; private set; } + [DataMember] + public int CarId { get; private set; } [Required] - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } [Required] - public int Count { get; private set; } + [DataMember] + public int Count { get; private set; } [Required] - public double Sum { get; private set; } + [DataMember] + public double Sum { get; private set; } [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public virtual Car Car { get; private set; } public virtual Client Client { get; set; } public Implementer? Implementer { get; private set; } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/AutomobilePlantFileImplement.csproj b/AutomobilePlant/AutomobilePlantFileImplement/AutomobilePlantFileImplement.csproj index a6820c2..547b455 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/AutomobilePlantFileImplement.csproj +++ b/AutomobilePlant/AutomobilePlantFileImplement/AutomobilePlantFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/AutomobilePlant/AutomobilePlantFileImplement/FileImplementationExtension.cs b/AutomobilePlant/AutomobilePlantFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..0fad965 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantFileImplement.Implements; + +namespace AutomobilePlantFileImplement +{ + 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/AutomobilePlant/AutomobilePlantFileImplement/Implements/BackUpInfo.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..be33307 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,28 @@ +using AutomobilePlantContracts.StoragesContracts; + +namespace AutomobilePlantFileImplement.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/AutomobilePlant/AutomobilePlantFileImplement/Models/Car.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Car.cs index 6eb3a53..fbb7f93 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Car.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Car.cs @@ -1,27 +1,28 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class Car : ICarModel - { - public string CarName { get; private set; } = string.Empty; + [DataContract] + public class Car : ICarModel + { + [DataMember] + public string CarName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public double Price { get; private set; } - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _carComponents = null; - public Dictionary CarComponents + [DataMember] + public Dictionary CarComponents { get { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Client.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Client.cs index e7ef2d7..d0fb0f5 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Client.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Client.cs @@ -1,19 +1,25 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Component.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Component.cs index b526725..e08b09c 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Component.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Component.cs @@ -1,20 +1,20 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = String.Empty; - public double Cost { get; set; } + [DataContract] + public class Component : IComponentModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = String.Empty; + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel? model) { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs index 9170a3a..136fc10 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs @@ -1,21 +1,28 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class Implementer : IImplementerModel - { - public int Id { get; private set; } + [DataContract] + public class Implementer : IImplementerModel + { + [DataMember] + public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Qualification { get; private set; } public static Implementer? Create(XElement element) { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/MessageInfo.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/MessageInfo.cs index f1aacf7..75812f2 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/MessageInfo.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/MessageInfo.cs @@ -1,23 +1,31 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class MessageInfo : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel model) { @@ -71,5 +79,7 @@ namespace AutomobilePlantFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs index c9f24c0..7a1f5f2 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs @@ -2,26 +2,32 @@ using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Enums; using AutomobilePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; using System.Xml.Linq; namespace AutomobilePlantFileImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int CarId { get; private set; } - public int ClientId { get; set; } - public int? ImplementerId { get; set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + public int CarId { 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) { diff --git a/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj b/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj index a6820c2..95c981f 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj +++ b/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -11,4 +11,8 @@ + + + + diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/BackUpInfo.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..8c94f15 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using AutomobilePlantContracts.StoragesContracts; + +namespace AutomobilePlantListImplement.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/AutomobilePlant/AutomobilePlantListImplement/ListImplementationExtension.cs b/AutomobilePlant/AutomobilePlantListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..293534d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.DI; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantListImplement.Implements; + +namespace AutomobilePlantListImplement +{ + 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/AutomobilePlant/AutomobilePlantListImplement/Models/MessageInfo.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/MessageInfo.cs index 269cd8c..64104e7 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Models/MessageInfo.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/MessageInfo.cs @@ -44,5 +44,7 @@ namespace AutomobilePlantListImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/AutomobilePlant/AutomobilePlantView/DataGridViewExtension.cs b/AutomobilePlant/AutomobilePlantView/DataGridViewExtension.cs new file mode 100644 index 0000000..b8662a1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/DataGridViewExtension.cs @@ -0,0 +1,45 @@ +using AutomobilePlantContracts.Attributes; + +namespace AutomobilePlantView +{ + 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/AutomobilePlant/AutomobilePlantView/FormCar.cs b/AutomobilePlant/AutomobilePlantView/FormCar.cs index 118c17f..26f3a64 100644 --- a/AutomobilePlant/AutomobilePlantView/FormCar.cs +++ b/AutomobilePlant/AutomobilePlantView/FormCar.cs @@ -1,17 +1,9 @@ using AutomobilePlantDataModels.Models; 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 AutomobilePlantContracts.BusinessLogicsContracts; using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.DI; namespace AutomobilePlantView { @@ -80,48 +72,42 @@ namespace AutomobilePlantView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent)); - if (service is FormCarComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - if (_carComponents.ContainsKey(form.Id)) - { - _carComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _carComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_carComponents.ContainsKey(form.Id)) + { + _carComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _carComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent)); - if (service is FormCarComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _carComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _carComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _carComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _carComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.cs b/AutomobilePlant/AutomobilePlantView/FormCars.cs index c1875a7..9fd8959 100644 --- a/AutomobilePlant/AutomobilePlantView/FormCars.cs +++ b/AutomobilePlant/AutomobilePlantView/FormCars.cs @@ -1,16 +1,7 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -using Microsoft.VisualBasic.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 AutomobilePlantContracts.DI; namespace AutomobilePlantView { @@ -33,16 +24,9 @@ namespace AutomobilePlantView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["CarComponents"].Visible = false; - } - _logger.LogInformation("Загрузка машин"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка Машин"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки Машин"); @@ -51,27 +35,21 @@ namespace AutomobilePlantView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCar)); - if (service is FormCar 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(FormCar)); - if (service is FormCar 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/AutomobilePlant/AutomobilePlantView/FormClients.cs b/AutomobilePlant/AutomobilePlantView/FormClients.cs index 26b35fb..560ba8a 100644 --- a/AutomobilePlant/AutomobilePlantView/FormClients.cs +++ b/AutomobilePlant/AutomobilePlantView/FormClients.cs @@ -24,15 +24,9 @@ namespace AutomobilePlantView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки клиентов"); diff --git a/AutomobilePlant/AutomobilePlantView/FormComponents.cs b/AutomobilePlant/AutomobilePlantView/FormComponents.cs index 0aa581c..3eb00b8 100644 --- a/AutomobilePlant/AutomobilePlantView/FormComponents.cs +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.cs @@ -1,5 +1,6 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using Microsoft.Extensions.Logging; namespace AutomobilePlantView @@ -22,15 +23,9 @@ namespace AutomobilePlantView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки компонентов"); @@ -39,27 +34,21 @@ namespace AutomobilePlantView } 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(); - } + LoadData(); } } } diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementers.cs b/AutomobilePlant/AutomobilePlantView/FormImplementers.cs index d0820bd..30be897 100644 --- a/AutomobilePlant/AutomobilePlantView/FormImplementers.cs +++ b/AutomobilePlant/AutomobilePlantView/FormImplementers.cs @@ -1,15 +1,7 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; 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; namespace AutomobilePlantView { @@ -32,15 +24,9 @@ namespace AutomobilePlantView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка исполнителей"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); @@ -50,29 +36,23 @@ namespace AutomobilePlantView } 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(); } } private void buttonUpdate_Click(object sender, EventArgs e) { 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/AutomobilePlant/AutomobilePlantView/FormMails.cs b/AutomobilePlant/AutomobilePlantView/FormMails.cs index 5ed0215..5792da0 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMails.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMails.cs @@ -19,16 +19,9 @@ namespace AutomobilePlantView { 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; - } - _logger.LogInformation("Загрузка писем"); - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка писем"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки писем"); diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs index 1d2d841..80cec61 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -20,182 +20,190 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - menuStrip1 = new MenuStrip(); - toolStripMenuItemCatalogs = new ToolStripMenuItem(); - toolStripMenuItemComponents = new ToolStripMenuItem(); - toolStripMenuItemCars = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - implementersToolStripMenuItem = new ToolStripMenuItem(); - reportsToolStripMenuItem = new ToolStripMenuItem(); - carsListToolStripMenuItem = new ToolStripMenuItem(); - componentsByCarsToolStripMenuItem = new ToolStripMenuItem(); - ordersListToolStripMenuItem = new ToolStripMenuItem(); - startWorkingsToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonIssuedOrder = new Button(); - buttonRefresh = new Button(); - mailsToolStripMenuItem = new ToolStripMenuItem(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs, reportsToolStripMenuItem, startWorkingsToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(800, 24); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // toolStripMenuItemCatalogs - // - toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem, implementersToolStripMenuItem, mailsToolStripMenuItem }); - toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; - toolStripMenuItemCatalogs.Size = new Size(65, 20); - toolStripMenuItemCatalogs.Text = "Catalogs"; - // - // toolStripMenuItemComponents - // - toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; - toolStripMenuItemComponents.Size = new Size(180, 22); - toolStripMenuItemComponents.Text = "Components"; - toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; - // - // toolStripMenuItemCars - // - toolStripMenuItemCars.Name = "toolStripMenuItemCars"; - toolStripMenuItemCars.Size = new Size(180, 22); - toolStripMenuItemCars.Text = "Cars"; - toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; - // - // clientsToolStripMenuItem - // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(180, 22); - clientsToolStripMenuItem.Text = "Clients"; - clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; - // - // implementersToolStripMenuItem - // - implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; - implementersToolStripMenuItem.Size = new Size(180, 22); - implementersToolStripMenuItem.Text = "Implementers"; - implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; - // - // reportsToolStripMenuItem - // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem }); - reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; - reportsToolStripMenuItem.Size = new Size(59, 20); - reportsToolStripMenuItem.Text = "Reports"; - // - // carsListToolStripMenuItem - // - carsListToolStripMenuItem.Name = "carsListToolStripMenuItem"; - carsListToolStripMenuItem.Size = new Size(186, 22); - carsListToolStripMenuItem.Text = "Cars' list"; - carsListToolStripMenuItem.Click += carsListToolStripMenuItem_Click; - // - // componentsByCarsToolStripMenuItem - // - componentsByCarsToolStripMenuItem.Name = "componentsByCarsToolStripMenuItem"; - componentsByCarsToolStripMenuItem.Size = new Size(186, 22); - componentsByCarsToolStripMenuItem.Text = "Components' by cars"; - componentsByCarsToolStripMenuItem.Click += componentsByCarsToolStripMenuItem_Click; - // - // ordersListToolStripMenuItem - // - ordersListToolStripMenuItem.Name = "ordersListToolStripMenuItem"; - ordersListToolStripMenuItem.Size = new Size(186, 22); - ordersListToolStripMenuItem.Text = "Orders' list"; - ordersListToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; - // - // startWorkingsToolStripMenuItem - // - startWorkingsToolStripMenuItem.Name = "startWorkingsToolStripMenuItem"; - startWorkingsToolStripMenuItem.Size = new Size(94, 20); - startWorkingsToolStripMenuItem.Text = "Start workings"; - startWorkingsToolStripMenuItem.Click += startWorkingsToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 27); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(659, 411); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(677, 27); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(111, 23); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Create order"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(677, 56); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(111, 23); - buttonIssuedOrder.TabIndex = 5; - buttonIssuedOrder.Text = "Order is issued"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(677, 85); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(111, 23); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Refresh"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRef_Click; - // - // mailsToolStripMenuItem - // - mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; - mailsToolStripMenuItem.Size = new Size(180, 22); - mailsToolStripMenuItem.Text = "mails"; - mailsToolStripMenuItem.Click += mailsToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(buttonRefresh); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - Name = "FormMain"; - Text = "Automobile plant"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + toolStripMenuItemCatalogs = new ToolStripMenuItem(); + toolStripMenuItemComponents = new ToolStripMenuItem(); + toolStripMenuItemCars = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); + mailsToolStripMenuItem = new ToolStripMenuItem(); + reportsToolStripMenuItem = new ToolStripMenuItem(); + carsListToolStripMenuItem = new ToolStripMenuItem(); + componentsByCarsToolStripMenuItem = new ToolStripMenuItem(); + ordersListToolStripMenuItem = new ToolStripMenuItem(); + startWorkingsToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + createBackupToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs, reportsToolStripMenuItem, startWorkingsToolStripMenuItem, createBackupToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItemCatalogs + // + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem, implementersToolStripMenuItem, mailsToolStripMenuItem }); + toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + toolStripMenuItemCatalogs.Size = new Size(65, 20); + toolStripMenuItemCatalogs.Text = "Catalogs"; + // + // toolStripMenuItemComponents + // + toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; + toolStripMenuItemComponents.Size = new Size(147, 22); + toolStripMenuItemComponents.Text = "Components"; + toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; + // + // toolStripMenuItemCars + // + toolStripMenuItemCars.Name = "toolStripMenuItemCars"; + toolStripMenuItemCars.Size = new Size(147, 22); + toolStripMenuItemCars.Text = "Cars"; + toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; + // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(147, 22); + clientsToolStripMenuItem.Text = "Clients"; + clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + // + // implementersToolStripMenuItem + // + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(147, 22); + implementersToolStripMenuItem.Text = "Implementers"; + implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; + // + // mailsToolStripMenuItem + // + mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; + mailsToolStripMenuItem.Size = new Size(147, 22); + mailsToolStripMenuItem.Text = "mails"; + mailsToolStripMenuItem.Click += mailsToolStripMenuItem_Click; + // + // reportsToolStripMenuItem + // + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem }); + reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; + reportsToolStripMenuItem.Size = new Size(59, 20); + reportsToolStripMenuItem.Text = "Reports"; + // + // carsListToolStripMenuItem + // + carsListToolStripMenuItem.Name = "carsListToolStripMenuItem"; + carsListToolStripMenuItem.Size = new Size(186, 22); + carsListToolStripMenuItem.Text = "Cars' list"; + carsListToolStripMenuItem.Click += carsListToolStripMenuItem_Click; + // + // componentsByCarsToolStripMenuItem + // + componentsByCarsToolStripMenuItem.Name = "componentsByCarsToolStripMenuItem"; + componentsByCarsToolStripMenuItem.Size = new Size(186, 22); + componentsByCarsToolStripMenuItem.Text = "Components' by cars"; + componentsByCarsToolStripMenuItem.Click += componentsByCarsToolStripMenuItem_Click; + // + // ordersListToolStripMenuItem + // + ordersListToolStripMenuItem.Name = "ordersListToolStripMenuItem"; + ordersListToolStripMenuItem.Size = new Size(186, 22); + ordersListToolStripMenuItem.Text = "Orders' list"; + ordersListToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; + // + // startWorkingsToolStripMenuItem + // + startWorkingsToolStripMenuItem.Name = "startWorkingsToolStripMenuItem"; + startWorkingsToolStripMenuItem.Size = new Size(94, 20); + startWorkingsToolStripMenuItem.Text = "Start workings"; + startWorkingsToolStripMenuItem.Click += startWorkingsToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(659, 411); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(677, 27); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(111, 23); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Create order"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(677, 56); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(111, 23); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Order is issued"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(677, 85); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(111, 23); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // createBackupToolStripMenuItem + // + createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem"; + createBackupToolStripMenuItem.Size = new Size(95, 20); + createBackupToolStripMenuItem.Text = "Create backup"; + createBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + Name = "FormMain"; + Text = "Automobile plant"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; + private MenuStrip menuStrip1; private ToolStripMenuItem toolStripMenuItemCatalogs; private ToolStripMenuItem toolStripMenuItemComponents; private ToolStripMenuItem toolStripMenuItemCars; @@ -211,5 +219,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem startWorkingsToolStripMenuItem; private ToolStripMenuItem mailsToolStripMenuItem; - } + private ToolStripMenuItem createBackupToolStripMenuItem; + } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs index d1962d0..8c904ac 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -1,224 +1,218 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.DI; using AutomobilePlantDataModels.Enums; using Microsoft.Extensions.Logging; namespace AutomobilePlantView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - _workProcess = workProcess; - } - 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["CarId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, 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 + { + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void CarsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void CarsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCars)); - if (service is FormCars form) - { - form.ShowDialog(); - } - } + private void clientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void clientsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } + private void implementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void implementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } + private void mailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void mailsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } + private void carsListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveCarsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } - private void carsListToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveCarsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } + private void componentsByCarsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void componentsByCarsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportCarComponents)); - if (service is FormReportCarComponents form) - { - form.ShowDialog(); - } - } + private void ordersListToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } - private void ordersListToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } - private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + private void createBackupToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + 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 ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private OrderBindingModel CreateBindingModel(int id) - { - return new OrderBindingModel - { - Id = id, - CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].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("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _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("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - 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("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); + } + private OrderBindingModel CreateBindingModel(int id) + { + return new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].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("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _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("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + 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("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } } diff --git a/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index 522f2ab..b35b983 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -2,20 +2,16 @@ using AutomobilePlantBusinessLogic.OfficePackage.Implements; using AutomobilePlantBusinessLogic.OfficePackage; using AutomobilePlantContracts.BusinessLogicsContracts; -using AutomobilePlantContracts.StoragesContracts; -using AutomobilePlantDatabaseImplement.Implements; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using AutomobilePlantBusinessLogic.MailWorker; using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.DI; namespace AutomobilePlantView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -25,14 +21,12 @@ namespace AutomobilePlantView // 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(); - mailSender?.MailConfig(new MailConfigBindingModel + try + { + var mailSender = DependencyManager.Instance.Resolve(); + mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, @@ -45,52 +39,49 @@ namespace AutomobilePlantView var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); } catch (Exception ex) - { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Ошибка работы с почтой"); + { + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, "Ошибка работы с почтой"); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + Application.Run(DependencyManager.Instance.Resolve()); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + private static void InitDependency() + { + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + 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 diff --git a/AutomobilePlant/ImplementationExtensions/AutomobilePlantContracts.dll b/AutomobilePlant/ImplementationExtensions/AutomobilePlantContracts.dll new file mode 100644 index 0000000..3432b33 Binary files /dev/null and b/AutomobilePlant/ImplementationExtensions/AutomobilePlantContracts.dll differ diff --git a/AutomobilePlant/ImplementationExtensions/AutomobilePlantDataModels.dll b/AutomobilePlant/ImplementationExtensions/AutomobilePlantDataModels.dll new file mode 100644 index 0000000..6e02030 Binary files /dev/null and b/AutomobilePlant/ImplementationExtensions/AutomobilePlantDataModels.dll differ diff --git a/AutomobilePlant/ImplementationExtensions/AutomobilePlantFileImplement.dll b/AutomobilePlant/ImplementationExtensions/AutomobilePlantFileImplement.dll new file mode 100644 index 0000000..5acc331 Binary files /dev/null and b/AutomobilePlant/ImplementationExtensions/AutomobilePlantFileImplement.dll differ diff --git a/AutomobilePlant/ImplementationExtensions/AutomobilePlantListImplement.dll b/AutomobilePlant/ImplementationExtensions/AutomobilePlantListImplement.dll new file mode 100644 index 0000000..c379df1 Binary files /dev/null and b/AutomobilePlant/ImplementationExtensions/AutomobilePlantListImplement.dll differ