ПИбд-23 Волков Никита Андреевич Лабораторная работа №8 #10

Closed
bocchanskyy wants to merge 3 commits from Lab8Base into Lab7Base
93 changed files with 1685 additions and 579 deletions

View File

@ -0,0 +1,103 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.StorageContracts;
using ComputersShopDataModels;
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 ComputersShopBusinessLogic.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

@ -1,7 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;

View File

@ -1,7 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;

View File

@ -1,7 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;

View File

@ -1,7 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;

View File

@ -1,7 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;

View File

@ -2,7 +2,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Enums; using ComputersShopDataModels.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -3,7 +3,7 @@ using ComputersShopBusinessLogic.OfficePackage.HeplerModels;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.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,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.Attributes
{
public enum GridViewAutoSize
{
NotSet = 0,
None = 1,
ColumnHeader = 2,
AllCellsExceptHeader = 4,
AllCells = 6,
DisplayedCellsExceptHeader = 8,
DisplayedCells = 10,
Fill = 16
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.BindingModels
{
public class BackUpSaveBinidngModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

@ -4,15 +4,20 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ComputersShopContracts.Attributes;
using СomputersShopDataModels.Models; using СomputersShopDataModels.Models;
namespace ComputersShopContracts.BindingModels namespace ComputersShopContracts.BindingModels
{ {
public class ClientBindingModel : IClientModel public class ClientBindingModel : IClientModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Column("Логин (эл. почта)", width: 200)]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Column("Пароль", width: 200)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }
} }

View File

@ -20,5 +20,7 @@ namespace ComputersShopContracts.BindingModels
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
public int Id => throw new NotImplementedException();
} }
} }

View File

@ -0,0 +1,14 @@
using ComputersShopContracts.BindingModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.BusinessLogicContracts
{
public interface IBackUpLogic
{
void CreateBackUp(BackUpSaveBinidngModel model);
}
}

View File

@ -8,6 +8,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> <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>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.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<ILoggingBuilder> configure) =>
_dependencyManager.AddLogging(configure);
public void RegisterType<T, U>(bool isSingle = false) where U :
class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
public T Resolve<T>() => _dependencyManager.Resolve<T>();
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.DI
{
public interface IDependencyContainer
{
void AddLogging(Action<ILoggingBuilder> configure);
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
void RegisterType<T>(bool isSingle) where T : class;
T Resolve<T>();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.DI
{
public interface IImplementationExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -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 ComputersShopContracts.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,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.DI
{
public class ServiceProviderLoader
{
public static IImplementationExtension? GetImplementationExtensions()
{
IImplementationExtension? source = null;
var files =
Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll",
SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass &&
typeof(IImplementationExtension).IsAssignableFrom(t))
{
if (source == null)
{
source =
(IImplementationExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource =
(IImplementationExtension)Activator.CreateInstance(t)!;
if (newSource.Priority > source.Priority)
{
source = newSource;
}
}
}
}
}
return source;
}
private static string TryGetImplementationExtensionsFolder()
{
var directory = new
DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null &&
!directory.GetDirectories("ImplementationExtensions",
SearchOption.AllDirectories)
.Any(x => x.Name == "ImplementationExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\ImplementationExtensions";
}
}
}

View File

@ -0,0 +1,43 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Unity.Microsoft.Logging;
namespace ComputersShopContracts.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,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.StorageContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IClientStorage public interface IClientStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IComponentStorage public interface IComponentStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IComputerStorage public interface IComputerStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IImplementerStorage public interface IImplementerStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IMessageInfoStorage public interface IMessageInfoStorage
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts namespace ComputersShopContracts.StorageContracts
{ {
public interface IOrderStorage public interface IOrderStorage
{ {

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Models; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -11,15 +12,16 @@ namespace ComputersShopContracts.ViewModels
{ {
public class ClientViewModel : IClientModel public class ClientViewModel : IClientModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("ФИО клиента")] [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")] [Column("Логин (эл. почта)", width: 200)]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column("Пароль", width: 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }
} }

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Models; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,10 +11,11 @@ namespace ComputersShopContracts.ViewModels
{ {
public class ComponentViewModel : IComponentModel public class ComponentViewModel : IComponentModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название компонента")] [Column("Название комплектующего", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column("Цена", width: 100)]
public double Cost { get; set; } public double Cost { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Models; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,14 +11,15 @@ namespace ComputersShopContracts.ViewModels
{ {
public class ComputerViewModel : IComputerModel public class ComputerViewModel : IComputerModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название компьютера")] [Column("Название компьютера", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ComputerName { get; set; } = string.Empty; public string ComputerName { get; set; } = string.Empty;
[DisplayName("Цена")] [Column("Цена", width: 100)]
public double Price { get; set; } public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IComponentModel, int)> ComputerComponents public Dictionary<int, (IComponentModel, int)> ComputerComponents
{ {
get; get;

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Models; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,18 +11,19 @@ namespace ComputersShopContracts.ViewModels
{ {
public class ImplementerViewModel : IImplementerModel public class ImplementerViewModel : IImplementerModel
{ {
[Column(visible: false)]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("ФИО исполнителя")] [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")] [Column("Пароль", width: 150)]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DisplayName("Стаж работы")] [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[DisplayName("Квалификация")] [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Qualification { get; set; } public int Qualification { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Models; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,20 +11,24 @@ namespace ComputersShopContracts.ViewModels
{ {
public class MessageInfoViewModel : IMessageInfoModel public class MessageInfoViewModel : IMessageInfoModel
{ {
[Column(visible: false)]
public string MessageId { get; set; } = string.Empty; public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public int? ClientId { get; set; } public int? ClientId { get; set; }
[DisplayName("Отправитель")] [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
public string SenderName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата письма")] [Column("Дата письма", width: 100)]
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
[DisplayName("Заголовок")] [Column("Заголовок", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string Subject { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty;
[DisplayName("Текст")] [Column("Текст", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
[Column(visible: false)]
public int Id => throw new NotImplementedException();
} }
} }

View File

@ -1,4 +1,5 @@
using ComputersShopDataModels.Enums; using ComputersShopContracts.Attributes;
using ComputersShopDataModels.Enums;
using ComputersShopDataModels.Models; using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -11,27 +12,43 @@ namespace ComputersShopContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
[DisplayName("Номер")] [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Id { get; set; } public int Id { get; set; }
[Column(visible: false)]
public int ComputerId { get; set; } public int ComputerId { get; set; }
[Column(visible: false)]
public int ClientId { get; set; } public int ClientId { get; set; }
[DisplayName("Фамилия клиента")]
[Column("Данные клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Column(visible: false)]
public string ClientEmail { get; set; } = string.Empty; public string ClientEmail { get; set; } = string.Empty;
[Column(visible: false)]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[DisplayName("Исполнитель")]
[Column("Данные исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Компьютер")]
[Column("Компьютер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public string ComputerName { get; set; } = string.Empty; public string ComputerName { get; set; } = string.Empty;
[DisplayName("Количество")]
[Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")]
[Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")]
[Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")]
[Column("Дата создания", width: 100)]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
[Column("Дата выполнения", width: 100)]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
} }
} }

View File

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

View File

@ -0,0 +1,27 @@
using ComputersShopContracts.DI;
using ComputersShopContracts.StorageContracts;
using ComputersShopDataBaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement
{
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<IComputerStorage, ComputerStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,32 @@
using ComputersShopContracts.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new ComputersShopDataBase();
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

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using System; using System;

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models; using ComputersShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -0,0 +1,285 @@
// <auto-generated />
using System;
using ComputersShopDataBaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ComputersShopDataBaseImplement.Migrations
{
[DbContext(typeof(ComputersShopDataBase))]
[Migration("20240512072253_SecondMig")]
partial class SecondMig
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Computer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ComputerName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Computers");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("integer");
b.Property<int>("ComputerId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ComputerId");
b.ToTable("ComputerComponents");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b =>
{
b.Property<string>("MessageId")
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp with time zone");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("MessageId");
b.ToTable("Messages");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("ComputerId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComputerId");
b.HasIndex("ImplementerId");
b.ToTable("Orders");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
{
b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component")
.WithMany("ComputerComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
.WithMany("Components")
.HasForeignKey("ComputerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Computer");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
{
b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
.WithMany("Orders")
.HasForeignKey("ComputerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputersShopDataBaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Client");
b.Navigation("Computer");
b.Navigation("Implementer");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
{
b.Navigation("ComputerComponents");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Computer", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ComputersShopDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class SecondMig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Messages_Clients_ClientId",
table: "Messages");
migrationBuilder.DropIndex(
name: "IX_Messages_ClientId",
table: "Messages");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_Messages_ClientId",
table: "Messages",
column: "ClientId");
migrationBuilder.AddForeignKey(
name: "FK_Messages_Clients_ClientId",
table: "Messages",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id");
}
}
}

View File

@ -165,8 +165,6 @@ namespace ComputersShopDataBaseImplement.Migrations
b.HasKey("MessageId"); b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages"); b.ToTable("Messages");
}); });
@ -232,15 +230,6 @@ namespace ComputersShopDataBaseImplement.Migrations
b.Navigation("Computer"); b.Navigation("Computer");
}); });
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b =>
{
b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
{ {
b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client")
@ -268,8 +257,6 @@ namespace ComputersShopDataBaseImplement.Migrations
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{ {
b.Navigation("Messages");
b.Navigation("Orders"); b.Navigation("Orders");
}); });

View File

@ -8,21 +8,26 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.Serialization;
using СomputersShopDataModels.Models; using СomputersShopDataModels.Models;
namespace ComputersShopDataBaseImplement.Models namespace ComputersShopDataBaseImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[Required] [Required]
[DataMember]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[ForeignKey("ClientId")] [ForeignKey("ClientId")]

View File

@ -9,15 +9,20 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using System.Runtime.Serialization;
namespace ComputersShopDataBaseImplement.Models namespace ComputersShopDataBaseImplement.Models
{ {
[DataContract]
public class Component : IComponentModel public class Component : IComponentModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
[DataMember]
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Cost { get; set; } public double Cost { get; set; }
[ForeignKey("ComponentId")] [ForeignKey("ComponentId")]
public virtual List<ComputerComponent> ComputerComponents { get; set; } = new(); public virtual List<ComputerComponent> ComputerComponents { get; set; } = new();

View File

@ -8,15 +8,20 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using System.Runtime.Serialization;
namespace ComputersShopDataBaseImplement.Models namespace ComputersShopDataBaseImplement.Models
{ {
[DataContract]
public class Computer : IComputerModel public class Computer : IComputerModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string ComputerName { get; set; } = string.Empty; public string ComputerName { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public double Price { get; set; } public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _ComputerComponents = null; private Dictionary<int, (IComponentModel, int)>? _ComputerComponents = null;
[NotMapped] [NotMapped]

View File

@ -8,23 +8,30 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace ComputersShopDataBaseImplement.Models namespace ComputersShopDataBaseImplement.Models
{ {
[DataContract]
public class Implementer : IImplementerModel public class Implementer : IImplementerModel
{ {
[DataMember]
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
[DataMember]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[Required] [Required]
[DataMember]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[Required] [Required]
[DataMember]
public int Qualification { get; set; } public int Qualification { get; set; }
[ForeignKey("ImplementerId")] [ForeignKey("ImplementerId")]

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -13,6 +14,7 @@ namespace ComputersShopDataBaseImplement.Models
public class Message : IMessageInfoModel public class Message : IMessageInfoModel
{ {
[Key] [Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty; public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; } public int? ClientId { get; private set; }
@ -27,6 +29,8 @@ namespace ComputersShopDataBaseImplement.Models
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public int Id => throw new NotImplementedException();
public static Message? Create(MessageInfoBindingModel model) public static Message? Create(MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -7,27 +7,36 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement.Models namespace ComputersShopDataBaseImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[Required] [Required]
[DataMember]
public int ComputerId { get; set; } public int ComputerId { get; set; }
[Required] [Required]
[DataMember]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[DataMember]
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[Required] [Required]
[DataMember]
public int Count { get; set; } public int Count { get; set; }
[Required] [Required]
[DataMember]
public double Sum { get; set; } public double Sum { get; set; }
[Required] [Required]
[DataMember]
public OrderStatus Status { get; set; } public OrderStatus Status { get; set; }
[Required] [Required]
[DataMember]
public DateTime DateCreate { get; set; } public DateTime DateCreate { get; set; }
[DataMember]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public virtual Computer Computer { get; set; } public virtual Computer Computer { get; set; }
public virtual Client Client { get; set; } public virtual Client Client { get; set; }
@ -70,7 +79,6 @@ namespace ComputersShopDataBaseImplement.Models
ComputerId = ComputerId, ComputerId = ComputerId,
ClientId = ClientId, ClientId = ClientId,
ClientFIO = Client.ClientFIO, ClientFIO = Client.ClientFIO,
ClientEmail = Client.Email,
ImplementerId = ImplementerId, ImplementerId = ImplementerId,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
Count = Count, Count = Count,

View File

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

View File

@ -0,0 +1,27 @@
using ComputersShopContracts.DI;
using ComputersShopContracts.StorageContracts;
using ComputersShopFileImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopFileImplement
{
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<IComputerStorage, ComputerStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,35 @@
using ComputersShopContracts.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
// Получаем значения из singleton-объекта универсального свойства содержащее тип T
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,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models; using ComputersShopFileImplement.Models;
using System; using System;

View File

@ -4,6 +4,7 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
@ -11,14 +12,16 @@ using СomputersShopDataModels.Models;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Client : IClientModel public class Client : IClientModel
{ {
[DataMember]
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty; public string Email { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)

View File

@ -4,16 +4,21 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Component : IComponentModel public class Component : IComponentModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; } public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {

View File

@ -4,16 +4,21 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Computer : IComputerModel public class Computer : IComputerModel
{ {
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember]
public string ComputerName { get; private set; } = string.Empty; public string ComputerName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _ComputerComponents = null; private Dictionary<int, (IComponentModel, int)>? _ComputerComponents = null;

View File

@ -4,22 +4,25 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Implementer : IImplementerModel public class Implementer : IImplementerModel
{ {
[DataMember]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DataMember]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[DataMember]
public int WorkExperience { get; set; } public int WorkExperience { get; set; }
[DataMember]
public int Qualification { get; set; } public int Qualification { get; set; }
[DataMember]
public int Id { get; set; } public int Id { get; set; }
public static Implementer? Create(ImplementerBindingModel? model) public static Implementer? Create(ImplementerBindingModel? model)

View File

@ -4,26 +4,31 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Message : IMessageInfoModel public class Message : IMessageInfoModel
{ {
[DataMember]
public string MessageId { get; private set; } = string.Empty; public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; } public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty; public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now; public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public string Subject { get; private set; } = string.Empty; public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public int Id => throw new NotImplementedException();
public static Message? Create(MessageInfoBindingModel model) public static Message? Create(MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -5,30 +5,33 @@ using ComputersShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace ComputersShopFileImplement.Models namespace ComputersShopFileImplement.Models
{ {
[DataContract]
public class Order : IOrderModel public class Order : IOrderModel
{ {
[DataMember]
public int ComputerId { get; private set; } public int ComputerId { get; private set; }
[DataMember]
public int ClientId { get; set; } public int ClientId { get; set; }
[DataMember]
public int? ImplementerId { get; private set; } public int? ImplementerId { get; private set; }
[DataMember]
public int Count { get; private set; } public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; } public double Sum { get; private set; }
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
[DataMember]
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
[DataMember]
public int Id { get; private set; } public int Id { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)

View File

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

View File

@ -0,0 +1,22 @@
using ComputersShopContracts.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopListImplement.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

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
using System; using System;

View File

@ -1,6 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels; using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopContracts.ViewModels; using ComputersShopContracts.ViewModels;
using ComputersShopListImplement; using ComputersShopListImplement;
using ComputersShopListImplement.Models; using ComputersShopListImplement.Models;
@ -10,7 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace OrdersShopListImplement.Implements namespace ComputersShopListImplement.Implements
{ {
public class OrderStorage : IOrderStorage public class OrderStorage : IOrderStorage
{ {

View File

@ -0,0 +1,26 @@
using ComputersShopContracts.DI;
using ComputersShopContracts.StorageContracts;
using ComputersShopListImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopListImplement
{
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComputerStorage, ComputerStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -23,6 +23,8 @@ namespace ComputersShopListImplement.Models
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public int Id => throw new NotImplementedException();
public static Message? Create(MessageInfoBindingModel model) public static Message? Create(MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -2,7 +2,7 @@ using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopBusinessLogic.MailWorker; using ComputersShopBusinessLogic.MailWorker;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopDataBaseImplement.Implements; using ComputersShopDataBaseImplement.Implements;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;

View File

@ -0,0 +1,52 @@
using ComputersShopContracts.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopView
{
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

@ -35,13 +35,7 @@ namespace ComputersShopView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов"); _logger.LogInformation("Загрузка клиентов");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,5 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.DI;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging; using Microsoft.VisualBasic.Logging;
using System; using System;
@ -36,13 +37,7 @@ namespace ComputersShopView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка компонентов"); _logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
@ -54,7 +49,7 @@ namespace ComputersShopView
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var service = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (service is FormComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -68,7 +63,7 @@ namespace ComputersShopView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var service = DependencyManager.Instance.Resolve<FormComponent>();
if (service is FormComponent form) if (service is FormComponent form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -12,6 +12,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using ComputersShopContracts.DI;
namespace ComputersShopView namespace ComputersShopView
{ {
@ -81,7 +82,7 @@ namespace ComputersShopView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComputerComponent)); var service = DependencyManager.Instance.Resolve<FormComputerComponent>();
if (service is FormComputerComponent form) if (service is FormComputerComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -109,7 +110,7 @@ namespace ComputersShopView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComputerComponent)); var service = DependencyManager.Instance.Resolve<FormComputerComponent>();
if (service is FormComputerComponent form) if (service is FormComputerComponent form)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);

View File

@ -1,5 +1,6 @@
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.DI;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -34,14 +35,7 @@ namespace ComputersShopView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ComputerComponents"].Visible = false;
}
_logger.LogInformation("Загрузка компьютеров"); _logger.LogInformation("Загрузка компьютеров");
} }
catch (Exception ex) catch (Exception ex)
@ -53,7 +47,7 @@ namespace ComputersShopView
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComputer)); var service = DependencyManager.Instance.Resolve<FormComputer>();
if (service is FormComputer form) if (service is FormComputer form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -67,7 +61,7 @@ namespace ComputersShopView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComputer)); var service = DependencyManager.Instance.Resolve<FormComputer>();
if (service is FormComputer form) if (service is FormComputer form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -1,5 +1,7 @@
using ComputersShopContracts.BindingModels; using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.DI;
using ComputersShopView; using ComputersShopView;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
@ -33,16 +35,7 @@ namespace ComputersShopView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей"); _logger.LogInformation("Загрузка исполнителей");
} }
catch (Exception ex) catch (Exception ex)
@ -54,7 +47,7 @@ namespace ComputersShopView
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var service = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) if (service is FormImplementer form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -68,7 +61,7 @@ namespace ComputersShopView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); var service = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form) if (service is FormImplementer form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -1,4 +1,5 @@
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -28,14 +29,7 @@ namespace ComputersShopView
{ {
try try
{ {
var list = _logic.ReadList(null); dataGridView.FillandConfigGrid(_logic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка писем"); _logger.LogInformation("Загрузка писем");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -39,18 +39,19 @@
componentsOfComputersToolStripMenuItem = new ToolStripMenuItem(); componentsOfComputersToolStripMenuItem = new ToolStripMenuItem();
listOrderToolStripMenuItem = new ToolStripMenuItem(); listOrderToolStripMenuItem = new ToolStripMenuItem();
doWorkToolStripMenuItem = new ToolStripMenuItem(); doWorkToolStripMenuItem = new ToolStripMenuItem();
почтаToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonIssuedOrder = new Button(); buttonIssuedOrder = new Button();
buttonRef = new Button(); buttonRef = new Button();
почтаToolStripMenuItem = new ToolStripMenuItem(); CreateBackupToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout(); menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// menuStrip // menuStrip
// //
menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem, почтаToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem, почтаToolStripMenuItem, CreateBackupToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1047, 24); menuStrip.Size = new Size(1047, 24);
@ -127,6 +128,13 @@
doWorkToolStripMenuItem.Text = "Запуск работ"; doWorkToolStripMenuItem.Text = "Запуск работ";
doWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; doWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click;
// //
// почтаToolStripMenuItem
//
почтаToolStripMenuItem.Name = "почтаToolStripMenuItem";
почтаToolStripMenuItem.Size = new Size(53, 20);
почтаToolStripMenuItem.Text = "Почта";
почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click;
//
// dataGridView // dataGridView
// //
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@ -166,12 +174,12 @@
buttonRef.UseVisualStyleBackColor = true; buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click; buttonRef.Click += ButtonRef_Click;
// //
// почтаToolStripMenuItem // CreateBackupToolStripMenuItem
// //
почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; CreateBackupToolStripMenuItem.Name = "CreateBackupToolStripMenuItem";
почтаToolStripMenuItem.Size = new Size(53, 20); CreateBackupToolStripMenuItem.Size = new Size(97, 20);
почтаToolStripMenuItem.Text = "Почта"; CreateBackupToolStripMenuItem.Text = "Создать Бекап";
почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; CreateBackupToolStripMenuItem.Click += CreateBackupToolStripMenuItem_Click;
// //
// FormMain // FormMain
// //
@ -212,5 +220,6 @@
private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem doWorkToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem;
private ToolStripMenuItem почтаToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem;
private ToolStripMenuItem CreateBackupToolStripMenuItem;
} }
} }

View File

@ -1,6 +1,7 @@
using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.DI;
using ComputersShopDataModels.Enums; using ComputersShopDataModels.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
@ -21,14 +22,16 @@ namespace ComputersShopView
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess; private readonly IWorkProcess _workProcess;
private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess) public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportlogic; _reportLogic = reportlogic;
_workProcess = workProcess; _workProcess = workProcess;
_backUpLogic = backUpLogic;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
@ -40,14 +43,7 @@ namespace ComputersShopView
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
try try
{ {
var list = _orderLogic.ReadList(null); dataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ComputerId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
catch (Exception ex) catch (Exception ex)
@ -58,7 +54,7 @@ namespace ComputersShopView
} }
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var service = DependencyManager.Instance.Resolve<FormComponents>();
if (service is FormComponents form) if (service is FormComponents form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -66,7 +62,7 @@ namespace ComputersShopView
} }
private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) private void ComputersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); var service = DependencyManager.Instance.Resolve<FormComputers>();
if (service is FormComputers form) if (service is FormComputers form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -74,7 +70,7 @@ namespace ComputersShopView
} }
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var service = DependencyManager.Instance.Resolve<FormCreateOrder>();
if (service is FormCreateOrder form) if (service is FormCreateOrder form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -186,7 +182,7 @@ namespace ComputersShopView
private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportComputerComponents)); var service = DependencyManager.Instance.Resolve<FormReportComputerComponents>();
if (service is FormReportComputerComponents form) if (service is FormReportComputerComponents form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -195,7 +191,7 @@ namespace ComputersShopView
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); var service = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form) if (service is FormReportOrders form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -204,7 +200,7 @@ namespace ComputersShopView
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormClients)); var service = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form) if (service is FormClients form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -213,7 +209,7 @@ namespace ComputersShopView
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); var service = DependencyManager.Instance.Resolve<FormImplementers>();
if (service is FormImplementers form) if (service is FormImplementers form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -222,8 +218,8 @@ namespace ComputersShopView
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
{ {
_workProcess.DoWork(( _workProcess.DoWork(
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, DependencyManager.Instance.Resolve<IImplementerLogic>(),
_orderLogic); _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
@ -231,7 +227,7 @@ namespace ComputersShopView
private void почтаToolStripMenuItem_Click(object sender, EventArgs e) private void почтаToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormMails)); var service = DependencyManager.Instance.Resolve<FormMails>();
if (service is FormMails form) if (service is FormMails form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -242,5 +238,31 @@ namespace ComputersShopView
{ {
LoadData(); LoadData();
} }
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("Бекап создан", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -2,20 +2,19 @@ using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopBusinessLogic.OfficePackage.Implements; using ComputersShopBusinessLogic.OfficePackage.Implements;
using ComputersShopBusinessLogic.OfficePackage; using ComputersShopBusinessLogic.OfficePackage;
using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.StorageContracts;
using ComputersShopDataBaseImplement.Implements; using ComputersShopDataBaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using ComputersShopBusinessLogic.MailWorker; using ComputersShopBusinessLogic.MailWorker;
using ComputersShopContracts.BindingModels; using ComputersShopContracts.BindingModels;
using ComputersShopContracts.DI;
namespace ComputersShopView namespace ComputersShopView
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
@ -25,12 +24,10 @@ namespace ComputersShopView
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection(); InitDependency();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
try try
{ {
var mailSender = _serviceProvider.GetService<AbstractMailWorker>(); var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel mailSender?.MailConfig(new MailConfigBindingModel
{ {
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@ -45,13 +42,13 @@ namespace ComputersShopView
} }
catch (Exception ex) catch (Exception ex)
{ {
var logger = _serviceProvider.GetService<ILogger>(); var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Error"); logger?.LogError(ex, "Error");
} }
Application.Run(_serviceProvider.GetRequiredService<FormMain>()); Application.Run(DependencyManager.Instance.Resolve<FormMain>());
} }
private static void ConfigureServices(ServiceCollection services) /*private static void ConfigureServices(ServiceCollection services)
{ {
services.AddLogging(option => services.AddLogging(option =>
{ {
@ -64,6 +61,7 @@ namespace ComputersShopView
services.AddTransient<IClientStorage, ClientStorage>(); services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>(); services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>(); services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IBackUpInfo, BackUpInfo>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IComputerLogic, ComputerLogic>(); services.AddTransient<IComputerLogic, ComputerLogic>();
@ -73,6 +71,7 @@ namespace ComputersShopView
services.AddTransient<IImplementerLogic, ImplementerLogic>(); services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>(); services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>(); services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IBackUpLogic, BackUpLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
@ -92,7 +91,43 @@ namespace ComputersShopView
services.AddTransient<FormImplementer>(); services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>(); services.AddTransient<FormImplementers>();
services.AddTransient<FormMails>(); services.AddTransient<FormMails>();
}*/
private static void InitDependency()
{
DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<IComputerLogic, ComputerLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormComponent>();
DependencyManager.Instance.RegisterType<FormComponents>();
DependencyManager.Instance.RegisterType<FormComputers>();
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormComputer>();
DependencyManager.Instance.RegisterType<FormComputerComponent>();
DependencyManager.Instance.RegisterType<FormReportComputerComponents>();
DependencyManager.Instance.RegisterType<FormReportOrders>();
DependencyManager.Instance.RegisterType<FormClients>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormMails>();
} }
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck(); private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ComputersShopDataModels.Models namespace ComputersShopDataModels.Models
{ {
public interface IMessageInfoModel public interface IMessageInfoModel : IId
{ {
string MessageId { get; } string MessageId { get; }