diff --git a/.gitignore b/.gitignore
index ca1c7a3..5bdd661 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+/AircraftPlant/ImplementationExtensions
diff --git a/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj b/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj
index 9d5c14b..bd4cea7 100644
--- a/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj
+++ b/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj
@@ -15,4 +15,8 @@
+
+
+
+
diff --git a/AircraftPlant/AbstractShopListImplement/BackUpInfo.cs b/AircraftPlant/AbstractShopListImplement/BackUpInfo.cs
new file mode 100644
index 0000000..5e74482
--- /dev/null
+++ b/AircraftPlant/AbstractShopListImplement/BackUpInfo.cs
@@ -0,0 +1,21 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement
+{
+ 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/AircraftPlant/AbstractShopListImplement/ImplementationExtension.cs b/AircraftPlant/AbstractShopListImplement/ImplementationExtension.cs
new file mode 100644
index 0000000..315dd04
--- /dev/null
+++ b/AircraftPlant/AbstractShopListImplement/ImplementationExtension.cs
@@ -0,0 +1,27 @@
+using AircraftPlantContracts.DI;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantListImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement
+{
+ public class ImplementationExtension : 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/AircraftPlant/AbstractShopListImplement/Message.cs b/AircraftPlant/AbstractShopListImplement/Message.cs
index 0a6857f..ec1cfc0 100644
--- a/AircraftPlant/AbstractShopListImplement/Message.cs
+++ b/AircraftPlant/AbstractShopListImplement/Message.cs
@@ -17,6 +17,7 @@ namespace AircraftPlantListImplement
public DateTime DateDelivery { get; set; }
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
+ public int Id => throw new NotImplementedException();
public static Message? Create(MessageInfoBindingModel model)
{
if (model == null)
diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs
new file mode 100644
index 0000000..8ce736e
--- /dev/null
+++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs
@@ -0,0 +1,101 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantDataModels;
+using DocumentFormat.OpenXml.EMMA;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.IO.Compression;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantBusinessLogic.BusinessLogics
+{
+ public class BackUpLogic : IBackUpLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IBackUpInfo _backUpInfo;
+ public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo)
+ {
+ _logger = logger;
+ _backUpInfo = backUpInfo;
+ }
+ public void CreateBackUp(BackUpSaveBindingModel model)
+ {
+ if (_backUpInfo == null)
+ {
+ return;
+ }
+ try
+ {
+ _logger.LogDebug("Clear folder");
+ // зачистка папки и удаление старого архива
+ var dirInfo = new DirectoryInfo(model.FolderName);
+ if (dirInfo.Exists)
+ {
+ foreach (var file in dirInfo.GetFiles())
+ {
+ file.Delete();
+ }
+ }
+ _logger.LogDebug("Delete archive");
+ string fileName = $"{model.FolderName}.zip";
+ if (File.Exists(fileName))
+ {
+ File.Delete(fileName);
+ }
+ // берем метод для сохранения
+ _logger.LogDebug("Get assembly");
+ var typeIId = typeof(IId);
+ var assembly = typeIId.Assembly;
+ if (assembly == null)
+ {
+ throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
+ }
+ var types = assembly.GetTypes();
+ var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
+ _logger.LogDebug("Find {count} types", types.Length);
+ foreach (var type in types)
+ {
+ if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
+ {
+ var modelType =
+ _backUpInfo.GetTypeByModelInterface(type.Name);
+ if (modelType == null)
+ {
+ throw new InvalidOperationException($"Не найден класс - модель для { type.Name }");
+ }
+ _logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
+ // вызываем метод на выполнение
+ method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
+ }
+ }
+ _logger.LogDebug("Create zip and remove folder");
+ // архивируем
+ ZipFile.CreateFromDirectory(model.FolderName, fileName);
+ // удаляем папку
+ dirInfo.Delete(true);
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+ private void SaveToFile(string folderName) where T : class, new()
+ {
+ var records = _backUpInfo.GetList();
+ if (records == null)
+ {
+ _logger.LogWarning("{type} type get null list", typeof(T).Name);
+ return;
+ }
+ var jsonFormatter = new DataContractJsonSerializer(typeof(List));
+ using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
+ jsonFormatter.WriteObject(fs, records);
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj b/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj
index d2377af..8cd3cf0 100644
--- a/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj
+++ b/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj
@@ -9,6 +9,8 @@
+
+
diff --git a/AircraftPlant/AircraftPlantContracts»/Attributes/ColumnAttribute.cs b/AircraftPlant/AircraftPlantContracts»/Attributes/ColumnAttribute.cs
new file mode 100644
index 0000000..c5a057f
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/Attributes/ColumnAttribute.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/Attributes/GridViewAutoSize.cs b/AircraftPlant/AircraftPlantContracts»/Attributes/GridViewAutoSize.cs
new file mode 100644
index 0000000..4a95eed
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/Attributes/GridViewAutoSize.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.Attributes
+{
+ public enum GridViewAutoSize
+ {
+ NotSet = 0,
+ None = 1,
+ ColumnHeader = 2,
+ AllCellsExceptHeader = 4,
+ AllCells = 6,
+ DisplayedCellsExceptHeader = 8,
+ DisplayedCells = 10,
+ Fill = 16
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/BindingModels/BackUpSaveBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/BackUpSaveBindingModel.cs
new file mode 100644
index 0000000..268bed3
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/BackUpSaveBindingModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BindingModels
+{
+ public class BackUpSaveBindingModel
+ {
+ public string FolderName { get; set; } = string.Empty;
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/BindingModels/MessageInfoBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/MessageInfoBindingModel.cs
index 538624b..2fe6c80 100644
--- a/AircraftPlant/AircraftPlantContracts»/BindingModels/MessageInfoBindingModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/MessageInfoBindingModel.cs
@@ -15,5 +15,6 @@ namespace AircraftPlantContracts.BindingModels
public DateTime DateDelivery { get; set; }
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
+ public int Id => throw new NotImplementedException();
}
}
diff --git a/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IBackUpLogic.cs b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IBackUpLogic.cs
new file mode 100644
index 0000000..07f2932
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IBackUpLogic.cs
@@ -0,0 +1,14 @@
+using AircraftPlantContracts.BindingModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BusinessLogicsContracts
+{
+ public interface IBackUpLogic
+ {
+ void CreateBackUp(BackUpSaveBindingModel model);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/DI/DependencyManager.cs b/AircraftPlant/AircraftPlantContracts»/DI/DependencyManager.cs
new file mode 100644
index 0000000..3ee41f9
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/DependencyManager.cs
@@ -0,0 +1,69 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DI
+{
+ ///
+ /// Менеджер для работы с зависимостями
+ ///
+ public class DependencyManager
+ {
+ private readonly IDependencyContainer _dependencyManager;
+
+ private static DependencyManager? _manager;
+
+ private static readonly object _locjObject = new();
+
+ private DependencyManager()
+ {
+ _dependencyManager = new ServiceDependencyContainer();
+ }
+
+ public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
+
+ ///
+ /// Иницализация библиотек, в которых идут установки зависомстей
+ ///
+ public static void InitDependency()
+ {
+ var ext = ServiceProviderLoader.GetImplementationExtensions();
+ if (ext == null)
+ {
+ throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
+ }
+ // регистрируем зависимости
+ ext.RegisterServices();
+ }
+
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure);
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle);
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle);
+
+ ///
+ /// Получение класса со всеми зависмостями
+ ///
+ ///
+ ///
+ public T Resolve() => _dependencyManager.Resolve();
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantContracts»/DI/IDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts»/DI/IDependencyContainer.cs
new file mode 100644
index 0000000..2c453ba
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/IDependencyContainer.cs
@@ -0,0 +1,38 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/DI/IImplementationExtension.cs b/AircraftPlant/AircraftPlantContracts»/DI/IImplementationExtension.cs
new file mode 100644
index 0000000..cf5d667
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/IImplementationExtension.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DI
+{
+ ///
+ /// Интерфейс для регистрации зависимостей в модулях
+ ///
+ public interface IImplementationExtension
+ {
+ public int Priority { get; }
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/DI/ServiceDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts»/DI/ServiceDependencyContainer.cs
new file mode 100644
index 0000000..0bc57a9
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/ServiceDependencyContainer.cs
@@ -0,0 +1,62 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/DI/ServiceProviderLoader.cs b/AircraftPlant/AircraftPlantContracts»/DI/ServiceProviderLoader.cs
new file mode 100644
index 0000000..a28d4d4
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/ServiceProviderLoader.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.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";
+ }
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantContracts»/DI/UnityDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts»/DI/UnityDependencyContainer.cs
new file mode 100644
index 0000000..ca64ab0
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/DI/UnityDependencyContainer.cs
@@ -0,0 +1,42 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Unity.Microsoft.Logging;
+using Unity;
+
+namespace AircraftPlantContracts.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 U : class, T where T : class
+ {
+ _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
+ }
+
+ public void RegisterType(bool isSingle) where T : class
+ {
+ _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
+ }
+
+ public T Resolve()
+ {
+ return _container.Resolve();
+ }
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IBackUpInfo.cs b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IBackUpInfo.cs
new file mode 100644
index 0000000..7e98b6d
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IBackUpInfo.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.StoragesContracts
+{
+ public interface IBackUpInfo
+ {
+ List? GetList() where T : class, new();
+ Type? GetTypeByModelInterface(string modelInterfaceName);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/ClientViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/ClientViewModel.cs
index 5472026..587a7aa 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/ClientViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/ClientViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,12 +11,13 @@ namespace AircraftPlantContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
- public int Id { get; set; }
- [DisplayName("ФИО клиента")]
- public string ClientFIO { get; set; } = string.Empty;
- [DisplayName("Логин (эл. почта)")]
+ [Column(visible: false)]
+ public int Id { get; set; }
+ [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ClientFIO { get; set; } = string.Empty;
+ [Column(title: "Логин (эл. почта)", width: 150)]
public string Email { get; set; } = string.Empty;
- [DisplayName("Пароль")]
+ [Column(title: "Пароль", width: 150)]
public string Password { get; set; } = string.Empty;
}
}
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs
index 0e24d67..e18cec6 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,10 +11,11 @@ namespace AircraftPlantContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{
+ [Column(visible: false)]
public int Id { get; set; }
- [DisplayName("Название компонента")]
+ [Column(title: "Компонент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComponentName { get; set; } = string.Empty;
- [DisplayName("Цена")]
+ [Column(title: "Цена", width: 150)]
public double Cost { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/ImplementerViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/ImplementerViewModel.cs
index 5a96ee4..712f169 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/ImplementerViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/ImplementerViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,14 +11,15 @@ namespace AircraftPlantContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
+ [Column(visible: false)]
public int Id { get; set; }
- [DisplayName("ФИО исполнителя")]
+ [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
- [DisplayName("Пароль")]
+ [Column(title: "Пароль", width: 100)]
public string Password { get; set; } = string.Empty;
- [DisplayName("Опыт работы")]
+ [Column(title: "Стаж работы", width: 150)]
public int WorkExperience { get; set; }
- [DisplayName("Квалификация")]
+ [Column(title: "Квалификация", width: 150)]
public int Qualification { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/MessageInfoViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/MessageInfoViewModel.cs
index b5c4d0c..49a07c8 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/MessageInfoViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/MessageInfoViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,15 +11,25 @@ namespace AircraftPlantContracts.ViewModels
{
public class MessageInfoViewModel : IMessageInfoModel
{
+ [Column(visible: false)]
+ public int Id { get; set; }
+
+ [Column(visible: false)]
public string MessageId { get; set; } = string.Empty;
+
+ [Column(visible: false)]
public int? ClientId { get; set; }
- [DisplayName("Отправитель")]
+
+ [Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
- [DisplayName("Дата письма")]
+
+ [Column(title: "Дата письма", width: 120)]
public DateTime DateDelivery { get; set; }
- [DisplayName("Заголовок")]
+
+ [Column(title: "Заголовок", width: 120)]
public string Subject { get; set; } = string.Empty;
- [DisplayName("Текст")]
+
+ [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty;
}
}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs
index 62c76af..a2e2e4a 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs
@@ -6,6 +6,7 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using AircraftPlantContracts.Attributes;
namespace AircraftPlantContracts.ViewModels
{
@@ -18,69 +19,77 @@ namespace AircraftPlantContracts.ViewModels
///
/// Идентификатор
///
- [DisplayName("Номер")]
+ [Column(title: "Номер", width: 90)]
public int Id { get; set; }
///
/// Идентификатор изделия
///
+ [Column(visible: false)]
public int PlaneId { get; set; }
-
///
/// Название изделия
///
- [DisplayName("Изделие")]
+ [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string PlaneName { get; set; } = string.Empty;
///
/// Идентификатор клиента
///
+ [Column(visible: false)]
public int ClientId { get; set; }
///
/// ФИО клиента
///
- [DisplayName("ФИО клиента")]
+ [Column(title: "Имя клиента", width: 190)]
public string ClientFIO { get; set; } = string.Empty;
+ ///
+ /// Email клиента
+ ///
+ [Column(visible: false)]
+ public string ClientEmail { get; set; } = string.Empty;
+
///
/// Идентификатор исполнителя
///
+ [Column(visible: false)]
public int? ImplementerId { get; set; }
///
/// ФИО исполнителя
///
- [DisplayName("ФИО исполнителя")]
- public string ImplementerFIO { get; set; } = string.Empty;
+ [Column(title: "ФИО исполнителя", width: 150)]
+ public string? ImplementerFIO { get; set; } = null;
///
/// Количество изделий
///
- [DisplayName("Количество")]
+ [Column(title: "Количество", width: 100)]
public int Count { get; set; }
///
/// Сумма заказа
///
- [DisplayName("Сумма")]
+ [Column(title: "Сумма", width: 120)]
public double Sum { get; set; }
///
/// Статус заказа
///
- [DisplayName("Статус")]
+ [Column(title: "Статус", width: 70)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
///
/// Дата создания заказа
///
- [DisplayName("Дата создания")]
+ [Column(title: "Дата создания", width: 120)]
public DateTime DateCreate { get; set; } = DateTime.Now;
///
/// Дата выполнения заказа
///
- [DisplayName("Дата выполнения")]
+ [Column(title: "Дата выполнения", width: 120)]
public DateTime? DateImplement { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs
index 0e60ba4..60397cd 100644
--- a/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -17,23 +18,25 @@ namespace AircraftPlantContracts.ViewModels
///
/// Идентификатор
///
+ [Column(visible: false)]
public int Id { get; set; }
///
/// Название изделия
///
- [DisplayName("Название изделия")]
+ [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string PlaneName { get; set; } = string.Empty;
///
/// Стоимость изделия
///
- [DisplayName("Цена")]
+ [Column(title: "Цена", width: 70)]
public double Price { get; set; }
///
/// Коллекция компонентов изделия
///
+ [Column(visible: false)]
public Dictionary PlaneComponents
{
get;
diff --git a/AircraftPlant/AircraftPlantDataModels/IMessageInfoModel.cs b/AircraftPlant/AircraftPlantDataModels/IMessageInfoModel.cs
index 10c0535..1a9f3c7 100644
--- a/AircraftPlant/AircraftPlantDataModels/IMessageInfoModel.cs
+++ b/AircraftPlant/AircraftPlantDataModels/IMessageInfoModel.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AircraftPlantDataModels
{
- public interface IMessageInfoModel
+ public interface IMessageInfoModel : IId
{
string MessageId { get; }
int? ClientId { get; }
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj b/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
index 03cd680..586e3bb 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
@@ -20,6 +20,10 @@
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/ImplementationExtension.cs b/AircraftPlant/AircraftPlantDatabaseImplement/ImplementationExtension.cs
new file mode 100644
index 0000000..b2f0b6f
--- /dev/null
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/ImplementationExtension.cs
@@ -0,0 +1,27 @@
+using AircraftPlantContracts.DI;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantDatabaseImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantDatabaseImplement
+{
+ public class ImplementationExtension : IImplementationExtension
+ {
+ public int Priority => 3;
+
+ 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/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs
new file mode 100644
index 0000000..e0b57f1
--- /dev/null
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs
@@ -0,0 +1,32 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantDatabaseImplement.Implements
+{
+ public class BackUpInfo : IBackUpInfo
+ {
+ public List? GetList() where T : class, new()
+ {
+ using var context = new AircraftPlantDatabase();
+ 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/AircraftPlant/AircraftPlantDatabaseImplement/Models/Client.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Client.cs
index 31ea51f..33ba87e 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Client.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Client.cs
@@ -6,18 +6,24 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantDatabaseImplement.Models
{
+ [DataContract]
public class Client : IClientModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
[Required]
public string ClientFIO { get; set; } = string.Empty;
+ [DataMember]
[Required]
public string Email { get; set; } = string.Empty;
+ [DataMember]
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Component.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Component.cs
index 7ffeebf..a688f4c 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Component.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Component.cs
@@ -5,16 +5,21 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace AircraftPlantDatabaseImplement.Models
{
+ [DataContract]
public class Component : IComponentModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
[Required]
public string ComponentName { get; private set; } = string.Empty;
+ [DataMember]
[Required]
public double Cost { get; set; }
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Implementer.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Implementer.cs
index f6176d2..27e44a2 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Implementer.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Implementer.cs
@@ -8,18 +8,29 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Runtime.Serialization;
namespace AircraftPlantDatabaseImplement.Models
{
+ [DataContract]
public class Implementer : IImplementerModel
{
+ [DataMember]
public int Id { get; private set; }
+
+ [DataMember]
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
+
+ [DataMember]
[Required]
public string Password { get; private set; } = string.Empty;
+
+ [DataMember]
[Required]
public int WorkExperience { get; private set; }
+
+ [DataMember]
[Required]
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")]
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
index 3ca7d5e..a7bff10 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
@@ -4,7 +4,9 @@ using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
@@ -12,16 +14,30 @@ namespace AircraftPlantDatabaseImplement.Models
{
public class Message : IMessageInfoModel
{
+ [NotMapped]
+ public int Id { get; private set; }
+
+ [DataMember]
[Key]
public string MessageId { get; set; } = string.Empty;
+
+ [DataMember]
public int? ClientId { get; set; }
public virtual Client? Client { get; set; }
+
+ [DataMember]
[Required]
public string SenderName { get; set; } = string.Empty;
+
+ [DataMember]
[Required]
public DateTime DateDelivery { get; set; }
+
+ [DataMember]
[Required]
public string Subject { get; set; } = string.Empty;
+
+ [DataMember]
[Required]
public string Body { get; set; } = string.Empty;
public static Message? Create(MessageInfoBindingModel model)
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs
index fe4a767..37bff52 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs
@@ -3,39 +3,51 @@ using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
+using System.Runtime.Serialization;
namespace AircraftPlantDatabaseImplement.Models
{
+ [DataContract]
public class Order : IOrderModel
{
+ [DataMember]
public int Id { get; set; }
+ [DataMember]
[Required]
public int PlaneId { get; set; }
public virtual Plane Plane { get; set; } = new();
+ [DataMember]
[Required]
public int ClientId { get; set; }
+ [DataMember]
public Client Client { get; set; } = new();
+ [DataMember]
public int? ImplementerId { get; set; }
public virtual Implementer? Implementer { get; set; } = new();
+ [DataMember]
[Required]
public int Count { get; set; }
+ [DataMember]
[Required]
public double Sum { get; set; }
+ [DataMember]
[Required]
public OrderStatus Status { get; set; }
+ [DataMember]
[Required]
public DateTime DateCreate { get; set; }
+ [DataMember]
public DateTime? DateImplement { get; set; }
public static Order? Create(AircraftPlantDatabase context, OrderBindingModel? model)
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Plane.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Plane.cs
index 3108c85..e317513 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Plane.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Plane.cs
@@ -8,17 +8,26 @@ using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Serialization;
namespace AircraftPlantDatabaseImplement.Models
{
+ [DataContract]
public class Plane : IPlaneModel
{
+ [DataMember]
public int Id { get; set; }
+
+ [DataMember]
[Required]
public string PlaneName { get; set; } = string.Empty;
+
+ [DataMember]
[Required]
public double Price { get; set; }
private Dictionary? _planeComponents = null;
+
+ [DataMember]
[NotMapped]
public Dictionary PlaneComponents
{
diff --git a/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj b/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
index a391d48..6b9c8fd 100644
--- a/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
+++ b/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
@@ -11,4 +11,8 @@
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantFileImplement/BackUpInfo.cs b/AircraftPlant/AircraftPlantFileImplement/BackUpInfo.cs
new file mode 100644
index 0000000..a4964b3
--- /dev/null
+++ b/AircraftPlant/AircraftPlantFileImplement/BackUpInfo.cs
@@ -0,0 +1,44 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantFileImplement
+{
+ public class BackUpInfo : IBackUpInfo
+ {
+ private readonly DataFileSingleton source;
+ private readonly PropertyInfo[] sourceProperties;
+
+ public BackUpInfo()
+ {
+ source = DataFileSingleton.GetInstance();
+ sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
+ }
+
+ public List? GetList() where T : class, new()
+ {
+ var requredType = typeof(T);
+ return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType)
+ ?.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/AircraftPlant/AircraftPlantFileImplement/Client.cs b/AircraftPlant/AircraftPlantFileImplement/Client.cs
index 9390971..06e6af7 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Client.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Client.cs
@@ -4,17 +4,23 @@ using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement
{
+ [DataContract]
public class Client : IClientModel
{
+ [DataMember]
public int Id { get; set; }
+ [DataMember]
public string ClientFIO { get; set; } = string.Empty;
+ [DataMember]
public string Email { get; set; } = string.Empty;
+ [DataMember]
public string Password { get; set; } = string.Empty;
public static Client? Create(ClientBindingModel? model)
{
diff --git a/AircraftPlant/AircraftPlantFileImplement/Component.cs b/AircraftPlant/AircraftPlantFileImplement/Component.cs
index c993102..cfdcc4c 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Component.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Component.cs
@@ -1,14 +1,19 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
+using System.Runtime.Serialization;
using System.Xml.Linq;
namespace AircraftPlantFileImplement.Models
{
+ [DataContract]
public class Component : IComponentModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ComponentName { get; private set; } = string.Empty;
+ [DataMember]
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model)
{
@@ -32,8 +37,8 @@ namespace AircraftPlantFileImplement.Models
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
- ComponentName = element.Element("ComponentName")!.Value,
- Cost = Convert.ToDouble(element.Element("Cost")!.Value)
+ ComponentName = element.Element("Компонент")!.Value,
+ Cost = Convert.ToDouble(element.Element("Стоимость")!.Value)
};
}
public void Update(ComponentBindingModel model)
@@ -53,7 +58,7 @@ namespace AircraftPlantFileImplement.Models
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
- new XElement("ComponentName", ComponentName),
- new XElement("Cost", Cost.ToString()));
+ new XElement("Компонент", ComponentName),
+ new XElement("Стоимость", Cost.ToString()));
}
}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantFileImplement/ImplementationExtension.cs b/AircraftPlant/AircraftPlantFileImplement/ImplementationExtension.cs
new file mode 100644
index 0000000..896f802
--- /dev/null
+++ b/AircraftPlant/AircraftPlantFileImplement/ImplementationExtension.cs
@@ -0,0 +1,27 @@
+using AircraftPlantContracts.DI;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantFileImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantFileImplement
+{
+ public class ImplementationExtension : 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/AircraftPlant/AircraftPlantFileImplement/Implementer.cs b/AircraftPlant/AircraftPlantFileImplement/Implementer.cs
index 3755ba8..22bf9a5 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Implementer.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Implementer.cs
@@ -4,18 +4,25 @@ using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement
{
+ [DataContract]
public class Implementer : IImplementerModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
+ [DataMember]
public string Password { get; private set; } = string.Empty;
+ [DataMember]
public int WorkExperience { get; private set; }
+ [DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel? model)
{
diff --git a/AircraftPlant/AircraftPlantFileImplement/Message.cs b/AircraftPlant/AircraftPlantFileImplement/Message.cs
index a1e933e..194e2fe 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Message.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Message.cs
@@ -4,19 +4,29 @@ using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement
{
+ [DataContract]
public class Message : IMessageInfoModel
{
+ [DataMember]
+ public int Id { get; private set; }
+ [DataMember]
public string MessageId { get; set; } = string.Empty;
+ [DataMember]
public int? ClientId { get; set; }
+ [DataMember]
public string SenderName { get; set; } = string.Empty;
+ [DataMember]
public DateTime DateDelivery { get; set; }
+ [DataMember]
public string Subject { get; set; } = string.Empty;
+ [DataMember]
public string Body { get; set; } = string.Empty;
public static Message? Create(MessageInfoBindingModel model)
{
diff --git a/AircraftPlant/AircraftPlantFileImplement/Order.cs b/AircraftPlant/AircraftPlantFileImplement/Order.cs
index bf3af81..7705784 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Order.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Order.cs
@@ -5,22 +5,33 @@ using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement.Models
{
+ [DataContract]
public class Order : IOrderModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public int PlaneId { get; private set; }
+ [DataMember]
public int ClientId { get; private set; }
+ [DataMember]
public int? ImplementerId { get; private set; }
+ [DataMember]
public int Count { get; private set; }
+ [DataMember]
public double Sum { get; private set; }
+ [DataMember]
public OrderStatus Status { get; private set; }
+ [DataMember]
public DateTime DateCreate { get; private set; }
+ [DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
diff --git a/AircraftPlant/AircraftPlantFileImplement/Plane.cs b/AircraftPlant/AircraftPlantFileImplement/Plane.cs
index 6bf45c0..7119cf3 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Plane.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Plane.cs
@@ -7,17 +7,22 @@ using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System.Xml.Linq;
+using System.Runtime.Serialization;
namespace AircraftPlantFileImplement.Models
{
+ [DataContract]
public class Plane : IPlaneModel
{
+ [DataMember]
public int Id { get; private set; }
+ [DataMember]
public string PlaneName { get; private set; } = string.Empty;
+ [DataMember]
public double Price { get; private set; }
public Dictionary Components { get; private set; } = new();
- private Dictionary? _planeComponents =
- null;
+ private Dictionary? _planeComponents = null;
+ [DataMember]
public Dictionary PlaneComponents
{
get
diff --git a/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs b/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs
new file mode 100644
index 0000000..12db033
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs
@@ -0,0 +1,55 @@
+using AircraftPlantContracts.Attributes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantView
+{
+ 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/AircraftPlant/AircraftPlantView/FormClients.cs b/AircraftPlant/AircraftPlantView/FormClients.cs
index 6dfdea3..45121b9 100644
--- a/AircraftPlant/AircraftPlantView/FormClients.cs
+++ b/AircraftPlant/AircraftPlantView/FormClients.cs
@@ -65,14 +65,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridViewClients.DataSource = list;
- dataGridViewClients.Columns["Id"].Visible = false;
- dataGridViewClients.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridViewClients.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridViewClients.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormComponents.cs b/AircraftPlant/AircraftPlantView/FormComponents.cs
index d3d16c5..cabfd48 100644
--- a/AircraftPlant/AircraftPlantView/FormComponents.cs
+++ b/AircraftPlant/AircraftPlantView/FormComponents.cs
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DI;
using Microsoft.Extensions.Logging;
namespace AircraftPlantView
@@ -51,30 +52,22 @@ namespace AircraftPlantView
}
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 (dataGridViewComponents.SelectedRows.Count == 1)
{
- var service =
- Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var form = DependencyManager.Instance.Resolve();
+
+ form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id =
- Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
diff --git a/AircraftPlant/AircraftPlantView/FormImplementers.cs b/AircraftPlant/AircraftPlantView/FormImplementers.cs
index a176361..d506599 100644
--- a/AircraftPlant/AircraftPlantView/FormImplementers.cs
+++ b/AircraftPlant/AircraftPlantView/FormImplementers.cs
@@ -85,13 +85,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridViewImplementers.DataSource = list;
- dataGridViewImplementers.Columns["Id"].Visible = false;
- dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridViewImplementers.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка списка исполнителей");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormMails.cs b/AircraftPlant/AircraftPlantView/FormMails.cs
index 3b44bd0..08e1b03 100644
--- a/AircraftPlant/AircraftPlantView/FormMails.cs
+++ b/AircraftPlant/AircraftPlantView/FormMails.cs
@@ -57,14 +57,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["MessageId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка писем");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
index 6540ec9..6ea4431 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
@@ -1,4 +1,5 @@
-namespace AircraftPlantView
+
+namespace AircraftPlantView
{
partial class FormMain
{
@@ -44,6 +45,7 @@
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem();
почтаToolStripMenuItem = new ToolStripMenuItem();
+ создатьБекапToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@@ -105,7 +107,7 @@
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
- menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem });
+ menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem, создатьБекапToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
@@ -190,6 +192,13 @@
почтаToolStripMenuItem.Text = "Почта";
почтаToolStripMenuItem.Click += ПочтаToolStripMenuItem_Click;
//
+ // создатьБекапToolStripMenuItem
+ //
+ создатьБекапToolStripMenuItem.Name = "cоздатьБекапToolStripMenuItem";
+ создатьБекапToolStripMenuItem.Size = new Size(123, 24);
+ создатьБекапToolStripMenuItem.Text = "Создать бекап";
+ создатьБекапToolStripMenuItem.Click += CоздатьБекапToolStripMenuItem_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -230,5 +239,6 @@
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem почтаToolStripMenuItem;
+ private ToolStripMenuItem создатьБекапToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs
index 0c1dd7a..9523055 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.cs
@@ -1,6 +1,7 @@
using AircraftPlantBusinessLogic.BusinessLogics;
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -35,18 +36,21 @@ namespace AircraftPlantView
/// Имитация деятельности исполнителей
///
private readonly IWorkProcess _workProcess;
+
+ private readonly IBackUpLogic _backUpLogic;
///
/// Конструктор
///
///
///
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
+ _backUpLogic = backUpLogic;
}
///
/// Загрузка списка заказов
@@ -64,11 +68,8 @@ namespace AircraftPlantView
///
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
- if (service is FormComponents form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
/// Показать список всех изделий
@@ -77,11 +78,8 @@ namespace AircraftPlantView
///
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlanes));
- if (service is FormPlanes form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
/// Показать список всех клиентов
@@ -90,11 +88,8 @@ namespace AircraftPlantView
///
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormClients));
- if (service is FormClients form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -104,11 +99,8 @@ namespace AircraftPlantView
///
private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
- if (service is FormImplementers form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -118,7 +110,7 @@ namespace AircraftPlantView
///
private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
- _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic )) as IImplementerLogic)!, _orderLogic);
+ _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@@ -129,11 +121,8 @@ namespace AircraftPlantView
///
private void ПочтаToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormMails));
- if (service is FormMails form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -143,13 +132,34 @@ namespace AircraftPlantView
///
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
- if (service is FormCreateOrder form)
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
+ }
+
+ private void CоздатьБекапToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ try
{
- form.ShowDialog();
- LoadData();
+ if (_backUpLogic != null)
+ {
+ var fbd = new FolderBrowserDialog();
+ if (fbd.ShowDialog() == DialogResult.OK)
+ {
+ _backUpLogic.CreateBackUp(new BackUpSaveBindingModel
+ {
+ FolderName = fbd.SelectedPath
+ });
+ MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
+
///
/// Кнопка "Заказ выдан"
///
@@ -195,15 +205,7 @@ namespace AircraftPlantView
_logger.LogInformation("Загрузка заказов");
try
{
- var list = _orderLogic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["PlaneName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridView.Columns["PlaneId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["ImplementerId"].Visible = false;
- }
+ dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
@@ -224,20 +226,14 @@ namespace AircraftPlantView
private void КомпонентыПоСамолётамToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportPlaneComponents));
- if (service is FormReportPlaneComponents form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
private void СписокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
- if (service is FormReportOrders form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
}
diff --git a/AircraftPlant/AircraftPlantView/FormPlane.cs b/AircraftPlant/AircraftPlantView/FormPlane.cs
index ca07dc0..bd6de85 100644
--- a/AircraftPlant/AircraftPlantView/FormPlane.cs
+++ b/AircraftPlant/AircraftPlantView/FormPlane.cs
@@ -1,6 +1,8 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DI;
using AircraftPlantContracts.SearchModels;
+using AircraftPlantDatabaseImplement.Models;
using AircraftPlantDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
@@ -84,27 +86,22 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlaneComponent));
- if (service is FormPlaneComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- if (form.ComponentModel == null)
- {
- return;
- }
- _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
- if (_planeComponents.ContainsKey(form.Id))
- {
- _planeComponents[form.Id] = (form.ComponentModel, form.Count);
- }
- else
- {
- _planeComponents.Add(form.Id, (form.ComponentModel, form.Count));
- }
- LoadData();
- }
+ return;
}
+ _logger.LogInformation("Добавление нового компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_planeComponents.ContainsKey(form.Id))
+ {
+ _planeComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _planeComponents.Add(form.Id, (form.ComponentModel,
+ form.Count));
+ }
+ LoadData();
}
///
/// Кнопка "Изменить"
@@ -115,22 +112,19 @@ namespace AircraftPlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlaneComponent));
- if (service is FormPlaneComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _planeComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
- form.Id = id;
- form.Count = _planeComponents[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);
- _planeComponents[form.Id] = (form.ComponentModel, form.Count);
- LoadData();
+ return;
}
+ _logger.LogInformation("Изменение компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
+ _planeComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
}
}
}
diff --git a/AircraftPlant/AircraftPlantView/FormPlanes.cs b/AircraftPlant/AircraftPlantView/FormPlanes.cs
index 9c3d5ca..88233db 100644
--- a/AircraftPlant/AircraftPlantView/FormPlanes.cs
+++ b/AircraftPlant/AircraftPlantView/FormPlanes.cs
@@ -1,5 +1,6 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DI;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -55,13 +56,10 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlane));
- if (service is FormPlane form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
///
@@ -73,14 +71,11 @@ namespace AircraftPlantView
{
if (dataGridViewPlanes.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlane));
- if (service is FormPlane form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridViewPlanes.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridViewPlanes.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
@@ -132,14 +127,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridViewPlanes.DataSource = list;
- dataGridViewPlanes.Columns["Id"].Visible = false;
- dataGridViewPlanes.Columns["PlaneName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridViewPlanes.Columns["PlaneComponents"].Visible = false;
- }
+ dataGridViewPlanes.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка изделий");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/Program.cs b/AircraftPlant/AircraftPlantView/Program.cs
index ea40c46..fc5efe4 100644
--- a/AircraftPlant/AircraftPlantView/Program.cs
+++ b/AircraftPlant/AircraftPlantView/Program.cs
@@ -10,6 +10,7 @@ using NLog.Extensions.Logging;
using System;
using AircraftPlantBusinessLogic.MailWorker;
using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.DI;
namespace AircraftPlantView
{
@@ -31,14 +32,11 @@ namespace AircraftPlantView
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- var services = new ServiceCollection();
- ConfigureServices(services);
- _serviceProvider = services.BuildServiceProvider();
+ InitDependency();
try
{
- var mailSender =
- _serviceProvider.GetService();
+ var mailSender = DependencyManager.Instance.Resolve();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@@ -53,63 +51,58 @@ namespace AircraftPlantView
}
catch (Exception ex)
{
- var logger = _serviceProvider.GetService();
+ var logger = DependencyManager.Instance.Resolve();
logger?.LogError(ex, " ");
}
- Application.Run(_serviceProvider.GetRequiredService());
+ Application.Run(DependencyManager.Instance.Resolve());
}
///
/// IoC-
///
///
- private static void ConfigureServices(ServiceCollection services)
+ private static void InitDependency()
{
- services.AddLogging(option =>
+ DependencyManager.InitDependency();
+
+ DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ 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(true);
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ DependencyManager.Instance.RegisterType();
- services.AddTransient();
- services.AddSingleton();
-
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
-
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
}
- private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck();
+ private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck();
}
}
\ No newline at end of file