L8 to LC8

This commit is contained in:
Timourka 2024-05-16 08:40:19 +04:00
commit 3bb2a7548c
58 changed files with 1506 additions and 909 deletions

View File

@ -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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantShopApp", "AutomobilePlantShopApp\AutomobilePlantShopApp.csproj", "{0FC4B81C-8B2D-466F-AE81-8740C6B39817}"
EndProject

View File

@ -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<BackUpLogic> 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<T>(string folderName) where T : class, new()
{
var records = _backUpInfo.GetList<T>();
if (records == null)
{
_logger.LogWarning("{type} type get null list", typeof(T).Name);
return;
}
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
jsonFormatter.WriteObject(fs, records);
}
}
}

View File

@ -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; }
}
}

View File

@ -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
}
}

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutomobilePlantDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup>

View File

@ -0,0 +1,7 @@
namespace AutomobilePlantContracts.BindingModels
{
public class BackUpSaveBinidngModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

@ -17,5 +17,8 @@ namespace AutomobilePlantContracts.BindingModels
public string Body { get; set; } = string.Empty;
public bool IsReaded { get; set; }
public string? Reply { get; set; }
}
public int Id => throw new NotImplementedException();
}
}

View File

@ -0,0 +1,9 @@
using AutomobilePlantContracts.BindingModels;
namespace AutomobilePlantContracts.BusinessLogicsContracts
{
public interface IBackUpLogic
{
void CreateBackUp(BackUpSaveBinidngModel model);
}
}

View File

@ -0,0 +1,63 @@
using Microsoft.Extensions.Logging;
namespace AutomobilePlantContracts.DI
{
/// <summary>
/// Менеджер для работы с зависимостями
/// </summary>
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; } }
/// <summary>
/// Иницализация библиотек, в которых идут установки зависомстей
/// </summary>
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
// регистрируем зависимости
ext.RegisterServices();
}
/// <summary>
/// Регистрация логгера
/// </summary>
/// <param name="configure"></param>
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
/// <summary>
/// Добавление зависимости
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
/// <summary>
/// Добавление зависимости
/// </summary>
/// <typeparam name="T"></typeparam>
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
/// <summary>
/// Получение класса со всеми зависмостями
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T Resolve<T>() => _dependencyManager.Resolve<T>();
}
}

View File

@ -0,0 +1,38 @@
using Microsoft.Extensions.Logging;
namespace AutomobilePlantContracts.DI
{
/// <summary>
/// Интерфейс установки зависмости между элементами
/// </summary>
public interface IDependencyContainer
{
/// <summary>
/// Регистрация логгера
/// </summary>
/// <param name="configure"></param>
void AddLogging(Action<ILoggingBuilder> configure);
/// <summary>
/// Добавление зависимости
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
/// <param name="isSingle"></param>
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
/// <summary>
/// Добавление зависимости
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="isSingle"></param>
void RegisterType<T>(bool isSingle) where T : class;
/// <summary>
/// Получение класса со всеми зависмостями
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
T Resolve<T>();
}
}

View File

@ -0,0 +1,14 @@
namespace AutomobilePlantContracts.DI
{
/// <summary>
/// Интерфейс для регистрации зависимостей в модулях
/// </summary>
public interface IImplementationExtension
{
public int Priority { get; }
/// <summary>
/// Регистрация сервисов
/// </summary>
public void RegisterServices();
}
}

View File

@ -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<ILoggingBuilder> configure)
{
_serviceCollection.AddLogging(configure);
}
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T, U>();
}
else
{
_serviceCollection.AddTransient<T, U>();
}
_serviceProvider = null;
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T>();
}
else
{
_serviceCollection.AddTransient<T>();
}
_serviceProvider = null;
}
public T Resolve<T>()
{
if (_serviceProvider == null)
{
_serviceProvider = _serviceCollection.BuildServiceProvider();
}
return _serviceProvider.GetService<T>()!;
}
}
}

View File

@ -0,0 +1,53 @@
using System.Reflection;
namespace AutomobilePlantContracts.DI
{
/// <summary>
/// Загрузчик данных
/// </summary>
public class ServiceProviderLoader
{
/// <summary>
/// Загрузка всех классов-реализаций IImplementationExtension
/// </summary>
/// <returns></returns>
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";
}
}
}

View File

@ -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<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}
}

View File

@ -0,0 +1,8 @@
namespace AutomobilePlantContracts.StoragesContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -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
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Car's name")]
[Column("Car's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string CarName { get; set; } = string.Empty;
[DisplayName("Price")]
[Column("Price", width: 100)]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> CarComponents
{
get;
set;
} = new();
[Column(visible: false)]
public Dictionary<int, (IComponentModel, int)> CarComponents { get; set; } = new();
}
}

View File

@ -1,16 +1,17 @@
using AutomobilePlantDataModels.Models;
using System.ComponentModel;
using AutomobilePlantContracts.Attributes;
using AutomobilePlantDataModels.Models;
namespace AutomobilePlantContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Client's FIO")]
[Column(title: "Client's FIO", width: 150)]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Login (Email)")]
[Column(title: "Login (Email)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Email { get; set; } = string.Empty;
[DisplayName("Password")]
[Column(title: "Password", width: 150)]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -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
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Component's name")]
[Column("Component's name", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Cost")]
[Column("Cost", width: 100)]
public double Cost { get; set; }
}
}

View File

@ -1,22 +1,23 @@
using AutomobilePlantDataModels.Models;
using System.ComponentModel;
using AutomobilePlantContracts.Attributes;
using AutomobilePlantDataModels.Models;
namespace AutomobilePlantContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("FIO")]
[Column("FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Password")]
[Column("Password", width: 150)]
public string Password { get; set; } = string.Empty;
[DisplayName("Work expirience")]
[Column("Work expirience", width: 150)]
public int WorkExperience { get; set; }
[DisplayName("Qualification")]
[Column("Qualification", width: 150)]
public int Qualification { get; set; }
}
}

View File

@ -1,24 +1,29 @@
using AutomobilePlantDataModels.Models;
using System.ComponentModel;
using AutomobilePlantContracts.Attributes;
using AutomobilePlantDataModels.Models;
namespace AutomobilePlantContracts.ViewModels
{
public class MessageInfoViewModel : IMessageInfoModel
{
[Column(visible: false)]
public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public int? ClientId { get; set; }
[DisplayName("Sender")]
[Column("Sender", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
public string SenderName { get; set; } = string.Empty;
[DisplayName("Delivery Date")]
[Column("Delivery Date", width: 100)]
public DateTime DateDelivery { get; set; }
[DisplayName("Subject")]
[Column("Subject", width: 150)]
public string Subject { get; set; } = string.Empty;
[DisplayName("Body")]
[Column("Body", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty;
[DisplayName("Readed")]
[Column(visible: false)]
public int Id => throw new NotImplementedException();
[Column("Readed", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
public bool IsReaded { get; set; }
[DisplayName("Reply")]
[Column("Reply", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
public string? Reply { get; set; }
}
}

View File

@ -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")]
[Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Id { get; set; }
[Column(visible: false)]
public int CarId { get; set; }
[DisplayName("Car's name")]
[Column("Car's name", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string CarName { get; set; } = string.Empty;
[Column(visible: false)]
public int ClientId { get; set; }
[DisplayName("Client's FIO")]
[Column("Client's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty;
[Column(visible: false)]
public int? ImplementerId { get; set; }
[DisplayName("Implementer's FIO")]
[Column("Implementer's FIO", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Count")]
[Column("Count", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Count { get; set; }
[DisplayName("Sum")]
[Column("Sum", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public double Sum { get; set; }
[DisplayName("Status")]
[Column("Status", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Date of creation")]
[Column("Date of creation", width: 100)]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Date of completion")]
[Column("Date of completion", width: 100)]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -1,6 +1,6 @@
namespace AutomobilePlantDataModels.Models
{
public interface IMessageInfoModel
public interface IMessageInfoModel : IId
{
string MessageId { get; }
int? ClientId { get; }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -20,4 +20,8 @@
</PackageReference>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -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<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,27 @@
using AutomobilePlantContracts.StoragesContracts;
namespace AutomobilePlantDatabaseImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new AutomobilePlantDatabase();
return context.Set<T>().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;
}
}
}

View File

@ -3,19 +3,25 @@ using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace AutomobilePlantDatabaseImplement.Models
{
[DataContract]
public class Car : ICarModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string CarName { get; private set; } = string.Empty;
[Required]
[DataMember]
public double Price { get; private set; }
private Dictionary<int, (IComponentModel, int)>? _carComponents = null;
[NotMapped]
[DataMember]
public Dictionary<int, (IComponentModel, int)> CarComponents
{
get

View File

@ -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
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
[Required]
[DataMember]
public string Email { get; private set; } = string.Empty;
[Required]
[DataMember]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]

View File

@ -3,16 +3,21 @@ using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace AutomobilePlantDatabaseImplement.Models
{
[DataContract]
public class Component : IComponentModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string ComponentName { get; private set; } = string.Empty;
[Required]
[DataMember]
public double Cost { get; set; }
[ForeignKey("ComponentId")]

View File

@ -2,19 +2,22 @@
using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace AutomobilePlantDatabaseImplement.Models
{
[DataContract]
public class Implementer : IImplementerModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")]

View File

@ -2,24 +2,36 @@
using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace AutomobilePlantDatabaseImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
[DataMember]
public bool IsReaded { get; private set; }
[DataMember]
public string? Reply { get; private set; }
public virtual Client? Client { get; private set; }
@ -64,5 +76,7 @@ namespace AutomobilePlantDatabaseImplement.Models
Reply = Reply,
IsReaded = IsReaded,
};
public int Id => throw new NotImplementedException();
}
}

View File

@ -7,28 +7,39 @@ 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
{
[DataContract]
public class Order : IOrderModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public int CarId { get; private set; }
[Required]
[DataMember]
public int ClientId { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; }
[Required]
[DataMember]
public int Count { get; private set; }
[Required]
[DataMember]
public double Sum { get; private set; }
[Required]
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
[DataMember]
public DateTime? DateImplement { get; private set; }
public virtual Car Car { get; private set; }
public virtual Client Client { get; set; }

View File

@ -11,4 +11,8 @@
<ProjectReference Include="..\AutomobilePlantDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -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<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,28 @@
using AutomobilePlantContracts.StoragesContracts;
namespace AutomobilePlantFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataFileSingleton.GetInstance();
return (List<T>?)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;
}
}
}

View File

@ -1,26 +1,27 @@
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
{
[DataContract]
public class Car : ICarModel
{
[DataMember]
public string CarName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
[DataMember]
public int Id { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _carComponents = null;
[DataMember]
public Dictionary<int, (IComponentModel, int)> CarComponents
{
get

View File

@ -1,18 +1,24 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace AutomobilePlantFileImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)

View File

@ -1,19 +1,19 @@
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
{
[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)

View File

@ -1,20 +1,27 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace AutomobilePlantFileImplement.Models
{
[DataContract]
public class Implementer : IImplementerModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(XElement element)

View File

@ -1,22 +1,30 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels;
using AutomobilePlantDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace AutomobilePlantFileImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
public bool IsReaded { get; private set; }
@ -93,5 +101,7 @@ namespace AutomobilePlantFileImplement.Models
new XAttribute("Reply", Reply),
new XAttribute("HasRead", IsReaded)
);
public int Id => throw new NotImplementedException();
}
}

View File

@ -2,25 +2,31 @@
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
{
[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)

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -11,4 +11,8 @@
<ProjectReference Include="..\AutomobilePlantDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -0,0 +1,17 @@
using AutomobilePlantContracts.StoragesContracts;
namespace AutomobilePlantListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}

View File

@ -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<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ICarStorage, CarStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -62,5 +62,7 @@ namespace AutomobilePlantListImplement.Models
Reply = Reply,
IsReaded = IsReaded,
};
public int Id => throw new NotImplementedException();
}
}

View File

@ -0,0 +1,45 @@
using AutomobilePlantContracts.Attributes;
namespace AutomobilePlantView
{
public static class DataGridViewExtension
{
public static void FillAndConfigGrid<T>(this DataGridView grid, List<T>? 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;
}
}
}
}
}
}

View File

@ -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,9 +72,7 @@ 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<FormCarComponent>();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
@ -101,14 +91,11 @@ namespace AutomobilePlantView
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<FormCarComponent>();
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _carComponents[id].Item2;
@ -124,7 +111,6 @@ namespace AutomobilePlantView
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)

View File

@ -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,15 +24,8 @@ 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)
{
@ -51,22 +35,17 @@ 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<FormCar>();
if (form.ShowDialog() == DialogResult.OK)
{
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<FormCar>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
@ -74,7 +53,6 @@ namespace AutomobilePlantView
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)

View File

@ -24,13 +24,7 @@ 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;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)

View File

@ -1,5 +1,6 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
using Microsoft.Extensions.Logging;
namespace AutomobilePlantView
@ -22,13 +23,7 @@ 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;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
@ -39,22 +34,17 @@ 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<FormComponent>();
if (form.ShowDialog() == DialogResult.OK)
{
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<FormComponent>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
@ -62,7 +52,6 @@ namespace AutomobilePlantView
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)

View File

@ -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,13 +24,7 @@ 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;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
@ -51,23 +37,18 @@ 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<FormImplementer>();
if (form.ShowDialog() == DialogResult.OK)
{
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<FormImplementer>();
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
@ -75,7 +56,6 @@ namespace AutomobilePlantView
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{

View File

@ -19,24 +19,13 @@ namespace AutomobilePlantView
{
try
{
var list = _logic.ReadList(new()
{
Page = ((int)numericUpDownPage.Value),
PageSize = ((int)numericUpDownPageSize.Value),
});
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка писем");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки писем");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBox.Show(ex.Message, "Eror", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

View File

@ -37,55 +37,33 @@
sellCarsToolStripMenuItem = 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();
shopsListToolStripMenuItem = new ToolStripMenuItem();
storeCongestionToolStripMenuItem = new ToolStripMenuItem();
listOdOrdersByDatesToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonIssuedOrder = new Button();
buttonRefresh = new Button();
shopsListToolStripMenuItem = new ToolStripMenuItem();
storeCongestionToolStripMenuItem = new ToolStripMenuItem();
listOdOrdersByDatesToolStripMenuItem = new ToolStripMenuItem();
clientsToolStripMenuItem = new ToolStripMenuItem();
startWorkingsToolStripMenuItem = new ToolStripMenuItem();
mailsToolStripMenuItem = new ToolStripMenuItem();
createBackupToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs, reportsToolStripMenuItem, startWorkingsToolStripMenuItem });
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, shopsToolStripMenuItem, shopsSupplyToolStripMenuItem, sellCarsToolStripMenuItem, 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;
//
// shopsToolStripMenuItem
//
shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
@ -107,23 +85,51 @@
sellCarsToolStripMenuItem.Text = "Sell Cars";
sellCarsToolStripMenuItem.Click += sellCarsToolStripMenuItem_Click;
//
// 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(180, 22);
clientsToolStripMenuItem.Size = new Size(147, 22);
clientsToolStripMenuItem.Text = "Clients";
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
//
// implementersToolStripMenuItem
//
implementersToolStripMenuItem.Name = "implementersToolStripMenuItem";
implementersToolStripMenuItem.Size = new Size(180, 22);
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, shopsListToolStripMenuItem, storeCongestionToolStripMenuItem, listOdOrdersByDatesToolStripMenuItem });
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem });
reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
reportsToolStripMenuItem.Size = new Size(59, 20);
reportsToolStripMenuItem.Text = "Reports";
@ -216,14 +222,12 @@
listOdOrdersByDatesToolStripMenuItem.Text = "List od orders by dates";
listOdOrdersByDatesToolStripMenuItem.Click += listOdOrdersByDatesToolStripMenuItem_Click;
//
// clientsToolStripMenuItem
// startWorkingsToolStripMenuItem
// mailsToolStripMenuItem
// createBackupToolStripMenuItem
//
mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
mailsToolStripMenuItem.Size = new Size(180, 22);
mailsToolStripMenuItem.Text = "mails";
mailsToolStripMenuItem.Click += mailsToolStripMenuItem_Click;
createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem";
createBackupToolStripMenuItem.Size = new Size(95, 20);
createBackupToolStripMenuItem.Text = "Create backup";
createBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click;
//
// FormMain
//
@ -269,5 +273,6 @@
private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem startWorkingsToolStripMenuItem;
private ToolStripMenuItem mailsToolStripMenuItem;
private ToolStripMenuItem createBackupToolStripMenuItem;
}
}

View File

@ -1,5 +1,6 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.DI;
using AutomobilePlantDataModels.Enums;
using Microsoft.Extensions.Logging;
@ -11,13 +12,15 @@ namespace AutomobilePlantView
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> 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)
{
@ -28,15 +31,7 @@ namespace AutomobilePlantView
_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;
}
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
@ -45,24 +40,17 @@ namespace AutomobilePlantView
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)
{
var form = DependencyManager.Instance.Resolve<FormComponents>();
form.ShowDialog();
}
}
private void CarsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCars));
if (service is FormCars form)
{
var form = DependencyManager.Instance.Resolve<FormCars>();
form.ShowDialog();
}
}
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
@ -71,6 +59,7 @@ namespace AutomobilePlantView
form.ShowDialog();
}
}
private void shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
@ -82,30 +71,21 @@ namespace AutomobilePlantView
private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
var form = DependencyManager.Instance.Resolve<FormClients>();
form.ShowDialog();
}
}
private void implementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
var form = DependencyManager.Instance.Resolve<FormImplementers>();
form.ShowDialog();
}
}
private void mailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
if (service is FormMails form)
{
var form = DependencyManager.Instance.Resolve<FormMails>();
form.ShowDialog();
}
}
private void carsListToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -122,21 +102,15 @@ namespace AutomobilePlantView
private void componentsByCarsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportCarComponents));
if (service is FormReportCarComponents form)
{
var form = DependencyManager.Instance.Resolve<FormReportCarComponents>();
form.ShowDialog();
}
}
private void ordersListToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
form.ShowDialog();
}
}
private void sellCarsToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -171,7 +145,7 @@ namespace AutomobilePlantView
private void startWorkingsToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@ -184,16 +158,35 @@ namespace AutomobilePlantView
}
}
// управление заказами
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)
{
var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
form.ShowDialog();
LoadData();
}
}
private OrderBindingModel CreateBindingModel(int id)
{
return new OrderBindingModel
@ -278,7 +271,6 @@ namespace AutomobilePlantView
{
LoadData();
}
}
}

View File

@ -9,13 +9,12 @@ 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;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -25,13 +24,11 @@ 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<AbstractMailWorker>();
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@ -46,60 +43,56 @@ namespace AutomobilePlantView
}
catch (Exception ex)
{
var logger = _serviceProvider.GetService<ILogger>();
var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Ошибка работы с почтой");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
private static void ConfigureServices(ServiceCollection services)
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
private static void InitDependency()
{
services.AddLogging(option =>
DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ICarStorage, CarStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ICarLogic, CarLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormCar>();
services.AddTransient<FormCarComponent>();
services.AddTransient<FormCars>();
services.AddTransient<FormReportCarComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormReportShopCars>();
services.AddTransient<FormReportDateOrders>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormShopSupply>();
services.AddTransient<FormShopSell>();
services.AddTransient<FormClients>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormMails>();
services.AddTransient<FormMail>();
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ICarLogic, CarLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormComponent>();
DependencyManager.Instance.RegisterType<FormComponents>();
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormCar>();
DependencyManager.Instance.RegisterType<FormCarComponent>();
DependencyManager.Instance.RegisterType<FormCars>();
DependencyManager.Instance.RegisterType<FormReportCarComponents>();
DependencyManager.Instance.RegisterType<FormReportOrders>();
DependencyManager.Instance.RegisterType<FormReportShopCars>();
DependencyManager.Instance.RegisterType<FormReportDateOrders>();
DependencyManager.Instance.RegisterType<FormClients>();
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormMails>();
DependencyManager.Instance.RegisterType<FormShop>();
DependencyManager.Instance.RegisterType<FormShops>();
DependencyManager.Instance.RegisterType<FormShopSupply>();
DependencyManager.Instance.RegisterType<FormShopSell>();
}
}
}