Вроде сделал.
This commit is contained in:
parent
2fdbd0aaa2
commit
8ef45fb2eb
@ -0,0 +1,103 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryDataModels.Models;
|
||||
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 ConfectioneryBusinessLogic.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(BackUpSaveBindingModel model)
|
||||
{
|
||||
if (_backUpInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("Clear folder");
|
||||
// зачистка папки и удаление старого архива
|
||||
var dirInfo = new DirectoryInfo(model.FolderName);
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
foreach (var file in dirInfo.GetFiles())
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Delete archive");
|
||||
string fileName = $"{model.FolderName}.zip";
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
// берем метод для сохранения
|
||||
_logger.LogDebug("Get assembly");
|
||||
var typeIId = typeof(IId);
|
||||
var assembly = typeIId.Assembly;
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
|
||||
}
|
||||
var types = assembly.GetTypes();
|
||||
var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
_logger.LogDebug("Find {count} types", types.Length);
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
|
||||
{
|
||||
var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
|
||||
if (modelType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Не найден класс-модель для {type.Name}");
|
||||
}
|
||||
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
|
||||
// вызываем метод на выполнение
|
||||
method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Create zip and remove folder");
|
||||
// архивируем
|
||||
ZipFile.CreateFromDirectory(model.FolderName, fileName);
|
||||
// удаляем папку
|
||||
dirInfo.Delete(true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToFile<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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.Attributes
|
||||
{
|
||||
public enum GridViewAutoSize
|
||||
{
|
||||
NotSet = 0,
|
||||
None = 1,
|
||||
ColumnHeader = 2,
|
||||
AllCellsExceptHeader = 4,
|
||||
AllCells = 6,
|
||||
DisplayedCellsExceptHeader = 8,
|
||||
DisplayedCells = 10,
|
||||
Fill = 16
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.BindingModels
|
||||
{
|
||||
public class BackUpSaveBindingModel
|
||||
{
|
||||
public string FolderName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -20,5 +20,7 @@ namespace ConfectioneryContracts.BindingModels
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IBackUpLogic
|
||||
{
|
||||
void CreateBackUp(BackUpSaveBindingModel model);
|
||||
}
|
||||
}
|
@ -6,6 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
67
Confectionery/ConfectioneryContracts/DI/DependencyManager.cs
Normal file
67
Confectionery/ConfectioneryContracts/DI/DependencyManager.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Иницализация библиотек, в которых идут установки зависомстей
|
||||
/// </summary>
|
||||
public static void InitDependency()
|
||||
{
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
}
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
/// </summary>
|
||||
/// <param name="configure"></param>
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) =>
|
||||
_dependencyManager.AddLogging(configure);
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T, U>(bool isSingle = false) where U :
|
||||
class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
public void RegisterType<T>(bool isSingle = false) where T : class =>
|
||||
_dependencyManager.RegisterType<T>(isSingle);
|
||||
/// <summary>
|
||||
/// Получение класса со всеми зависмостями
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public interface IDependencyContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
/// </summary>
|
||||
/// <param name="configure"></param>
|
||||
void AddLogging(Action<ILoggingBuilder> configure);
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
/// <param name="isSingle"></param>
|
||||
void RegisterType<T, U>(bool isSingle) where U : class, T where T :
|
||||
class;
|
||||
/// <summary>
|
||||
/// Добавление зависимости
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="isSingle"></param>
|
||||
void RegisterType<T>(bool isSingle) where T : class;
|
||||
/// <summary>
|
||||
/// Получение класса со всеми зависмостями
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
T Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public interface IImplementationExtension
|
||||
{
|
||||
public int Priority { get; }
|
||||
/// <summary>
|
||||
/// Регистрация сервисов
|
||||
/// </summary>
|
||||
public void RegisterServices();
|
||||
}
|
||||
}
|
@ -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 ConfectioneryContracts.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>()!;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.DI
|
||||
{
|
||||
public class ServiceProviderLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузка всех классов-реализаций IImplementationExtension
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IImplementationExtension? GetImplementationExtensions()
|
||||
{
|
||||
IImplementationExtension? source = null;
|
||||
var files =
|
||||
Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll",
|
||||
SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass &&
|
||||
typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source =
|
||||
(IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource =
|
||||
(IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
private static string TryGetImplementationExtensionsFolder()
|
||||
{
|
||||
var directory = new
|
||||
DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
while (directory != null &&
|
||||
!directory.GetDirectories("ImplementationExtensions",
|
||||
SearchOption.AllDirectories)
|
||||
.Any(x => x.Name == "ImplementationExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
}
|
||||
}
|
@ -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 ConfectioneryContracts.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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryContracts.StoragesContracts
|
||||
{
|
||||
public interface IBackUpInfo
|
||||
{
|
||||
List<T>? GetList<T>() where T : class, new();
|
||||
Type? GetTypeByModelInterface(string modelInterfaceName);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,12 +11,13 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Логин (эл. почта)")]
|
||||
[Column("Логин (эл. почта)", width: 150)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
[Column("Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,12 +11,13 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название компонента")]
|
||||
[Column("Название бланка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column("Цена", width: 80)]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,18 +11,19 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
[Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
[Column("Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стаж работы")]
|
||||
[Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DisplayName("Квалификация")]
|
||||
[Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,20 +11,25 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
[DisplayName("Отправитель")]
|
||||
[Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата письма")]
|
||||
[Column("Дата письма", width: 100)]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
[DisplayName("Заголовок")]
|
||||
[Column("Заголовок", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Текст")]
|
||||
[Column("Текст", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,37 +12,40 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
[Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int PastryId { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[DisplayName("Фамилия клиента")]
|
||||
[Column("Данные клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
[Column("Данные исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Изделие")]
|
||||
[Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
[Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
[Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
[Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
[Column("Дата создания", width: 100)]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
[Column("Дата выполнения", width: 100)]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,14 +11,16 @@ namespace ConfectioneryContracts.ViewModels
|
||||
{
|
||||
public class PastryViewModel : IPastryModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название изделия")]
|
||||
[Column("Название документа", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column("Цена", width: 100)]
|
||||
public double Price { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public Dictionary<int, (IComponentModel, int)> PastryComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDataModels.Models
|
||||
{
|
||||
public interface IMessageInfoModel
|
||||
public interface IMessageInfoModel : IId
|
||||
{
|
||||
string MessageId { get; }
|
||||
int? ClientId { get; }
|
||||
|
@ -21,4 +21,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,27 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryDatabaseImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement
|
||||
{
|
||||
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<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Implements
|
||||
{
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
298
Confectionery/ConfectioneryDatabaseImplement/Migrations/20230504194238_migr7.Designer.cs
generated
Normal file
298
Confectionery/ConfectioneryDatabaseImplement/Migrations/20230504194238_migr7.Designer.cs
generated
Normal file
@ -0,0 +1,298 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ConfectioneryDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ConfectioneryDatabase))]
|
||||
[Migration("20230504194238_migr7")]
|
||||
partial class migr7
|
||||
{
|
||||
/// <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("ConfectioneryDatabaseImplement.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("ConfectioneryDatabaseImplement.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("ConfectioneryDatabaseImplement.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("ConfectioneryDatabaseImplement.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.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.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>("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>("PastryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("PastryId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("PastryName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Pastries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PastryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("PastryId");
|
||||
|
||||
b.ToTable("PastryComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Messages")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PastryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Pastry");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
|
||||
{
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("PastryComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("PastryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Pastry");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("PastryComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class migr7 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -216,7 +216,7 @@ namespace ConfectioneryDatabaseImplement.Migrations
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.WithMany("Messages")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
@ -268,6 +268,8 @@ namespace ConfectioneryDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
|
@ -8,24 +8,34 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Message> Messages { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -8,16 +8,24 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<PastryComponent> PastryComponents { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
|
@ -6,26 +6,33 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("ImplementerId")]
|
||||
|
@ -5,14 +5,17 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Message : IMessageInfoModel
|
||||
{
|
||||
[Key]
|
||||
[DataMember]
|
||||
public string MessageId { get; private set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; private set; }
|
||||
@ -53,5 +56,7 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,23 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int PastryId { get; set; }
|
||||
|
||||
public virtual Pastry Pastry { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
public virtual Client Client { get; private set; } = new();
|
||||
|
||||
@ -26,14 +30,22 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Count { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
@ -7,25 +7,31 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Pastry : IPastryModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string PastryName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Price { get; private set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _pastryComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
[DataMember]
|
||||
public Dictionary<int, (IComponentModel, int)> PastryComponents
|
||||
{
|
||||
get
|
||||
|
@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,27 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryFileImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement
|
||||
{
|
||||
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<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,20 +4,26 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
|
@ -4,16 +4,23 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
internal class Component : IComponentModel
|
||||
[DataContract]
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
|
@ -4,22 +4,29 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(XElement element)
|
||||
|
@ -76,5 +76,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
new XAttribute("SenderName", SenderName),
|
||||
new XAttribute("DateDelivery", DateDelivery)
|
||||
);
|
||||
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -5,30 +5,41 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int PastryId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
|
@ -4,25 +4,30 @@ using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Pastry : IPastryModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string PastryName { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _pastryComponents = null;
|
||||
|
||||
|
||||
[DataMember]
|
||||
public Dictionary<int, (IComponentModel, int)> PastryComponents
|
||||
{
|
||||
get
|
||||
|
@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,22 @@
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryListImplement.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();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryListImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryListImplement
|
||||
{
|
||||
public class ListImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<IPastryStorage, PastryStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -49,5 +49,7 @@ namespace ConfectioneryListImplement.Models
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
55
Confectionery/ConfectioneryView/DataGridViewExtension.cs
Normal file
55
Confectionery/ConfectioneryView/DataGridViewExtension.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using ConfectioneryContracts.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryView
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -31,13 +31,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Confectionery;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -36,14 +37,8 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -54,7 +49,7 @@ namespace ConfectioneryView
|
||||
|
||||
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 (form.ShowDialog() == DialogResult.OK)
|
||||
@ -68,8 +63,8 @@ namespace ConfectioneryView
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
var service = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Confectionery;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -33,16 +34,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _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;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка исполнителей");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -54,7 +46,7 @@ namespace ConfectioneryView
|
||||
|
||||
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 (form.ShowDialog() == DialogResult.OK)
|
||||
@ -68,7 +60,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||
if (service is FormImplementer form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -1,4 +1,6 @@
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,6 +19,7 @@ namespace ConfectioneryView
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
|
||||
|
||||
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -28,14 +31,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["MessageId"].Visible = false;
|
||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка списка писем");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -44,6 +40,6 @@ namespace ConfectioneryView
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
12
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
@ -46,6 +46,7 @@
|
||||
this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.запускРаботыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.бэкапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -115,7 +116,8 @@
|
||||
this.справочникиToolStripMenuItem,
|
||||
this.отчётыToolStripMenuItem,
|
||||
this.запускРаботыToolStripMenuItem,
|
||||
this.письмаToolStripMenuItem});
|
||||
this.письмаToolStripMenuItem,
|
||||
this.бэкапToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
|
||||
@ -206,6 +208,13 @@
|
||||
this.письмаToolStripMenuItem.Text = "Письма";
|
||||
this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailToolStripMenuItem_Click);
|
||||
//
|
||||
// бэкапToolStripMenuItem
|
||||
//
|
||||
this.бэкапToolStripMenuItem.Name = "бэкапToolStripMenuItem";
|
||||
this.бэкапToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
|
||||
this.бэкапToolStripMenuItem.Text = "Бэкап";
|
||||
this.бэкапToolStripMenuItem.Click += new System.EventHandler(this.СreateBackupToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@ -250,5 +259,6 @@
|
||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботыToolStripMenuItem;
|
||||
private ToolStripMenuItem письмаToolStripMenuItem;
|
||||
private ToolStripMenuItem бэкапToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@ -22,13 +23,16 @@ namespace ConfectioneryView
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
private readonly IWorkProcess _workProcess;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
|
||||
private readonly IBackUpLogic _backUpLogic;
|
||||
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workProcess = workProcess;
|
||||
_backUpLogic = backUpLogic;
|
||||
}
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
@ -60,7 +64,7 @@ namespace ConfectioneryView
|
||||
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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -68,7 +72,7 @@ e)
|
||||
}
|
||||
private void PastriesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastries));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastries>();
|
||||
if (service is FormPastries form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -77,7 +81,7 @@ 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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -201,7 +205,7 @@ e)
|
||||
|
||||
private void PastryComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportPastryComponents>();
|
||||
if (service is FormReportPastryComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -210,7 +214,7 @@ 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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -219,7 +223,7 @@ 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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -228,7 +232,7 @@ 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)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -237,7 +241,7 @@ e)
|
||||
|
||||
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
||||
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
|
||||
MessageBox.Show("Процесс обработки запущен", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
@ -249,11 +253,37 @@ e)
|
||||
|
||||
private void MailToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
|
||||
var service = DependencyManager.Instance.Resolve<FormMails>();
|
||||
if (service is FormMails form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void СreateBackupToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_backUpLogic != null)
|
||||
{
|
||||
var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel
|
||||
{
|
||||
FolderName = fbd.SelectedPath
|
||||
});
|
||||
MessageBox.Show("Бекап создан", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Confectionery;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using System;
|
||||
@ -35,14 +36,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["PastryComponents"].Visible = false;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка компьютеров");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -54,7 +48,7 @@ namespace ConfectioneryView
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastry>();
|
||||
if (service is FormPastry form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -68,7 +62,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastry>();
|
||||
if (service is FormPastry form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -13,6 +13,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Confectionery;
|
||||
using ConfectioneryContracts.DI;
|
||||
|
||||
namespace ConfectioneryView
|
||||
{
|
||||
@ -85,7 +86,7 @@ namespace ConfectioneryView
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastryComponent>();
|
||||
if (service is FormPastryComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -113,8 +114,7 @@ namespace ConfectioneryView
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
|
||||
var service = DependencyManager.Instance.Resolve<FormPastryComponent>();
|
||||
if (service is FormPastryComponent form)
|
||||
{
|
||||
int id =
|
||||
|
@ -4,6 +4,7 @@ using ConfectioneryBusinessLogic.OfficePackage;
|
||||
using ConfectioneryBusinessLogic.OfficePackage.Implements;
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.DI;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryDatabaseImplement.Implements;
|
||||
using ConfectioneryView;
|
||||
@ -15,9 +16,6 @@ namespace Confectionery
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -27,13 +25,11 @@ namespace Confectionery
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
InitDependency();
|
||||
|
||||
try
|
||||
{
|
||||
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
|
||||
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin =
|
||||
@ -57,56 +53,48 @@ namespace Confectionery
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = _serviceProvider.GetService<ILogger>();
|
||||
var logger = DependencyManager.Instance.Resolve<ILogger>();
|
||||
}
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
private static void InitDependency()
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
DependencyManager.InitDependency();
|
||||
DependencyManager.Instance.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IPastryStorage, PastryStorage>();
|
||||
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IPastryLogic, PastryLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormPastry>();
|
||||
services.AddTransient<FormPastryComponent>();
|
||||
services.AddTransient<FormPastries>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormReportPastryComponents>();
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormImplementers>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
services.AddTransient<FormMails>();
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IPastryLogic, PastryLogic>();
|
||||
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<FormPastries>();
|
||||
DependencyManager.Instance.RegisterType<FormCreateOrder>();
|
||||
DependencyManager.Instance.RegisterType<FormPastry>();
|
||||
DependencyManager.Instance.RegisterType<FormPastryComponent>();
|
||||
DependencyManager.Instance.RegisterType<FormReportPastryComponents>();
|
||||
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();
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user